Most of the times, production data is not available in development environments. Here, I would like to share a single sql command which can generate random data. But before that, let’s address another issue faced by a lot of new oracle users. We need to generate a sequence of numbers using a sql statement. This will generate a number sequence. Nothing fancy, simplest of sql known :) Here it is:
Now, to generate the random data, the oracle build in package “dbms_random” comes handy. I am referring to the version 10GR2, there might be additional features available on 11G . Other build in functions can also be used. Here is a sample sql:
There are numerous functions which can be used to generate randomized data in different ways. Best is to create a wrapper package which can generate number, string, date etc based on the parameter passed and then call that package. I will share it as soon as I am done writing it.
I was looking for something like this and i was using the rowNum mod in the where clause but wasn’t pulling exactly what i wanted. This worked well, nice Job!
I was looking for something like this and i was using the rowNum mod in the where clause but wasn’t pulling exactly what i wanted. This worked well, nice Job!
thank of your effort
create table employee as (SELECT LEVEL empl_id,
MOD (ROWNUM, 50000) dept_id,
TRUNC (DBMS_RANDOM.VALUE (1000, 500000), 2) salary,
DECODE (ROUND (DBMS_RANDOM.VALUE (1, 2)), 1, ‘M’, 2, ‘F’) gender,
TO_DATE ( ROUND (DBMS_RANDOM.VALUE (1, 28))
|| ‘-‘
|| ROUND (DBMS_RANDOM.VALUE (1, 12))
|| ‘-‘
|| ROUND (DBMS_RANDOM.VALUE (1900, 2010)),
‘DD-MM-YYYY’
) dob,
DBMS_RANDOM.STRING (‘x’, DBMS_RANDOM.VALUE (20, 50)) address
FROM DUAL
CONNECT BY LEVEL < 10000);
nice job, awesome query, specially when we wanted to popullet the table with dummy data.
Thank you
Mohammad Shahnawaz
good article