how to genarate random numbers in oracle for particular row?
Answers were Sorted based on User's Feedback
Answer / tanoy guhasarkar
the DBMS_RANDOM package provides a built-in random number
generator utility.
Using In Side A Block:--
DECLARE
my_random BINARY_INTEGER;
BEGIN
my_random := DBMS_RANDOM.RANDOM;
dbms_output.put_line(my_random);
end ;
Executing This Code, We Will Get A Random Number Every Time...
In Side A Select Statement :--
select DBMS_RANDOM.RANDOM from dual;
Note:--
This DBMS_RANDOM package included in oracle after oracle 8.
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / 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 |
Answer / swamireddy
first take table. the table contain a more than one row.
write query display the row randomly.
SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1
| Is This Answer Correct ? | 1 Yes | 5 No |
From the database level, how can you tell under which time zone a database is operating?
How to create a server parameter file?
20. Using a set operator, display the client number of all clients who have never placed an order.
does Oracle has only one table space?
10. Display the client number, order date and shipping date for all orders where the shipping date is between three and six months after the order date.
Explain user account with reference to oracle.
How many types of database triggers exist?
How to increment dates by 1 in oracle?
What is max rowid in oracle?
What is the cache hit ratio, what impact does it have on performance of an Oracle database and what is involved in tuning it?
How to view the dropped tables in your recycle bin?
How many types of segments in Oracle?