Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > Oracle
|
Oracle General Oracle database discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 30th, 2004, 04:55 PM
Authorized User
 
Join Date: Sep 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default Enable auto numbering in an existing table

Hi everyone,

I have an Oracle table with some data. I want to edit a column in the table to start using auto numbering. I cannot figure out the SQL syntax to do so. I know there is an IDENTITY command in SQL Server, what is the equivalant in Oracle?

Thanks,

Pankaj

 
Old June 30th, 2004, 05:02 PM
Authorized User
 
Join Date: Jul 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Pankaj,

Let's say your table is

my_table( my_id number, my_column varchar2(10) )

Create a database sequence in Oracle as follows:

create sequence my_sequence start with 1 increment by 1 ;

Then, while inserting a record in the table "my_table", use the following command:

insert into my_table ( my_id, my_column ) values ( my_sequence.nextval, 'abcd' );

The construct "my_sequence.nextval" will give the value 1 the first time it is invoked and will increment thereafter. To check the current value, execute the following command:

select my_sequence.currval from dual;

Hope that helps.

Cheers,
AM







Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Numbering in Report View anukagni Access 7 March 7th, 2006 07:34 AM
Sequential numbering a non auto number field dbartelt Access 3 May 5th, 2005 02:56 PM
Add an attribute to existing table peter_budo SQL Language 9 April 24th, 2005 01:35 PM
Creating table with existing table without value kumar_kumar Oracle 1 January 4th, 2005 07:12 AM
select into non-temp table? (existing) nlicata SQL Server 2000 3 November 7th, 2003 03:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.