<?xml version="1.0" encoding="ISO-8859-1" ?> 
<TemplateProc>

<Script>
                  <![CDATA[
DECLARE
 INTCOUNT INT:=0;
BEGIN
 SELECT COUNT(*) INTO INTCOUNT FROM USER_TABLES WHERE TABLE_NAME=UPPER('%%TableName%%');
 IF (INTCOUNT>0) THEN
    BEGIN
    	%%ScriptField%%
    END;
 ELSE
     BEGIN
     	EXECUTE IMMEDIATE '
		create table %%TableName%% 
	        (
	         %%CampoChave%% INT not null,
		%%CampoUsuario%%  INT,
		%%CampoGUID%%    varchar2(36),
		%%CampoParentGUID%% varchar2(36)
		)
		';
	EXECUTE IMMEDIATE '
		alter table %%TableName%% 
		add constraint PK_%%TableName%% primary key (%%CampoChave%%) 
		';
	EXECUTE IMMEDIATE '
		create sequence SEQ_%%TableName%%
		minvalue 1
		maxvalue 999999999999999999999999999
		start with 1
		increment by 1
		cache 20
		';
	
	%%ScriptFieldNew%%
     END;
 END IF;
 
 EXECUTE IMMEDIATE '
	CREATE OR REPLACE TRIGGER TR_%%TableName%%
	BEFORE INSERT ON %%TableName%% 
 	FOR EACH ROW 
	BEGIN
                SELECT SEQ_%%TableName%%.NEXTVAL INTO :NEW.%%CampoChave%% FROM DUAL; 
	            SELECT SEQ_%%TableName%%.CURRVAL INTO WFPORTAL.IDENTITY FROM DUAL; 
	END;
	';
 
END;
]]></Script>

</TemplateProc>