SET PATH *LIBL ; 

CREATE OR REPLACE FUNCTION CISTOOLS.GET_TITLE_CASE ( 
	INPUT_STRING VARCHAR(32000) CCSID 37 ) 
	RETURNS VARCHAR(32000) CCSID 37   
	LANGUAGE SQL 
	SPECIFIC CISTOOLS.GET_TITLE_CASE 
	NOT DETERMINISTIC 
	READS SQL DATA 
	CALLED ON NULL INPUT 
	CONCURRENT ACCESS RESOLUTION DEFAULT 
	SET OPTION  ALWBLK = *ALLREAD , 
	ALWCPYDTA = *OPTIMIZE , 
	COMMIT = *NONE , 
	DBGVIEW = *SOURCE , 
	DECRESULT = (31, 31, 05) , 
	DYNDFTCOL = *NO , 
	DYNUSRPRF = *OWNER , 
	SQLCURRULE = *STD , 
	SRTSEQ = *HEX   
	BEGIN 
DECLARE OUTPUT_STRING VARCHAR ( 32000 ) DEFAULT ' ' ; 
SET OUTPUT_STRING = ( 
SELECT LISTAGG ( FRAGMENT , ' ' ) WITHIN GROUP ( ORDER BY ORDINAL_POSITION ) 
FROM TABLE ( 
SELECT ORDINAL_POSITION , 
UPPER ( LEFT ( ELEMENT , 1 ) ) || SUBSTR ( ELEMENT , 2 ) AS FRAGMENT 
FROM TABLE ( 
SYSTOOLS . SPLIT ( 
REGEXP_REPLACE ( 
LOWER ( CAST ( INPUT_STRING AS VARCHAR ( 32000 ) CCSID 37 ) ) , 
'[\s+_-]' , ' ' ) , ' ' ) 
) 
) R 
WHERE FRAGMENT <> ' ' ) ; 
RETURN TRIM ( OUTPUT_STRING ) ; 
END  ; 

COMMENT ON PARAMETER SPECIFIC FUNCTION CISTOOLS.GET_TITLE_CASE 
( INPUT_STRING IS 'Input String' ) ; 

LABEL ON SPECIFIC FUNCTION CISTOOLS.GET_TITLE_CASE 
	IS 'Get Title Case' ; 

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

GRANT EXECUTE   
ON SPECIFIC FUNCTION CISTOOLS.GET_TITLE_CASE 
TO PUBLIC ; 

