要检索第三个字符为“_”下划线的数据?

时间:2014-03-07 04:10:24

标签: sql oracle

如何找到第三个字符为'_'下划线的数据。

像这样

Names
------
al_en
vi_i
sm_th

4 个答案:

答案 0 :(得分:2)

你可以这样做:

select name from t1 where SUBSTRING(name, 3 , 1) = '_'

working fiddle

答案 1 :(得分:2)

您可以使用LIKE子句使用ESCAPE运算符。 由于'_'是模式匹配字符,因此需要使用ESCAPE子句。

where names like '__\_%' escape '\';

这里首先强调匹配任意两个字符,转义字符'\'导致第三个下划线按字面解释。

SQL> with x(y) as (
        select 'al_en' from dual union all
        select 'a_en' from dual union all
        select 'awen' from dual union all
        select '___en' from dual union all
        select 'sm_' from dual
        )
select y from x
where y like '__\_%' escape '\';

Y
-----
al_en
___en
sm_

答案 2 :(得分:1)

SELECT COLUMNNAME
FROM YOURTABLE
WHERE INSTR(COLUMNNAME,'_') = 3

INSTR()返回字符串中指定字符串/字符的位置。

答案 3 :(得分:0)

从table_name中选择名称,其中instr(name,'_')= 3;