2012-10-03 18 views

risposta

5

Per trovare un valore che contiene caratteri non stampabili, come ritorno a capo o tabulazione verticale o alla fine della linea puoi usare la funzione regexp_like. Nel tuo caso per visualizzare le righe in cui un valore di stringa di una particolare colonna contiene il ritorno a capo alla fine, è possibile utilizzare la query simile.

select * 
    from your_table_name 
where regexp_like(trim(string_column), '[[:space:]]$') 

Demo


risposta ai commenti

Trim funzione, per impostazione predefinita, cancella spazi iniziali e finali e non cancellerà Carriage Return o fine della riga caratteri. Consente di eseguire un semplice test:

SQL> create table Test_Table(
    2 id number, 
    3 col1 varchar2(101) 
    4 ); 

Table created 

SQL> insert into Test_Table (id, col1) 
    2 values(1, 'Simple string'); 

1 row inserted 

SQL> commit; 

Commit complete 

SQL> insert into Test_Table (id, col1) 
    2 values(1, 'Simple string with carriage return at the end' || chr(13)); 

1 row inserted 

SQL> commit; 

Commit complete 

SQL> insert into Test_Table (id, col1) 
    2 values(1, ' Simple string with carriage return at the end leading and trailing spaces' || chr(13)||' '); 

1 row inserted 

SQL> commit; 

Commit complete 

SQL> insert into Test_Table (id, col1) 
    2 values(1, ' Simple string leading and trailing spaces '); 

1 row inserted 

SQL> commit; 

Commit complete 

SQL> select * 
    2 from test_table; 

     ID COL1 
-------------------------------------------------------------------------------- 
     1 Simple string 
     1 Simple string with carriage return at the end 
     1 Simple string with carriage return at the end leading and trailing spaces 
     1 Simple string leading and trailing spaces 

SQL> 
SQL> select * 
    2 from test_table 
    3 where regexp_like(trim(col1), '[[:space:]]$') 
    4 ; 

     ID COL1 
---------------------------------------------------------------------------------- 
     1 Simple string with carriage return at the end 
     1 Simple string with carriage return at the end leading and trailing spaces 

SQL> 
+0

Quale parte di '[[: space:]] $' sta effettivamente verificando il ritorno a capo? È '$'? – raffian

+0

'[[: space:]]' - cerca il ritorno a capo (e altri caratteri non stampabili citati nella risposta). '$' - cerca le corrispondenze alla fine della stringa. –

+0

Ho provato questo, ma raccogliendo colonne con spazi alla fine, saltando decisamente sopra quelli con ritorni a capo ... BTW, +1 per SQLFiddle! – raffian

10

Prova

SELECT name from myTable where name like '%'||chr(10) or name like '%'||chr(13) 
+1

I numeri corretto da utilizzare dipende dal set di caratteri database per [var] char [2] tipi e database di carattere nazionale fissato per n [var] char [2] tipi. (Commentato sulla sfortuna che chiunque usi EBCDIC attraversa questa risposta.) –