2
I have the following query:
INSERT INTO TB_CLASSIFICACAO_UG
(COD_CLASSIFICACAO_UG, TXT_DESCRICAO, IND_ATIVO)
VALUES
(SEQ_COD_TB_CLASSIFICACAO_UG.nextval, 'TESTANDO', 1)
WHERE
(SELECT COUNT(TXT_DESCRICAO) FROM TB_CLASSIFICACAO_UG WHERE TXT_DESCRICAO = 'TESTANDO') = 0
This query generates the error:
"SQL command not properly ended"
But if I turn only the first part it works.
INSERT INTO TB_CLASSIFICACAO_UG
(COD_CLASSIFICACAO_UG, TXT_DESCRICAO, IND_ATIVO)
VALUES
(SEQ_COD_TB_CLASSIFICACAO_UG.nextval, 'TESTANDO', 1)
And if I turn the second part too.
(SELECT COUNT(TXT_DESCRICAO) FROM TB_CLASSIFICACAO_UG WHERE TXT_DESCRICAO = 'TESTANDO') = 0
I wonder what I’m doing wrong?
What I want after all is like an INSERT IF NOT EXISTS. Any query suggestions? I’ve tried other ways than this and it didn’t work.
What is this DUP_VAL_ON_INDEX
– Joao Paulo
It is a type of exception that Oracle throws when there is index duplicity (Duplication of value on index)
– PedroSena
But how does he know that the index is the TXT_DESCRICAO?
– Joao Paulo
I figured since you intend to avoid duplication of a certain field you could have added an index to it, this is not necessarily true but it can be interesting especially if you intend to do this check often
– PedroSena