假设下面是一个字符串:
" Rajiv Verma 3/20/2018 3:48:39汤姆告诉我在这里发表评论"
我需要得到hh:mm:ss格式之后的子字符串:
"汤姆告诉我在这里发表评论"。
如何通过Pl sql Oracle实现这一目标?
答案 0 :(得分:3)
您可以使用带有模式的REGEXP_SUBSTR
来匹配时间:
DECLARE
p_input VARCHAR2(4000) := 'Rajiv Verma 3/20/2018 3:48:39 Tom has told me to comment here';
p_comment VARCHAR2(4000);
BEGIN
p_comment := REGEXP_SUBSTR(
p_input,
'\d\d?:\d\d?:\d\d?(.*)$',
1, -- Start from the 1st character
1, -- Find the 1st match
NULL, -- No flags
1 -- Return the 1st capture group
);
END;
/
或在SQL中:
SELECT REGEXP_SUBSTR(
your_string,
'\d\d?:\d\d?:\d\d?(.*)$',
1, -- Start from the 1st character
1, -- Find the 1st match
NULL, -- No flags
1 -- Return the 1st capture group
)
FROM your_table;
有关Oracle(perl)正则表达式模式can be found here的文档。