José Perez
asked on
Create 1 million row in an Oracle Database?
Hi,
for testing purposes I need to create 1 Million rows in an Oracle 11G database.
Table: User
Columns:
Is there someway this can be achieved?
for testing purposes I need to create 1 Million rows in an Oracle 11G database.
Table: User
Columns:
ID
FirstName
LastName
MailAddress
Company
Is there someway this can be achieved?
ASKER
mmm so I have the following from Google:
I also have this for Strings:
SELECT TO_DATE(
TRUNC(
DBMS_RANDOM.VALUE(TO_CHAR(DATE '1999-01-01','J')
,TO_CHAR(DATE '2015-12-31','J')
)
),'J'
) FROM DUAL;
I also have this for Strings:
DBMS_RANDOM.STRING
opt IN CHAR,
len IN NUMBER)
RETURN VARCHAR2;
but now how would the query be to mix both of them? (it is the first time I see something like this can be achievable)
>>but now how would the query be to mix both of them?
You just use dbms_random for the column and data type you want. If you want a number, use VALUE. If you want a string use STRING.
If you want a random length string, use VALUE for the len parameter of the STRING function.
I suggest you play around with simple examples using sqlplus to learn what they are doing:
select dbms_random.value(100,200) from dual;
select dbms_random.string('a',10) from dual;select dbms_random.string('a',dbm s_random.v alue(10,20 )) from dual;
Run each one several times to get the idea.
You just use dbms_random for the column and data type you want. If you want a number, use VALUE. If you want a string use STRING.
If you want a random length string, use VALUE for the len parameter of the STRING function.
I suggest you play around with simple examples using sqlplus to learn what they are doing:
select dbms_random.value(100,200)
select dbms_random.string('a',10)
Run each one several times to get the idea.
ASKER
Ok, I have play with it and think I understand the idea, but when I tried to apply to my query it fails saying there is a missing parenthesis, can you please check my syntax?
If I run the query without DBMS_RANDOM it does it with no issues:
If I run the query without DBMS_RANDOM it does it with no issues:
INSERT INTO tblUser
(id, FirstName, LastName, MailAddress, Company)
VALUES
(
'1',
'Oscar',
'Garin',
'mrgari@gmail.com',
'01-01-2015');
If I do it replacing 1 column (FirstName) to match the random function, it fails:INSERT INTO tblUser
(id, FirstName, LastName, MailAddress, Company)
VALUES
(
'1',
DBMS_RANDOM.string('L' 20)
(SELECT * FROM
(SELECT FirstName FROM tblUser ORDER BY DBMS_RANDOM.VALUE
)
WHERE ROWNUM = 1),
'Garin',
'mrgari@gmail.com',
'01-01-2015');
INSERT INTO ... VALUES ... is not the correct syntax.
INSERT INTO ... SELECT ... is.
No idea what you are trying to do with the SELECT from tblUser but it probably isn't going to work. It will jusst select the first row and use that for everything so why bother.
Your columns also need to match.
You specify 5 on the insert side but look like you are trying to select 6.
Try this but it is untested:
INSERT INTO ... SELECT ... is.
No idea what you are trying to do with the SELECT from tblUser but it probably isn't going to work. It will jusst select the first row and use that for everything so why bother.
Your columns also need to match.
You specify 5 on the insert side but look like you are trying to select 6.
Try this but it is untested:
INSERT INTO tblUser
(id, FirstName, LastName, MailAddress, Company)
select
'1',
DBMS_RANDOM.string('L' 20),
'Garin',
'mrgari@gmail.com',
'01-01-2015' from dual;
ASKER
Not working, same error "missing right parenthesis"
ASKER
also this working query does not work when I add your predicate "connect be level<1000000);"
INSERT INTO tblUser
(id, FirstName, LastName, MailAddress, Company)
VALUES
(
'1',
'Oscar',
'Garin',
'mrgari@gmail.com',
'01-01-2015') connect be level<1000000);
This does not work ? I have modified slightwv's select:
INSERT INTO tblUser
select
'1',
DBMS_RANDOM.string('L' 20),
'Garin',
'mrgari@gmail.com',
'01-01-2015' from dual;
Also "connect be" ought to be "connect by".
INSERT INTO tblUser
select
'1',
DBMS_RANDOM.string('L' 20),
'Garin',
'mrgari@gmail.com',
'01-01-2015' from dual;
Also "connect be" ought to be "connect by".
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent!
If you want random values for names and addresses use dbms_random.string. The docs have the usage.