我有字符串'KK12340000',我只想在KK之后的前4位数按升序排列时验证它,所以我使用类似的东西:
select case when REGEXP_LIKE('KK12340000', '^KK(?=\d{4})(?:(.)\\1*|0?1?2?3?4?5?6?7?8?9?)\d{4}$') then 1 else 0 end as valid from dual;
但它返回0.所以在oracle中甚至可以按升序验证数字吗?
答案 0 :(得分:2)
试试这个:
SELECT CASE
WHEN REGEXP_LIKE (
'KK12230000',
'^KK(?:(.)\\1*|0?1?2?3?4?5?6?7?8?9?)\d{4}$')
THEN
1
ELSE
0
END
AS valid
FROM DUAL;
答案 1 :(得分:-1)
您也可以尝试这样的事情
SELECT 'KK12340000' LIKE 'KK%' AND
SUBSTRING('KK12340000', 3, 1) - SUBSTRING('KK12340000', 4, 1) < 0 AND
SUBSTRING('KK12340000', 4, 1) - SUBSTRING('KK12340000', 5, 1) < 0 AND
SUBSTRING('KK12340000', 5, 1) - SUBSTRING('KK12340000', 6, 1) < 0