how to genarate random numbers in oracle for particular row?

Answers were Sorted based on User's Feedback



how to genarate random numbers in oracle for particular row?..

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

how to genarate random numbers in oracle for particular row?..

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

how to genarate random numbers in oracle for particular row?..

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

Post New Answer

More Oracle General Interview Questions

What is data file?

0 Answers  


How many data types are supported?

0 Answers  


What is hash cluster in oracle?

0 Answers  


Tell me New Feature of Oracle 10g?

5 Answers   Thermotech,


How to load data from external tables to regular tables?

0 Answers  






How to display First 4 rows From Database Table?

6 Answers  


how to select alphabets in a one column , for this the table name is PA_TASKS and column name is TASK_NUMBER, In TASK_NUMBER the data like this 1.1.3NN,1.1.4NN,1.5.1NN,1.3.2NE,1.5NN,1NN,1.2NE,1CE , For this i need to disply output as only NN,but not other alphabets, if NN is thre means i should display , otherwise leave that blank or empty Its some urgent requirement ,thanks in advance

2 Answers  


How to create a new table in your schema?

0 Answers  


How to insert multiple rows with one insert statement in oracle?

0 Answers  


How to define a specific record type?

0 Answers  


what is port in oracle? how is it related to database application.

0 Answers  


What is system tablespace?

0 Answers  


Categories
  • Oracle General Interview Questions Oracle General (1789)
  • Oracle DBA (Database Administration) Interview Questions Oracle DBA (Database Administration) (261)
  • Oracle Call Interface (OCI) Interview Questions Oracle Call Interface (OCI) (10)
  • Oracle Architecture Interview Questions Oracle Architecture (90)
  • Oracle Security Interview Questions Oracle Security (38)
  • Oracle Forms Reports Interview Questions Oracle Forms Reports (510)
  • Oracle Data Integrator (ODI) Interview Questions Oracle Data Integrator (ODI) (120)
  • Oracle ETL Interview Questions Oracle ETL (15)
  • Oracle RAC Interview Questions Oracle RAC (93)
  • Oracle D2K Interview Questions Oracle D2K (72)
  • Oracle AllOther Interview Questions Oracle AllOther (241)