开发者

In Oracle, how do I select rows which contain a character within a certain numeric range?

I have a table in Oracle with a VARCHAR column called DESCRIPTION. Some of the rows contai开发者_如何学运维n non-printable characters such as the character with numeric value 150 (which is not in Latin-1 and is "Start of Protected Area" in Unicode).

I want to select all the rows whose DESCRIPTION columns contain a character whose numeric value is between 128 and 160. Is there a way to do this without a long list of LIKE clauses OR'ed together? I suppose it can be done with regular expressions, but I haven't found a way to do it.


I had to do something very like this recently and used some SQL like this:

with codes as (select rownum code from dual connect by level <= 160)
select distinct t.id, t.description
from mytable t, codes c
where t.description like '%' || chr(c.code) || '%'
and c.code >= 128;


Vincent's post helped me a lot with this problem! I wanted to find all rows that had any extended ASCII: 128-255, so I shortened the statement to this:

SELECT description
FROM your_table
WHERE regexp_like (description, '['||chr(128)||'-'||chr(255)||']');

Short way to grab a range.


You could use a regular expression, it may perform better than 30+ single WHERE clause but it won't be much prettier:

SELECT * 
  FROM your_table 
 WHERE regexp_like(description, '['||chr(128)||chr(129)||...||chr(160)||']')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