简体   繁体   中英

Is there any possibility of using “? =” and “?<=” qualifiers inside the regular expressions in oracle sql?

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

You can use TRANSLATE , but in my opinion is not easy to maintain. You also can use regexp_replace function. Basically, you are replacing everyting but the first letter of each word.

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

Hopefully, this is helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM