Search code examples
sqldatabaseoracleoracle-sqldeveloper

How to fill database with data


I would like to ask, how can I make insert script without I have to manually write it. Does exist some soft with GUI where I can write a data and it will generate me a script? I do my database in oracle sqldeveloper, but I can't find something like that. Thank you in advice.


Solution

  • If you mean you want to fill with dummy test data in a table, there are dozens of way to do it:

    Provided you have access to the data dictionary, here is one easy way to generate 20,000 records:

    insert into my_table
    select
       --<number of columns you want
       -- use dbms_random if you would like> 
    from
       dba_objects a,
       dba_objects b
    where
       rownum<=20000;
    

    This makes use of cartesian join with one of the large dictionary views that comes installed with Oracle dba_objects.

    PS: Cartesian join on large tables/views can become very slow, so use good judgement to restrict the result set.

    OTOH, if you want specific data and not some random stuff to be inserted into the table, you are stuck with the INSERT..VALUES syntax of Oracle wherein which you create a INSERT statement for each of the records. You might reduce the effort to convert your data(in CSV or some other standard format) by automating copy/paste stuff using features like macro available in some editors like Notepad++, sublime, etc.,.

    There are also other options like SQL*Loader where you need to write a "Control File" to tell the tool how to load the data from external file to the table. This approach would be best and faster than the INSERT..VALUES approach.