<?xml version="1.0" encoding="utf-8" ?> 
<TemplateProc>

<Script>
    <![CDATA[
BEGIN 
EXECUTE IMMEDIATE '
CREATE OR REPLACE PROCEDURE %%ProcName%% 
(
	CF_%%CampoChave%% INT,
	CF_%%CampoUsuario%% INT,
	CF_%%CampoGUID%% VARCHAR2,
	CF_%%CampoParentGUID%% VARCHAR2 := NULL
	%%CamposDeclare%%,
	Cur		OUT		WFPORTAL.Cursor
)
AS
StoO_selcnt	INTEGER;
StoO_error 	INTEGER;
StoO_rowcnt	INTEGER;
StoO_crowcnt	INTEGER := 0;
StoO_fetchstatus	INTEGER := 0;
StoO_errmsg	VARCHAR2(255);
StoO_sqlstatus	INTEGER;
BEGIN
	IF(CF_%%CampoChave%% = 0) THEN
	BEGIN

		INSERT INTO %%TableName%%
		(%%Campos%%)
		VALUES
		(%%Valores%%);
		OPEN Cur FOR 
		SELECT * FROM %%TableName%% WHERE %%CampoChave%% = (select WFPORTAL.IDENTITY from SYS.DUAL);
	EXCEPTION
		WHEN NO_DATA_FOUND THEN
			NULL;
		WHEN OTHERS THEN
			StoO_error := SQLCODE;
			StoO_errmsg := SQLERRM;
			RAISE_APPLICATION_ERROR(SQLCODE, SQLERRM,TRUE);
	END;	
	ELSE
	BEGIN
	
		UPDATE %%TableName%%
		SET %%ValoresUpdate%% 
		WHERE %%Where%%;
		OPEN Cur FOR 
		SELECT * FROM %%TableName%% WHERE %%CampoChave%% = CF_%%CampoChave%%;
	EXCEPTION
		WHEN NO_DATA_FOUND THEN
			NULL;
		WHEN OTHERS THEN
			StoO_error := SQLCODE;
			StoO_errmsg := SQLERRM;
			RAISE_APPLICATION_ERROR(SQLCODE, SQLERRM,TRUE);
	END;
	END IF;
END;
';
END;	
]]></Script>

</TemplateProc>