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
How to open a cursor variable?
Why do you create or replace procedures rather that drop and recreate.
Can objects of the same schema reside in different tablespace?
What is oracle instant client?
What is the maximum number of triggers that can be applied to a single table?
Which is better Oracle or MS SQL? Why?
What happens to the indexes if a table is recovered?
In Oracle Clinical 4.5.0, can the VIEW_TEMPLATE_ID column in DATA_EXTRACT_VIEWS table contain NULL value?
Is oracle the best database?
What do you understand by a database object?
ABOUT IDENTITY?
Explain the use of record length option in exp command.
What is oracle and what are its different editions?
Compare and contrast between sql and sql server and explain its various functions?
nw i'm doing MBA system and planning to do oracle,database management.tell me that whether it is useful r not?.refer any course for my carrier pls