/*******************************************************************
						ZTEMPLATETIPOOBJETO
*******************************************************************/
DECLARE
nCount NUMBER;
BEGIN

SELECT COUNT(*) INTO nCount FROM USER_TABLES WHERE TABLE_NAME = 'ZTEMPLATETIPOOBJETO';
IF(nCount <= 0) THEN
EXECUTE IMMEDIATE 
		'CREATE TABLE ZTEMPLATETIPOOBJETO
		(
			IDTIPOOBJETO 	NUMBER(10,0) 		NOT NULL,
			TIPOOBJETO 		VARCHAR(100) 		NULL,
			DESCRICAO 		VARCHAR(200) 		NULL,		
			RECCREATEDBY 	VARCHAR(50) 		NULL,
			RECCREATEDON 	DATE  				NULL,
			RECMODIFIEDBY 	VARCHAR(50) 		NULL,
			RECMODIFIEDON 	DATE				NULL,
			
			CONSTRAINT PK_ZTEMPLATETIPOOBJETO PRIMARY KEY(IDTIPOOBJETO)
		)';
END IF;		


EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATETIPOOBJETO WHERE IDTIPOOBJETO = 1' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATETIPOOBJETO (IDTIPOOBJETO, TIPOOBJETO, DESCRICAO) VALUES (1, ''RM.Cst.TemplatesRM.Parametros.TextBoxControle,RM.Cst.TemplatesRM.Parametros.Form'', ''Texto livre'')';
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATETIPOOBJETO WHERE IDTIPOOBJETO = 2' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATETIPOOBJETO (IDTIPOOBJETO, TIPOOBJETO, DESCRICAO) VALUES (2, ''RM.Cst.TemplatesRM.Parametros.CheckBoxControle,RM.Cst.TemplatesRM.Parametros.Form'', ''CheckBox'')';
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATETIPOOBJETO WHERE IDTIPOOBJETO = 3' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATETIPOOBJETO (IDTIPOOBJETO, TIPOOBJETO, DESCRICAO) VALUES (3, ''RM.Cst.TemplatesRM.Parametros.ActionControle,RM.Cst.TemplatesRM.Parametros.Form'', ''Action'')';
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATETIPOOBJETO WHERE IDTIPOOBJETO = 4' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATETIPOOBJETO (IDTIPOOBJETO, TIPOOBJETO, DESCRICAO) VALUES (4, ''RM.Cst.TemplatesRM.Parametros.LookupControle,RM.Cst.TemplatesRM.Parametros.Form'', ''Lookup'')';
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATETIPOOBJETO WHERE IDTIPOOBJETO = 5' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATETIPOOBJETO (IDTIPOOBJETO, TIPOOBJETO, DESCRICAO) VALUES (5, ''RM.Cst.TemplatesRM.Parametros.MaskedTextBoxControle,RM.Cst.TemplatesRM.Parametros.Form'', ''Texto livre com máscara'')';
END IF;
	

/*******************************************************************
						ZTEMPLATEPROPOBJETO
*******************************************************************/
SELECT COUNT(*) INTO nCount FROM USER_TABLES WHERE TABLE_NAME = 'ZTEMPLATEPROPOBJETO';
IF(nCount <= 0) THEN
EXECUTE IMMEDIATE 
		'CREATE TABLE ZTEMPLATEPROPOBJETO
		(
			IDPROPOBJETO 	NUMBER(10,0)	 	NOT NULL,
			NOMEPROPOBJETO	VARCHAR(100) 		NULL,
			IDTIPOOBJETO 	NUMBER(10,0)		NOT NULL,
			RECCREATEDBY 	VARCHAR(50) 		NULL,
			RECCREATEDON 	DATE	 			NULL,
			RECMODIFIEDBY 	VARCHAR(50) 		NULL,
			RECMODIFIEDON 	DATE				NULL,
			
			CONSTRAINT PK_ZTEMPLATEPROPOBJETO PRIMARY KEY(IDPROPOBJETO),
			CONSTRAINT FK_ZTEMPLATEPROPOBJETO_ZTEMPLA FOREIGN KEY (IDTIPOOBJETO) REFERENCES ZTEMPLATETIPOOBJETO (IDTIPOOBJETO)
		)';
		
EXECUTE IMMEDIATE 
		'CREATE UNIQUE INDEX IX_ZTEMPLATEPROPOBJETO ON ZTEMPLATEPROPOBJETO(IDPROPOBJETO,IDTIPOOBJETO) TABLESPACE RM_INDICES';
