Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle11g 如何在oracle中获取固定模式的输出_Oracle11g - Fatal编程技术网

Oracle11g 如何在oracle中获取固定模式的输出

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的列,它的数据如下所示

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
或者试试这个