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:
ID
FirstName
LastName
MailAddress
Company

Is there someway this can be achieved?
LVL 2
José PerezAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
insert into user (select rownum,'first','last','address','company' from dual connect be level<1000000);

If you want random values for names and addresses use dbms_random.string.  The docs have the usage.
José PerezAuthor Commented:
mmm so I have the following from Google:

  SELECT TO_DATE(
              TRUNC(
                   DBMS_RANDOM.VALUE(TO_CHAR(DATE '1999-01-01','J')
                                    ,TO_CHAR(DATE '2015-12-31','J')
                                    )
                    ),'J'
               ) FROM DUAL;

Open in new window


I also have this for Strings:
DBMS_RANDOM.STRING
   opt  IN  CHAR,
   len  IN  NUMBER)
  RETURN VARCHAR2;

Open in new window

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)
slightwv (䄆 Netminder) Commented:
>>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',dbms_random.value(10,20)) from dual;

Run each one several times to get the idea.
SolarWinds® VoIP and Network Quality Manager(VNQM)

WAN and VoIP monitoring tools that can help with troubleshooting via an intuitive web interface. Review quality of service data, including jitter, latency, packet loss, and MOS. Troubleshoot call performance and correlate call issues with WAN performance for Cisco and Avaya calls

José PerezAuthor Commented:
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:
INSERT INTO tblUser 
  (id, FirstName, LastName, MailAddress, Company) 
VALUES
    (
    '1', 
    'Oscar',
      'Garin', 
      'mrgari@gmail.com', 
      '01-01-2015');

Open in new window

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');

Open in new window

slightwv (䄆 Netminder) Commented:
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 tblUser 
  (id, FirstName, LastName, MailAddress, Company) 
select 
    '1', 
        DBMS_RANDOM.string('L' 20),
      'Garin', 
      'mrgari@gmail.com', 
      '01-01-2015' from dual;

Open in new window

José PerezAuthor Commented:
Not working, same error "missing right parenthesis"
José PerezAuthor Commented:
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);

Open in new window

Helena Markováprogrammer-analystCommented:
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".
slightwv (䄆 Netminder) Commented:
>>also this working query does not work when I add your predicate "connect be level<1000000);"

You cannot mix the VALUES and SELECT versions of insert.

connect by level is part of a SELECT.

>>Not working, same error "missing right parenthesis"

I just copied and pasted what you had.  There was a missing comma between the 'L' and 20 in dbms_random.string.

INSERT INTO tblUser 
  (id, FirstName, LastName, MailAddress, Company) 
select 
    '1', 
        DBMS_RANDOM.string('L',20),
      'Garin', 
      'mrgari@gmail.com', 
      '01-01-2015' from dual;

Open in new window



This works and generates 100 rows:
create table tblUser (id varchar2(20), FirstName varchar2(20), LastName varchar2(20), MailAddress varchar2(20), Company varchar2(20)) ;

INSERT INTO tblUser 
  (id, FirstName, LastName, MailAddress, Company) 
select 
    '1', 
        DBMS_RANDOM.string('L',20),
      'Garin', 
      'mrgari@gmail.com', 
      '01-01-2015' from dual connect by level<=100;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
José PerezAuthor Commented:
Excellent!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.