Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2004
    Posts
    13

    Unanswered: Inserting data to table

    Hello,

    I would like to know if there is any way I can condense these 5 separate queries (into 1 query) that I wrote that inserts 5 rows into a table called 'Dogs'.

    INSERT INTO Dogs
    VALUES (19, ‘Hasso’, ‘Boxer’, 30);
    INSERT INTO Dogs
    VALUES (9, ‘Lupo’, ‘Rottweiler’, 110);
    INSERT INTO Dogs
    VALUES (26, ‘Snoopy’, NULL, 2);
    INSERT INTO Dogs
    VALUES (2, ‘ShaPi’, ‘Chowchow’, 40);
    INSERT INTO Dogs
    VALUES (20, ‘Blacky’, ‘Mongrel’, 80);

    Thank you very much!

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    I think you can't do that ... at least, I don't know how.

  3. #3
    Join Date
    Sep 2003
    Posts
    156
    if you have created the table and are just inserting dummy rows, then you are going to have to insert each row at a time, remember to commit once all rows have been entered. you can also create and populate that table from another one.
    rgs,

    Ghostman

  4. #4
    Join Date
    Jun 2003
    Posts
    294
    There are other two posibilities to Insert into DOG

    The first one is using an insert of a select but It's toooooo boring

    Insert into Dog select 'CDSC','DCDSC,'SDAC' UNION SELECT 'DCSD','DSCDS','SDC'

    The other one is using SQL LOADER !!! This is the best one !

  5. #5
    Join Date
    Apr 2004
    Location
    USA
    Posts
    33
    INSERT INTO DOGS
    select 19, 'Hasso', 'Boxer', 30
    from dual
    union
    select 9, 'Lupo', 'Rottweiler', 110
    from dual
    union
    select 26, 'Snoopy', NULL, 2
    from dual
    union
    select 2, 'ShaPi', 'Chowchow', 40
    from dual
    union
    select 20, 'Blacky', 'Mongrel', 80
    from dual
    /

  6. #6
    Join Date
    May 2004
    Location
    Redwood Shores, CA
    Posts
    68
    Quote Originally Posted by Centro360
    Hello,

    I would like to know if there is any way I can condense these 5 separate queries (into 1 query) that I wrote that inserts 5 rows into a table called 'Dogs'.

    INSERT INTO Dogs
    VALUES (19, ‘Hasso’, ‘Boxer’, 30);
    INSERT INTO Dogs
    VALUES (9, ‘Lupo’, ‘Rottweiler’, 110);
    INSERT INTO Dogs
    VALUES (26, ‘Snoopy’, NULL, 2);
    INSERT INTO Dogs
    VALUES (2, ‘ShaPi’, ‘Chowchow’, 40);
    INSERT INTO Dogs
    VALUES (20, ‘Blacky’, ‘Mongrel’, 80);

    Thank you very much!
    Depending where you get the data from.
    If you query your data into arrays which you can do with cursor for loop or with bulk collect
    you can make one bulk insert with FORALL.

    Code:
    FORALL IN 1..DOGS_TAB.COUNT
      INSERT INTO Dogs VALUES (dogid_tab(i), dogname_tab(i), dogbreed_tab(i), ownerid_tab(i));
    END LOOP;
    My way or the highway. Yeah

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •