简体   繁体   中英

How to convert a given data value to camel case without using INITCAP function in Oracle SQL developer

Input: RAKE'SH RE'DD'Y

Output(using INITCAP function) : Rake'Sh Re'Dd'Y

Expected output : Rake'sh Re'dd'y

INPUT 2: RAKESH REDDY

Output(using INITCAP function) : Rakesh Reddy

Expected output : Rakesh Reddy

The above input and input 2 should have same functionality

Can anyone help me with this ????

You can use a recursive sub-query factoring clause to find the alphabetic characters after each white-space character and change them to upper-case:

WITH bounds (value, pos) AS (
  SELECT UPPER(SUBSTR(value, 1, 1)) || LOWER(SUBSTR(value, 2)),
         REGEXP_INSTR(LOWER(value), '\s([a-z])', 2)
  FROM   table_name
UNION ALL
  SELECT SUBSTR(value, 1, pos)
         || UPPER(SUBSTR(value, pos + 1, 1))
         || SUBSTR(value, pos + 2),
         REGEXP_INSTR(LOWER(value), '\s([a-z])', pos + 2)
  FROM   bounds
  WHERE  pos > 0
)
SELECT value
FROM   bounds
WHERE  pos = 0;

Which, for the sample data:

CREATE TABLE table_name (value) AS 
SELECT 'RAKE''SH RE''DD''Y' FROM DUAL;

Outputs:

VALUE
Rake'sh Re'dd'y

db<>fiddle here

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