检查字符串中的引号,即数字后跟逗号

时间:2019-07-24 12:07:03

标签: regex oracle plsql

我正在创建以字符串为输入示例的plsql函数 ('1234,4565,1212,7658') is right ('1234, 4565,1212,7658') is not right as return ('12345, 4565,121552,7658')  不超过4个字符

我想确保用户使用功能仅输入2个引号 只有4个字符,并以逗号分隔 如果违反以上任何条件,我该如何提出例外。

我尝试了REGEXP_LIKE(Column ,'^['][0-9]{d},[']$'),但没有用

我尝试了REGEXP_LIKE(Column ,'^['][0-9]{d},[']$'),但没有用

REGEXP_LIKE(Column ,'^['][0-9]{d},[']$')但不起作用

预期:

('1234, 4565,1212,7658')

不期望

('1234, 
4565,1212,7658')

('123456, 
45654,1212,7658')

1 个答案:

答案 0 :(得分:0)

您可以尝试这个

WITH tab AS(
  SELECT '''1234,4565,1212,7658''' AS str FROM dual UNION ALL
  SELECT '''1234,4565,4565,1212,7658''' AS str FROM dual UNION ALL
  SELECT '''1234m,4565,1212,7658' AS str FROM dual UNION ALL
  SELECT '''1234,45655,1212,7658' AS str FROM dual UNION ALL
  SELECT '''1234,456,1212,7658''' AS str FROM dual UNION ALL
  SELECT '''1234,4565,1212'',7658''' AS str FROM dual       
)
SELECT * FROM tab t
WHERE REGEXP_LIKE(t.str ,'^['']([[:digit:]]{4},)+([[:digit:]]{4})['']$')

结果:

str
------
'1234,4565,1212,7658'
'1234,4565,4565,1212,7658'