Re: AW: [PHP] Oracle question

From: Date: Tue, 10 Jul 2001 11:26:38 +0000
Subject: Re: AW: [PHP] Oracle question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-57133@lists.php.net to get a copy of this message
PL/SQL code for an Oracle trigger that will auto-increment specified field: create or replace trigger <trigger> before insert on <table> for each row begin if :new.<field> is null then select <sequence-name>.nextval into :new.<field> from dual; end if; end; You have to create a sequence first. Example: CREATE SEQUENCE <sequence-name> INCREMENT BY 1 START WITH -99999999999999999999999999 MAXVALUE 9999999999999999999999999999999999999999999999 MINVALUE -999999999999999999999999999999999999999999999 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. -Stathis. 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 : > http://conf.php.net/oci2 > http://conf.php.net/pres/slides/oci/paper.txt > > which features a small non-trigger-work-around > > sebastian > > > -----Ursprόngliche Nachricht----- > > Von: Duy B [mailto:ngo_duy@fmail.vnn.vn] > > Gesendet: Dienstag, 10. Juli 2001 04:36 > > An: php-general@lists.php.net > > 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 > >

« previous php.general (#57133) next »