SET PATH *LIBL ; 

CREATE OR REPLACE FUNCTION RESTAPI.PATH_PARAMS ( 
	INAPPVER VARCHAR(10) , 
	INAPPNAME VARCHAR(128) , 
	INAPPFUNC VARCHAR(128) ) 
	RETURNS TABLE ( 
	RESTNAME VARCHAR(128) , 
	ORD INTEGER )   
	LANGUAGE SQL 
	SPECIFIC RESTAPI.PATH_PARAMS 
	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 
WITH E AS ( 
SELECT PATH_TEMPLATE 
FROM RESTAPI . ENDPOINTS 
WHERE ( APPVER , APPNAME , APPFUNC ) = ( INAPPVER , 
INAPPNAME , INAPPFUNC ) 
) , 
X AS ( 
-- Extract each {...} occurrence; ORD is its position 
SELECT ROW_NUMBER ( ) OVER ( 
) AS ORD , 
REGEXP_SUBSTR ( 
PATH_TEMPLATE , '\{([^}]+)\}' , 1 , 
ORDINAL_POSITION , '' , 1 ) AS RESTNAME 
FROM E , TABLE ( 
SYSTOOLS . SPLIT ( PATH_TEMPLATE , '}' ) 
) 
WHERE REGEXP_SUBSTR ( 
PATH_TEMPLATE , '\{([^}]+)\}' , 1 , ORDINAL_POSITION , 
'' , 1 ) IS NOT NULL 
) SELECT RESTNAME , ORD 
FROM X ; 
END  ; 

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

GRANT EXECUTE   
ON SPECIFIC FUNCTION RESTAPI.PATH_PARAMS 
TO PUBLIC ; 

