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

What is the data pump import utility?

797


Does oracle charge for java?

828


How to list all tables in your schema?

810


21. Using a set operator, display the client number of all clients who have ever placed an order and whose whose name does not contain the string Sm.

1834


How is it different from a normal table?

803


How to load data through external tables?

884


Explain the use of ignore option in imp command.

794


Give the various rollback segment states.

823


How many types of tables are there in oracle?

823


How to convert characters to times in oracle?

784


what are steps for interface? where is exchange rate defined in which table?

1759


How to define a data source name (dsn) in odbc manager?

798


Can we store images in oracle database?

761


Why does oracle 9i treat an empty string as null?

760


What is oracle datasource?

773