Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1050367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:45:37+00:00 2026-05-16T16:45:37+00:00

I need to create a Oracle tables with random number of columns for load

  • 0

I need to create a Oracle tables with random number of columns for load testing. I just want to specify number of columns with type NUMBER, number of columns with type VARCHAR2 etc and the fields should be generated automatically. Also, I will be filling up the tables with random data for which I will be using dbms_random.

How can I achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:45:37+00:00Added an answer on May 16, 2026 at 4:45 pm

    “I just want to specify number of
    columns with type NUMBER, number of
    columns with type VARCHAR2 etc and the
    fields should be generated
    automatically.”

    The following procedure does just that. Note that it is rather basic; you might want to make it more sophisticated, for example by varying the length of the varchar2 columns:

    SQL> create or replace procedure bld_table
      2      ( p_tab_name in varchar2
      3        , no_of_num_cols in pls_integer
      4        , no_of_var_cols in pls_integer
      5        , no_of_date_cols in pls_integer
      6      )
      7  as
      8  begin
      9      execute immediate 'create table '||p_tab_name||' ('
     10                        ||' pk_col number not null'
     11                        ||', constraint '||p_tab_name||'_pk primary key (pk_col) using index)';
     12      << numcols >>
     13      for i in 1..no_of_num_cols loop
     14          execute immediate 'alter table '||p_tab_name||' add '
     15                            ||' col_n'||trim(to_char(i))||' number';
     16      end loop numcols;
     17      << varcols >>
     18      for i in 1..no_of_var_cols loop
     19          execute immediate 'alter table '||p_tab_name||' add '
     20                            ||' col_v'||trim(to_char(i))||' varchar2(30)';
     21      end loop varcols;
     22      << datcols >>
     23      for i in 1..no_of_date_cols loop
     24          execute immediate 'alter table '||p_tab_name||' add '
     25                            ||' col_d'||trim(to_char(i))||' date';
     26      end loop datcols;
     27  end bld_table;
     28  /
    
    Procedure created.
    
    SQL>
    

    Here it is in action:

    SQL> exec bld_table ('T23', 2, 3, 0)
    
    PL/SQL procedure successfully completed.
    
    SQL> desc t23
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     PK_COL                                    NOT NULL NUMBER
     COL_N1                                             NUMBER
     COL_N2                                             NUMBER
     COL_V1                                             VARCHAR2(30 CHAR)
     COL_V2                                             VARCHAR2(30 CHAR)
     COL_V3                                             VARCHAR2(30 CHAR)
    
    SQL>
    

    We can also use dynamic SQL to populate the table with rows of random data.

    SQL> create or replace procedure pop_table
      2          ( p_tab_name in varchar2
      3        , p_no_of_rows in pls_integer
      4      )
      5  as
      6   stmt varchar2(32767);
      7  begin
      8   stmt := 'insert into '||p_tab_name
      9                || ' select rownum ';
     10        for r in ( select column_name
     11                          , data_type
     12                          , data_length
     13                   from user_tab_columns
     14                   where table_name = p_tab_name
     15                  and column_name != 'PK_COL' )
     16        loop
     17            case r.data_type
     18           when 'VARCHAR2' then
     19               stmt := stmt ||', dbms_random.string(''a'', '||r.data_length||')';
     20           when 'NUMBER' then
     21               stmt := stmt ||', dbms_random.value(0, 1000)';
     22           when 'DATE' then
     23               stmt := stmt ||', sysdate + dbms_random.value(-1000, 0)';
     24            end case;
     25        end loop;
     26        stmt := stmt || ' from dual connect by level <= '||p_no_of_rows;
     27        execute immediate stmt;
     28  end pop_table;
     29  /
    
    Procedure created.
    
    SQL>
    

    Note that the primary key is populated with the ROWNUM so it will most likely fail if the table already contains rows.

    SQL> exec pop_table('T23', 4)
    
    PL/SQL procedure successfully completed.
    
    SQL> select * from t23
      2  /
    
        PK_COL     COL_N1     COL_N2 COL_V1                         COL_V2                         COL_V3
    ---------- ---------- ---------- ------------------------------ ----------------------------- ------------------------------
             1 913.797432 934.265814 NUtxjLoRQMCTLNMPKVGbTZwJeYaqnXTkCcWu WFRSHjXdLfpgVYOjzrGrtUoX jIBSoYOhSdhRFeEeFlpAxoanPabvwK
             2 346.879815 104.800387 NTkvIlKeJWybCTNEdvsqJOKyidNkjgngwRNN PPIOInbzInrsVTmFYcDvwygr RyKFoMoSiWTmjTqRBCqDxApIIrctPu
             3 93.1220275 649.335267 NTUxzPRrKKfFncWaeuzuyWzapmzEGtAwpnjj jHILMWJlcMjnlboOQEIDFTBG JRozyOpWkfmrQJfbiiNaOnSXxIzuHk
             4 806.709357 857.489387 ZwLLkyINrVeCkUpznVdTHTdHZnuFzfPJbxCB HnoaErdzIHXlddOPETzzkFQk dXWTTgDsIeasNHSPbAsDRIUEyPILDT
    
    4 rows selected.
    
    SQL>
    

    Again, there are all sorts of ways to improve the sophistication of the data.


    As an aside, using these sorts of data pools for load testing is not always a good idea. Performance problems are often caused by skews in the distribution of data values which you just aren’t going to get with DBMS_RANDOM. This is particularly true of some date columns – e.g. START_DATE – which would tend to be clustered together in real life but the above procedure will not generate that pattern. Similarly maxing out the varchar2 columns will lead to tables which take up more storage than they wlll under real-life usage.

    In short, randomly generated data is better than nothing but we need to understand its weaknesses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a lot of similar oracle jobs I need to create, and I'd
I have a oracle table called: create table InsertHere( generate_id varchar2(10), name varchar2(100) );
I have four DB tables in an Oracle database that need to be rewritten/refreshed
Hi guys I need to create a trigger in ORACLE 10g which ensures that
I need to create a table in Oracle that will store a series of
I'm familiar with Oracle's objects, nested tables, table() functions etc. But is it possible
Earlier I have created tables this way: create table workflow ( id number primary
I need create custom dialog and put JPanel into it. Is it possible?
i need create an email list sending to many emails. what is best solution
I need create clone repository. but I do not know where can I get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.