SET PATH *LIBL ; 

CREATE OR REPLACE FUNCTION RESTAPI.GET_PARAM_PLACEHOLDERS ( 
	INAPPVER VARCHAR(10) DEFAULT  NULL  , 
	INAPPNAME VARCHAR(128) DEFAULT  NULL  , 
	INAPPFUNC VARCHAR(128) DEFAULT  NULL  ) 
	RETURNS TABLE ( 
	APPVER VARCHAR(10) , 
	APPNAME VARCHAR(128) , 
	APPFUNC VARCHAR(128) , 
	APPPARAM VARCHAR(128) , 
	PARAMPOS INTEGER )   
	LANGUAGE SQL 
	SPECIFIC RESTAPI.GET_PARAM_PLACEHOLDERS 
	NOT DETERMINISTIC 
	READS SQL DATA 
	CALLED ON NULL INPUT 
	SET OPTION  ALWBLK = *ALLREAD , 
	ALWCPYDTA = *OPTIMIZE , 
	COMMIT = *NONE , 
	DECRESULT = (31, 31, 00) , 
	DYNDFTCOL = *NO , 
	DYNUSRPRF = *USER , 
	SRTSEQ = *HEX   
	BEGIN 
RETURN 
SELECT S . * , ROW_NUMBER ( ) OVER ( 
PARTITION BY S . APPVER , S . APPNAME , S . APPFUNC 
) 
FROM TABLE ( 
SELECT DISTINCT S . APPVER , S . APPNAME , S . APPFUNC , 
REGEXP_SUBSTR ( 
S . SQLSTMT , '\{\{([^}]+)\}\}' , 1 , 
X . ORDINAL_POSITION , '' , 1 ) AS APPPARAM 
FROM RESTAPI . SQLSTMTS AS S , TABLE ( 
SYSTOOLS . SPLIT ( S . SQLSTMT , '}' ) 
) AS X 
WHERE REGEXP_SUBSTR ( 
S . SQLSTMT , '\{\{([^}]+)\}\}' , 1 , 
X . ORDINAL_POSITION , '' , 1 ) IS NOT NULL 
AND ( S . APPVER , S . APPNAME , S . APPFUNC ) = ( COALESCE ( 
INAPPVER , S . APPVER ) , 
COALESCE ( INAPPNAME , S . APPNAME ) , COALESCE ( 
INAPPFUNC , S . APPFUNC ) ) 
) S ; 
END  ; 

GRANT ALTER , EXECUTE   
ON SPECIFIC FUNCTION RESTAPI.GET_PARAM_PLACEHOLDERS 
TO AMAPICS WITH GRANT OPTION ; 

GRANT EXECUTE   
ON SPECIFIC FUNCTION RESTAPI.GET_PARAM_PLACEHOLDERS 
TO PUBLIC ; 

