VARCHAR列の値が改行で終わるかどうかをテストする正しい方法を見つけようとしています。文字列値にキャリッジリターンが含まれているかどうかをテストするSQLクエリ
select name from myTable where name LIKE '%\r' OR name like '%\n'
VARCHAR列の値が改行で終わるかどうかをテストする正しい方法を見つけようとしています。文字列値にキャリッジリターンが含まれているかどうかをテストするSQLクエリ
select name from myTable where name LIKE '%\r' OR name like '%\n'
をお試しください...データベースはOracle 11g
あり、これを試してみましたが、それは動作しません。 regexp_like機能を使用することができます。特定の列の文字列値に最後に改行が含まれている行を表示する場合は、同様のクエリを使用できます。コメント
Trim
関数に
select *
from your_table_name
where regexp_like(trim(string_column), '[[:space:]]$')
回答は、デフォルトでは、先頭と末尾のスペースを削除し、それがラインのキャリッジリターン又はエンドは削除されません文字。
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>
は、キャリッジリターンまたは垂直タブまたは行の終わりのような非印字可能な文字を含む値を検索するに
SELECT name from myTable where name like '%'||chr(10) or name like '%'||chr(13)
使用する正しい数字は、[var] char [2]タイプのデータベース・キャラクタ・セットとn [var] char [2]タイプのデータベース・ナショナル・キャラクタ・セットに依存します。 (EBCDICを使用している誰かがこの回答を実行するチャンスについてコメントしました) –
'[[:space:]] $'のどの部分が実際に改行をチェックしていますか?それは '$'ですか? – raffian
'[[:space:]]' - キャリッジリターン(および答えに記載されている他の印字不可能な文字)を探します。 '$' - 文字列の最後にある一致を検索します。 –
私はこれを試しましたが、最後に空白を持つ列をピックアップしていますが、間違いなくキャリッジリターンを持つものをスキップしています... BTW、+1 for SQLFiddle! – raffian