是否有可能使用"? ="和"?< =" oracle sql中正则表达式中的限定符?

时间:2018-01-17 09:12:47

标签: sql regex oracle

是否有可能在oracle sql的正则表达式中使用?=?<=限定符?

1 个答案:

答案 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;

希望这很有用。