我的表REMARKS
中有一个名为TBL_DATA
的列,我的数据如表所示。
REMARKS
--------------
Ramesh has VR2
Ravi is VR1 member
Rajesh had VR2
Rakesh is VR10 employee
我的要求是从remarks
结尾的表中获取数据,其中VR
后跟VR2, VR3,VR10,VR33
之类的数字。
从上面的数据我想得到第一和第三行数据。
P.S:我不应该使用类似的运算符(LIKE'%VR%')
答案 0 :(得分:1)
您可能需要以下内容:
with tbl_data(remarks) as (
select 'Ramesh has VR2' from dual union all
select 'Ravi is VR1 member' from dual union all
select 'Rajesh had VR2' from dual union all
select 'Rakesh is VR10 employee' from dual
)
select *
from tbl_data
where regexp_like(remarks, 'VR[0-9]+$')
给出:
REMARKS
-----------------------
Ramesh has VR2
Rajesh had VR2
'VR[0-9]+$'
如何运作:
VR
:不言自明[0-9]+
:一个或多个数字$
:字符串的结尾答案 1 :(得分:0)
只需使用正则表达式:
select t.*
from t
where regexp_like(t.remarks, 'VR[0-9]+$');
答案 2 :(得分:0)
另一个正则表达式:
with tbl_data(remarks) as (
select 'Ramesh has VR2' from dual union all
select 'Ravi is VR1 member' from dual union all
select 'Rajesh had VR2' from dual union all
select 'Rakesh is VR10 employee' from dual
)
select *
from tbl_data
where regexp_like(remarks, 'VR\d+$')
;