Inclusion of First Record using a select SUM

Asked

Viewed 28 times

1

In certain routine I have a Trigger that runs a code similar to the one below.

I’m having trouble in the first record, as in the first record does not have any code, the sum of + 1 is not being held, and I can’t do the Insert.

Have some way to play a default value, or some Oracle feature that bypasses when entering the first record?

INSERT INTO TABELA1                                                                  (
 CODIGO
,CAMPO2
,CAMPO3)

VALUES

(
(select max(CODIGO)+1 from TABELA1)
,VALOR2,
VALOR3)
);

1 answer

3

  • thanks to all, the nvl solved my problem, after that I decided to use the creation of sequence, and also worked well.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.