SET PATH *LIBL ; 

CREATE OR REPLACE FUNCTION CISTOOLS.GET_CAMEL_CASE ( 
	INSTRING VARCHAR(528) ) 
	RETURNS VARCHAR(528)   
	LANGUAGE SQL 
	SPECIFIC CISTOOLS.GET_CAMEL_CASE 
	DETERMINISTIC 
	READS SQL DATA 
	CALLED ON NULL INPUT 
	NO EXTERNAL ACTION 
	SET OPTION  ALWBLK = *ALLREAD , 
	ALWCPYDTA = *OPTIMIZE , 
	COMMIT = *NONE , 
	DECRESULT = (31, 31, 00) , 
	DYNDFTCOL = *NO , 
	DYNUSRPRF = *USER , 
	SRTSEQ = *HEX   
	BEGIN 
DECLARE V_WORKSTR VARCHAR ( 528 ) ; 
DECLARE V_RESULT VARCHAR ( 528 ) ; 
-- Normalize to lowercase and replace separators with spaces 
SET V_WORKSTR = LOWER ( 
REGEXP_REPLACE ( 
TRIM ( CAST ( INSTRING AS VARCHAR ( 528 ) CCSID 37 ) ) , 
'(_|-|\\.|\\s)+' , ' ' ) ) ; 
-- Capitalize each word 
SET V_RESULT = ( 
SELECT TRIM ( 
LISTAGG ( 
UPPER ( LEFT ( TRIM ( ELEMENT ) , 1 ) ) || 
SUBSTR ( TRIM ( ELEMENT ) , 2 ) , '' ) 
WITHIN GROUP ( ORDER BY ORDINAL_POSITION ) ) 
FROM TABLE ( 
SYSTOOLS . SPLIT ( V_WORKSTR , ' ' ) 
) 
WHERE TRIM ( ELEMENT ) <> '' ) ; 
-- Make first character lowercase 
SET V_RESULT = LOWER ( LEFT ( V_RESULT , 1 ) ) || SUBSTR ( V_RESULT , 2 ) ; 
RETURN TRIM ( V_RESULT ) ; 
END  ; 

COMMENT ON PARAMETER SPECIFIC FUNCTION CISTOOLS.GET_CAMEL_CASE 
( INSTRING IS 'In String' ) ; 

LABEL ON SPECIFIC FUNCTION CISTOOLS.GET_CAMEL_CASE 
	IS 'Get Camel Case' ; 

GRANT ALTER , EXECUTE   
ON SPECIFIC FUNCTION CISTOOLS.GET_CAMEL_CASE 
TO AMAPICS WITH GRANT OPTION ; 

GRANT EXECUTE   
ON SPECIFIC FUNCTION CISTOOLS.GET_CAMEL_CASE 
TO PUBLIC ; 

