Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Increament

Re: Increament

From: Eric Comeau <ecomeau_at_sympatico.ca>
Date: Mon, 29 Oct 2001 06:36:25 -0500
Message-ID: <dfbD7.6097$Fy2.599253@news20.bellglobal.com>


try --> Select sysdate FROM dual

Dual is a "dummy" table which can used inside oracle to fetch say system variables, etc

I don't believe you can defined a table and specify the default value to be MyTableSEQ.nextVal in Oracle. You can though perform the following which would reduce the requirement for the trigger

INSERT INTO myTable(myTbaleSeq.nextVal)

But if you require the seqence number to tell the user before you insert the data, then you would have to perfomr a select on it and store it in a variable before you do the insert.

-EC

"Oliver Wong" <oliverwong_at_aforce.com> wrote in message news:3BDD10C5.660A8F8D_at_aforce.com...
> What is mean by "Dual"?
>
>
> Brian Tkatch wrote:
>
> > On Mon, 29 Oct 2001 12:02:22 +0800, Oliver Wong
> > <oliverwong_at_aforce.com> wrote:
> >
> > >How can I create a field that will increament by n?
> > >Thank you!
> > >
> > >
> > >
> >
> > Most probably you want to use a SEQUENCE and a TRIGGER.
> >
> > Check out the CREATE SEQUENCE command. By default it starts at one and
> > increments by one, but you can change both of these.
> >
> > The CREATE TRIGGER command can create a trigger that will
> > automatically put the number in the column.
> >
> > An example:
> >
> > CREATE TABLE MyTable (Id NUMBER PRIMARY KEY);
> >
> > CREATE SEQUENCE MyTableSEQ NOCACHE ORDER;
> >
> > CREATE OR REPLACE TRIGGER MyTableANR
> > BEFORE INSERT ON MyTable
> > FOR EACH ROW
> > BEGIN
> > SELECT MyTableSEQ.NEXTVAL INTO :NEW.Id FROM Dual;
> > END MyTableANR;
> > /
> >
> > Brian
>
Received on Mon Oct 29 2001 - 05:36:25 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US