试图找出测试 VARCHAR 列值是否以回车符结尾的正确方法。试过这个,但它不起作用,数据库是Oracle 11g
......
select name from myTable where name LIKE '%\r' OR name like '%\n'
试图找出测试 VARCHAR 列值是否以回车符结尾的正确方法。试过这个,但它不起作用,数据库是Oracle 11g
......
select name from myTable where name LIKE '%\r' OR name like '%\n'
尝试
SELECT name from myTable where name like '%'||chr(10) or name like '%'||chr(13)
要查找包含不可打印字符(例如回车或垂直制表符或行尾)的值,您可以使用regexp_like函数。在您的情况下,要显示特定列的字符串值在末尾包含回车的行,可以使用类似的查询。
select *
from your_table_name
where regexp_like(trim(string_column), '[[:space:]]$')
回复评论
Trim
默认情况下,函数会删除前导和尾随空格,并且不会删除回车符或行尾字符。让我们进行一个简单的测试:
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>