Oracle11g 如何在oracle中获取固定模式的输出
我的表中有一个名为TRAN_TYPE的列,它的数据如下所示Oracle11g 如何在oracle中获取固定模式的输出,oracle11g,Oracle11g,我的表中有一个名为TRAN_TYPE的列,它的数据如下所示 TRAN_TYPE ---------- success failed 123456-001 654321-001 098765-002 time out 我的要求是获取列数据,其中包含连续的6位数字,后跟-和3位数字 根据以上数据,我的输出将是 123456-001 654321-001 098765-002 请建议查询。您可以使用正则表达式: where regexp_like(tran_type, '^\d{6}-\d{3}$
TRAN_TYPE
----------
success
failed
123456-001
654321-001
098765-002
time out
我的要求是获取列数据,其中包含连续的6位数字,后跟-和3位数字
根据以上数据,我的输出将是
123456-001
654321-001
098765-002
请建议查询。您可以使用正则表达式:
where regexp_like(tran_type, '^\d{6}-\d{3}$');
\d代表一个数字,{6}和{3}是前一个模式必须重复的次数,它们必须用破折号分隔。^和$是起始和结束锚点,因此数字前后不能有任何内容
在CTE中使用示例数据演示:
with your_table (tran_type) as (
select 'success' from dual
union all select 'failed' from dual
union all select '123456-001' from dual
union all select '654321-001' from dual
union all select '098765-002' from dual
union all select 'time out' from dual
)
select tran_type
from your_table
where regexp_like(tran_type, '^\d{6}-\d{3}$');
TRAN_TYPE
----------
123456-001
654321-001
098765-002
或者试试这个