我有将近1000条记录,其中前两个字符为字母,然后为多个字符。 例如。
- BE123
- QT12124
- ST1000
- XY12345
和类似数据。
我在Oracle中有一个表X,该表的列“序列号”将具有相似的数据,但它的标准长度为7,并且以字母的前两个字符开头。
我想在序列号列上进行模式匹配,在这里我可以在列的前两个字符之后的字符上使用LIKE
和'%'匹配,例如
如果列中有数据
- BE00123 , it should start give me BE123 as matched data
- QT12124 , it is matched data
- ST11001 , unmatched data
- XY12345, matched data
答案 0 :(得分:1)
好吧,这将返回您的要求。看看是否有帮助。
SQL> with t_one (col) as
2 (select 'BE123' from dual union all
3 select 'QT12124' from dual union all
4 select 'ST1000' from dual union all
5 select 'XY12345' from dual
6 ),
7 t_two (col) as
8 (select 'BE00123' from dual union all
9 select 'QT12124' from dual union all
10 select 'ST11001' from dual union all
11 select 'XY12345' from dual
12 )
13 select o.col
14 from t_one o join t_two t on substr(o.col, 1, 2) = substr(t.col, 1, 2)
15 and instr(t.col, substr(o.col, 3)) > 0;
COL
-------
BE123
QT12124
XY12345
SQL>