how to genarate random numbers in oracle for particular row?

Answer Posted / nusrath sultana

We can make use of sequence to generate random numbers.
example:
SQL> create sequence seq1 start with 1 increment by 1
maxvalue 100;
SQL>Sequence created.

SQL> create table dup(rollno number(10) primary key,name
varchar2(20) not null);

Table created.

SQL> insert into dup values(seq1.nextval,'&name');
Enter value for name: SAM
old 1: insert into dup values(seq1.nextval,'&name'
new 1: insert into dup values(seq1.nextval,'SAM')

1 row created.

SQL> /

Enter value for name: RAM
old 1: insert into dup values(seq1.nextval,'&name'
new 1: insert into dup values(seq1.nextval,'RAM')

1 row created.

SQL> /
Enter value for name: REENA
old 1: insert into dup values(seq1.nextval,'&name'
new 1: insert into dup values(seq1.nextval,'REENA'

1 row created.

SQL> /
Enter value for name: TINA
old 1: insert into dup values(seq1.nextval,'&name'
new 1: insert into dup values(seq1.nextval,'TINA')

1 row created.

SQL> /
Enter value for name: MONA
old 1: insert into dup values(seq1.nextval,'&name'
new 1: insert into dup values(seq1.nextval,'MONA')

1 row created.

SQL> SELECT * FROM DUP;

ROLLNO NAME
---------- --------------------
1 SAM
2 RAM
3 REENA
4 TINA
5 MONA

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can we force the database to use the user specified rollback segment?

826


Whats the benefit of dbms_stats over analyze?

1704


What is Trigger in Oracle?

792


What are the uses of synonyms?

840


How to create a new table by selecting rows from another table?

832


does the query needs a hint to access a materialized view?

1654


normally database take to refresh time 2 hours. but client asked iwant to refresh with in 5 min that same database. do you have any option in BO and Oracle? explain me briefly...kavi

1953


What are the differences between date and timestamp in oracle?

791


Hi friends can u send the oracle 9i full version download link?????????????? please reply ?

1632


How are extents allocated to a segment?

789


Explain oracle’s server parameter file.

754


How do I call oracle stored procedures that take no parameters?

790


 How to use an oracle sequence generator in a mapping?

806


What is a cursor variable?

792


defination of bitmap index

1807