Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Auto/Incrementing number?? Beginner needs help!
A copy of this was sent to "Dan Gibbons" <Daniel.Gibbons_at_Sebank.co.uk>
(if that email address didn't require changing)
On Mon, 30 Nov 1998 14:12:49 -0000, you wrote:
>Hi,
>
>I have just been given an Oracle database (of which I know absolutly nothing
>about) and have a really simple task which I just can't do! All I need to
>do is create a table with an auto incrementing number field like in SQL or
>Access (which is very is to do!).
>
>I have an Oracle users guide which mentions using a sequence. But where do
>I use a sequence? And how do I insert a new record into the table with it's
>unique auto number?
>
>If someone could please tell me the anwser to this most simple question then
>I would be most greatful.
>
it could look like this:
SQL> create table test ( x int primary key, data int );
Table created.
SQL> create sequence test_seq;
Sequence created.
SQL> create trigger test_trigger before insert on test for each row
2 begin
3 select test_seq.nextval into :new.x from dual;
4 end;
5 /
Trigger created.
SQL> insert into test ( data ) values ( 55 );
1 row created.
SQL> select * from test;
X DATA
---------- ----------
1 55
>Thanks
>
>Dan
>
>
>
Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA
--
http://govt.us.oracle.com/ -- downloadable utilities
Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Mon Nov 30 1998 - 10:04:36 CST