END IF;

EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 1' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (1, ''Width'', 1)'; -- Largura do TextBox
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 2' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (2, ''Height'', 1)'; -- Altura do TextBox
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 3' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (3, ''PasswordChar'', 1)'; -- Caractere de senha do TextBox
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 4' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (4, ''MaxLength'', 1)'; -- Tamanho máximo do TextBox
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 5' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (5, ''Value'', 2)'; -- Valor do CheckBox
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 6' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (6, ''ValueChecked'', 2)'; -- Valor do CheckBox marcado
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 7' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (7, ''ValueUnchecked'', 2)'; -- Valor do CheckBox desmarcado
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 8' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (8, ''Width'', 2)'; -- Largura do CheckBox
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 9' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (9, ''Height'', 2)'; -- Altura do CheckBox
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 10' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (10, ''Action'', 4)'; -- Nome da Action do Lookup
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 11' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (11, ''DataServer'', 4)'; -- Nome do DataServer do Lookup
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 12' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (12, ''KeyFields'', 4)'; -- Chave da tabela customizada
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 13' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (13, ''LookupField'', 4)'; -- Chave da tabela customizada
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 14' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (14, ''LookupKeyFields'', 4)'; -- Chave da tabela do Lookup
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 15' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (15, ''LookupResultFields'', 4)'; -- Campos do resultado do Lookup
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 16' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (16, ''LookupSearchField'', 4)'; -- Campo de pequisa do Lookup
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 17' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (17, ''DataField'', 4)'; -- DataField do Lookup
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 18' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (18, ''UseDataField'', 4)'; -- UseDataField do Lookup
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 19' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (19, ''AutoLoadView'', 4)'; -- AutoLoadView do Lookup
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 20' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (20, ''Width'', 5)'; -- Largura do MaskedTextBox
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 21' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (21, ''Height'', 5)'; -- Altura do MaskedTextBox
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 22' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (22, ''PasswordChar'', 5)'; -- Caractere de senha do MaskedTextBox
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 23' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (23, ''MaxLength'', 5)'; -- Tamanho máximo do MaskedTextBox	
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 24' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (24, ''Mask'', 5)'; -- Máscara do MaskedTextBox	
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 25' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (25, ''ReadOnly'', 1)'; -- Somente leitura TextBox	
END IF;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ZTEMPLATEPROPOBJETO WHERE IDPROPOBJETO = 26' INTO nCount;
IF(nCount <= 0) THEN
	EXECUTE IMMEDIATE 'INSERT INTO ZTEMPLATEPROPOBJETO (IDPROPOBJETO, NOMEPROPOBJETO, IDTIPOOBJETO) VALUES (26, ''OwnerData'', 4)'; -- OwnerData do Lookup
END IF;	
	

/*******************************************************************
						ZTEMPLATEPARAMETRO
*******************************************************************/
SELECT COUNT(*) INTO nCount FROM USER_TABLES WHERE TABLE_NAME = 'ZTEMPLATEPARAMETRO';
IF(nCount <= 0) THEN
EXECUTE IMMEDIATE 
		'CREATE TABLE ZTEMPLATEPARAMETRO
		(
			NOMEPROJETO					VARCHAR(50)		NOT NULL,
			NOMECAMPO 					VARCHAR(50) 	NOT NULL,
			DESCRICAOCAMPO 				VARCHAR(100) 	NULL,
			IDTIPOOBJETO 				NUMBER(10,0)	NULL,
			IDTIPOOBJETOSEGUNDONIVEL 	NUMBER(10,0)	NULL,
			CONTEXTO					VARCHAR(5)		NULL,
			RECCREATEDBY 				VARCHAR(50) 	NULL,
			RECCREATEDON 				DATE	 		NULL,
			RECMODIFIEDBY 				VARCHAR(50) 	NULL,
			RECMODIFIEDON 				DATE	 		NULL,
			
			CONSTRAINT PK_ZTEMPLATEPARAMETRO PRIMARY KEY(NOMEPROJETO, NOMECAMPO),
			CONSTRAINT FK_ZTEMPLATEPARAMETRO_ZTEMPL FOREIGN KEY (IDTIPOOBJETO) REFERENCES ZTEMPLATETIPOOBJETO (IDTIPOOBJETO),
			CONSTRAINT FK_ZTEMPLATEPARAMETRO_ZTEMPLSN FOREIGN KEY (IDTIPOOBJETOSEGUNDONIVEL) REFERENCES ZTEMPLATETIPOOBJETO (IDTIPOOBJETO)
		)';
		
