是否有可能在oracle sql的正则表达式中使用?=
和?<=
限定符?
答案 0 :(得分:0)
您可以使用TRANSLATE,但在我看来并不容易维护。您还可以使用regexp_replace功能。基本上,你正在替换每个单词的第一个字母。
-- Solution 1
WITH T AS (
SELECT 'Fredy Mercury' str FROM dual UNION ALL
SELECT 'Hello World' FROM dual UNION ALL
SELECT 'Abc Def Ghi Klm Opq' FROM dual UNION ALL
SELECT 'As far as I know' FROM dual
)
SELECT str,
TRANSLATE(INITCAP(str)
,'ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz'
,'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
FROM T;
-- Solution 2
WITH T AS (
SELECT 'Fredy Mercury' str FROM dual UNION ALL
SELECT 'Hello World' FROM dual UNION ALL
SELECT 'Abc Def Ghi Klm Opq' FROM dual UNION ALL
SELECT 'As far as I know' FROM dual
)
SELECT str, UPPER(regexp_replace(str,'(\w{1})\w*(\W+|$)','\1')) FROM T;
希望这很有用。