SET PATH *LIBL ; 

CREATE OR REPLACE FUNCTION CISTOOLS.STRIP_SPACES ( 
	INPUT_STRING CLOB(1048576) ) 
	RETURNS CLOB(1048576)   
	LANGUAGE SQL 
	SPECIFIC CISTOOLS.STRIP_SPACES 
	NOT DETERMINISTIC 
	READS SQL DATA 
	CALLED ON NULL INPUT 
	CONCURRENT ACCESS RESOLUTION DEFAULT 
	SET OPTION  ALWBLK = *ALLREAD , 
	ALWCPYDTA = *OPTIMIZE , 
	COMMIT = *NONE , 
	DECRESULT = (31, 31, 00) , 
	DYNDFTCOL = *NO , 
	DYNUSRPRF = *USER , 
	SQLCURRULE = *STD , 
	SRTSEQ = *HEX   
	BEGIN 
DECLARE OUTPUT_STRING CLOB ( 1 M ) DEFAULT ' ' ; 
-- Step 1: Remove newline characters (concatenate lines together) 
SET OUTPUT_STRING = REGEXP_REPLACE ( INPUT_STRING , '[\r\n]+' , '' ) ; 
-- Step 2: Replace multiple white spaces (spaces, tabs, etc.) with single space
SET OUTPUT_STRING = REGEXP_REPLACE ( OUTPUT_STRING , '\s+' , ' ' ) ; 
RETURN OUTPUT_STRING ; 
END  ; 

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

LABEL ON SPECIFIC FUNCTION CISTOOLS.STRIP_SPACES 
	IS 'Strip Spaces' ; 

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

GRANT EXECUTE   
ON SPECIFIC FUNCTION CISTOOLS.STRIP_SPACES 
TO PUBLIC ; 