EXECUTE IMMEDIATE 
		'CREATE UNIQUE INDEX IX_ZTEMPLATEPARAMETRO ON ZTEMPLATEPARAMETRO(NOMEPROJETO, NOMECAMPO, IDTIPOOBJETO) TABLESPACE RM_INDICES';
EXECUTE IMMEDIATE 		
		'CREATE UNIQUE INDEX IX_ZTEMPLATEPARAMETROSN ON ZTEMPLATEPARAMETRO(NOMEPROJETO, NOMECAMPO, IDTIPOOBJETOSEGUNDONIVEL) TABLESPACE RM_INDICES';
END IF;


/*******************************************************************
						ZTEMPLATEPARAMETROVALOR
*******************************************************************/
SELECT COUNT(*) INTO nCount FROM USER_TABLES WHERE TABLE_NAME = 'ZTEMPLATEPARAMETROVALOR';
IF(nCount <= 0) THEN
EXECUTE IMMEDIATE 
		'CREATE TABLE ZTEMPLATEPARAMETROVALOR
		(
			CODCOLIGADA 				NUMBER(10,0)	NOT NULL,
			CODFILIAL					NUMBER(10,0)	NOT NULL,
			CODTIPOCURSO				NUMBER(10,0)	NOT NULL,	
			NOMEPROJETO					VARCHAR(50)		NOT NULL,
			NOMECAMPO 					VARCHAR(50) 	NOT NULL,
			VALOR 						VARCHAR(1000) 	NULL,
			RECCREATEDBY 				VARCHAR(50) 	NULL,
			RECCREATEDON 				DATE	 		NULL,
			RECMODIFIEDBY 				VARCHAR(50) 	NULL,
			RECMODIFIEDON 				DATE	 		NULL,
			
			CONSTRAINT PK_ZTEMPLATEPARAMETROVALOR PRIMARY KEY(CODCOLIGADA, CODFILIAL, CODTIPOCURSO, NOMEPROJETO, NOMECAMPO),
			CONSTRAINT FK_ZTEMPLATEPARVALOR_ZTEMPL FOREIGN KEY(NOMEPROJETO, NOMECAMPO) REFERENCES ZTEMPLATEPARAMETRO (NOMEPROJETO, NOMECAMPO)			
		)';
END IF;

SELECT COUNT(*) INTO nCount FROM USER_TAB_COLS WHERE COLUMN_NAME = 'CODCOLIGADAENTIDADE' AND TABLE_NAME = 'ZTEMPLATEPARAMETROVALOR';
IF(nCount <= 0) THEN
EXECUTE IMMEDIATE 
	'ALTER TABLE ZTEMPLATEPARAMETROVALOR ADD (CODCOLIGADAENTIDADE INT NULL)';
END IF;

SELECT COUNT(*) INTO nCount FROM USER_TAB_COLS WHERE COLUMN_NAME = 'VALOR2' AND TABLE_NAME = 'ZTEMPLATEPARAMETROVALOR';
IF(nCount <= 0) THEN
EXECUTE IMMEDIATE 
	'ALTER TABLE ZTEMPLATEPARAMETROVALOR ADD (VALOR2 VARCHAR(200))';
END IF;


/*******************************************************************
						ZTEMPLATEPARAMETROPROPOBJETO
*******************************************************************/
SELECT COUNT(*) INTO nCount FROM USER_TABLES WHERE TABLE_NAME = 'ZTEMPLATEPARAMETROPROPOBJETO';
IF(nCount <= 0) THEN
EXECUTE IMMEDIATE 
		'CREATE TABLE ZTEMPLATEPARAMETROPROPOBJETO
		(
			NOMEPROJETO					VARCHAR(50)		NOT NULL,
			NOMECAMPO 					VARCHAR(50) 	NOT NULL,
			IDPROPOBJETO 				NUMBER(10,0)	NOT NULL,
			IDTIPOOBJETO 				NUMBER(10,0)	NOT NULL,
			VALOR 						VARCHAR(100) 	NULL,
			RECCREATEDBY 				VARCHAR(50) 	NULL,
			RECCREATEDON 				DATE			NULL,
			RECMODIFIEDBY 				VARCHAR(50) 	NULL,
			RECMODIFIEDON 				DATE			NULL,
			
			CONSTRAINT PK_ZTEMPLATEPARAMETROPROPOBJ PRIMARY KEY(NOMEPROJETO, NOMECAMPO, IDPROPOBJETO),
			CONSTRAINT FK_ZPARAMPROPOBJ_ZPARAMETRO FOREIGN KEY (NOMEPROJETO, NOMECAMPO) REFERENCES ZTEMPLATEPARAMETRO (NOMEPROJETO, NOMECAMPO),
			CONSTRAINT FK_ZPARAMPROPOBJ_ZPROPOBJETO FOREIGN KEY (IDPROPOBJETO) REFERENCES ZTEMPLATEPROPOBJETO (IDPROPOBJETO)
		)';
