PL/SQL code for an Oracle trigger that will auto-increment specified
create or replace trigger <trigger>
before insert on <table>
for each row
if :new.<field> is null then
select <sequence-name>.nextval into :new.<field> from dual;
You have to create a sequence first. Example:
CREATE SEQUENCE <sequence-name>
INCREMENT BY 1
START WITH -99999999999999999999999999
CYCLE CACHE 5 ORDER;
Of course, replace values in <xxx> as needed.
If you use the aboce code verbatim, you will a field incrementing from
-99999... until 99999 and then it will begin all over again.
Sebastian Stadtlich wrote:
> oracle does not have an autoincrement.
> it has the more powerfull concept of TRIGGERS
> unfortunatelly you have to write them in pl/sql or java...
> have a look on the net for oracle trigger tutorial or
> you can
> find a super oracle-feature-documentation here :
> which features a small non-trigger-work-around
> > -----Urspr&oacgr;ngliche Nachricht-----
> > Von: Duy B [mailto:[EMAIL PROTECTED]]
> > Gesendet: Dienstag, 10. Juli 2001 04:36
> > An: [EMAIL PROTECTED]
> > Betreff: [PHP] Oracle question
> > Dear all,
> > If i want to use id field in Oracle database, how can i do?
> > For example, in MySQL
> > create table test (
> > id int not null auto-increment primary key,
> > ten char(10));
> > So that, when i insert a new row into MySQL database, id
> > increases by 1.
> > But in Oracle i couldn't use as that.
> > Somebody could help me.
> > Thanks you all,
> > BaoDuy
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]