How can we manage the gap in a primary key column created
by a sequence?
Ex:a company has empno as primary key generated by a
sequence and some employees leaves in between.What is the
best way to manage this gap?
Answer Posted / harikanthkoneti
yes...yes........ you can do it simply by updating that
table using rownum yar. see my example below.
SQL> create table test(sno number(2),sname varchar2(20));
Table created.
now if you have the data in the table like follows.
SQL> select * from test;
SNO SNAME
---------- --------------------
1 sdf
3 sdf
6 ewr
7 rt
90 drt
now just do the following simple statement.
SQL> update test set sno=rownum;
5 rows updated.
now here is the o/p for eliminating the gap generated by the
sequence.
SQL> select * from test;
SNO SNAME
---------- --------------------
1 sdf
2 sdf
3 ewr
4 rt
5 drt
then do the commit. thats all....................
now enjoy with this coding
suppose if you want to allocate the with any kind of series
of values for updating the table just follow the below
procedure
SQL> update test set sno=sql.nextval;
NOTE:sql is the sequence.
this statement will updates ur table with
what ever you given with the start with value and it ll
increment by which value you had given in the increment by
clause.
| Is This Answer Correct ? | 1 Yes | 3 No |
Post New Answer View All Answers
What are ddl statements in oracle?
How to calculate date and time differences in oracle?
 What are the oracle DML commands possible through an update strategy?
How to rename a tablespace in oracle?
What are the oracle built-in data types?
How to turn on or off recycle bin for the instance?
How can I introduce multiple conditions in like operator?
How to create a new oracle data file?
What privilege is needed for a user to query tables in another schema?
Differentiate between post-database commit and post-form commit?
What is an oracle user role?
How to start your 10g xe server?
How to increment dates by 1 in oracle?
If any one has information regarding interview of NIC (National Informatics Centre),it would be of great help...
How to run queries on external tables?