Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Unique numeric column in Oracle V7.3
Ian Douglas wrote:
> I am an Oracle newbie. Could someone please tell me how to create a
> column with in an Oracle Table that has an automatically unique
> sequential number. I have looked at the rowid column, but this is no
> good to me because I need to specify the column name.
>
> Any help in what must surely be a very simple operation would be
> appreciated.
> --
> Ian Douglas
Define the column as a number (length is up to you).
CREATE TABLE xx
( row_nbr NUMBER(10)
);
Then create a sequence number that has the same length as your column (Can't remember the syntax for this. Just look it up in the Oracle documentation). Let's call the sequence SEQ_ROW_NBR.
When you insert into the table, just issue this :
INSERT INTO xx (row_nbr)
VALUES (SEQ_ROW_NBR.NEXTVAL);
Use 'SELECT SEQ_ROW_NBR.CURRVAL FROM DUAL' if you want to know what the
highest current sequence number is.
Hope this helps.
Fenella Received on Wed Sep 24 1997 - 00:00:00 CDT
![]() |
![]() |