Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Default column value of MAX +1 of column - possible in Oracle 9i?
David FitzGerald wrote:
> Hello -
>
> I'm trying to do something which I think ought to be simple, but am
> finding hard!
>
> I have a table which I want the default value of the "ID" column to be
> "MAX(ID)+1" - I can't get this to work. Is this possible to do, or am
> I barking up the wrong tree? The reason I need to do this is that an
> application needs to add to this table, but will not be able to do a
> "select MAX(ID)+1 from emp" before it inserts the new row. It also
> can't do a subselect in its insert. A PITA!
>
> I have thought about using a sequence instead, but this would require
> changing application code which I am reluctant to do.
You could put a 'before insert' trigger on the table to select from a sequence.
-- Preston.Received on Thu Mar 24 2005 - 10:16:12 CST