END IF;


/*******************************************************************
						ZTEMPLATEPARAMSEGNIVELPROPOBJ
*******************************************************************/
SELECT COUNT(*) INTO nCount FROM USER_TABLES WHERE TABLE_NAME = 'ZTEMPLATEPARAMSEGNIVELPROPOBJ';
IF(nCount <= 0) THEN
EXECUTE IMMEDIATE 
		'CREATE TABLE ZTEMPLATEPARAMSEGNIVELPROPOBJ
		(
			NOMEPROJETO					VARCHAR(50)		NOT NULL,
			NOMECAMPO 					VARCHAR(50) 	NOT NULL,
			IDPROPOBJETO 				NUMBER(10,0)	NOT NULL,			
			IDTIPOOBJETO 				NUMBER(10,0)	NOT NULL,
			VALOR 						VARCHAR(100) 	NULL,
			RECCREATEDBY 				VARCHAR(50) 	NULL,
			RECCREATEDON 				DATE			NULL,
			RECMODIFIEDBY 				VARCHAR(50) 	NULL,
			RECMODIFIEDON 				DATE	 		NULL,
			
			CONSTRAINT PK_ZTEMPLATEPARAMSEGNIVPROPOB PRIMARY KEY(NOMEPROJETO, NOMECAMPO, IDPROPOBJETO),
			CONSTRAINT FK_ZPARAMPROPOBJ_ZPARAMETROSN FOREIGN KEY (NOMEPROJETO, NOMECAMPO) REFERENCES ZTEMPLATEPARAMETRO (NOMEPROJETO, NOMECAMPO),
			CONSTRAINT FK_ZPARAMPROPOBJ_ZPROPOBJETOSN FOREIGN KEY (IDPROPOBJETO) REFERENCES ZTEMPLATEPROPOBJETO (IDPROPOBJETO)
		)';
END IF;


/*******************************************************************
						ZTEMPLATEPARAMETROMULTIPLO
*******************************************************************/
SELECT COUNT(*) INTO nCount FROM USER_TABLES WHERE TABLE_NAME = 'ZTEMPLATEPARAMETROMULTIPLO';
IF(nCount <= 0) THEN
EXECUTE IMMEDIATE 
		'CREATE TABLE ZTEMPLATEPARAMETROMULTIPLO
		(
			CODCOLIGADA 	NUMBER(10,0)	NOT NULL,
			CODFILIAL		NUMBER(10,0)	NOT NULL,
			CODTIPOCURSO	NUMBER(10,0)	NOT NULL,			
			NOMEPROJETO		VARCHAR(50)		NOT NULL,
			NOMECAMPO 		VARCHAR(50) 	NOT NULL,
			VALOR 			VARCHAR(200) 	NOT NULL,
			DESCRICAO		VARCHAR(200) 	NULL,						
			RECCREATEDBY 	VARCHAR(50) 	NULL,
			RECCREATEDON 	DATE	 		NULL,
			RECMODIFIEDBY 	VARCHAR(50) 	NULL,
			RECMODIFIEDON 	DATE			NULL,
			
			CONSTRAINT PK_ZTEMPLATEPARAMETROMULTIPLO PRIMARY KEY(CODCOLIGADA, CODFILIAL, CODTIPOCURSO, NOMEPROJETO, NOMECAMPO, VALOR),
			CONSTRAINT FK_ZPARAMETROMULTIPLO_ZPARAM FOREIGN KEY (NOMEPROJETO, NOMECAMPO) REFERENCES ZTEMPLATEPARAMETRO(NOMEPROJETO, NOMECAMPO)
		)';
END IF;
END;