Multiple rows insertion in single insert query.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sumittyagi
    Recognized Expert New Member
    • Mar 2007
    • 202

    #1

    Multiple rows insertion in single insert query.

    Hi All,
    Is it possible in oracle to insert multiple rows in a single insert query, as is possible in sql server:
    insert into test_table values ('abc', 'xyz'), ('mno', 'pqr');

    This syntax is not supported in oracle. Is oracle having any alternative for this one.

    Thanks & happy new year in advance.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    try to use bulk insert using PL / SQL

    Comment

    • sumittyagi
      Recognized Expert New Member
      • Mar 2007
      • 202

      #3
      Originally posted by debasisdas
      try to use bulk insert using PL / SQL
      Hi debashisdas,
      Thanks for your reply. I know that can be done by PL/SQL, but in that case there will be multiple insert queries. I was wondering if there is any alternative in oracle for Multiple rows insertion specifically with single insert query.

      Thanks.

      Comment

      • chritzuk
        New Member
        • Dec 2007
        • 10

        #4
        The syntax you are asking about is not supported in Oracle.

        Comment

        • sumittyagi
          Recognized Expert New Member
          • Mar 2007
          • 202

          #5
          Originally posted by debasisdas
          The kind of syntax you are asking in SQL Server is not suppoerted in Oracle.
          Thanks for your replies.

          Comment

          • vikas000000a
            New Member
            • Jan 2008
            • 46

            #6
            Originally posted by sumittyagi
            Hi All,
            Is it possible in oracle to insert multiple rows in a single insert query, as is possible in sql server:
            insert into test_table values ('abc', 'xyz'), ('mno', 'pqr');

            This syntax is not supported in oracle. Is oracle having any alternative for this one.

            Thanks & happy new year in advance.
            Multiple rows can be inserted using only one insert statement only when you have got the data available in some other table in the database. In that case you can use following query:

            Code:
            insert into table1
            select * from table2
            assuming that the structures of table1 and table2 are the same.

            Comment

            • debasisdas
              Recognized Expert Expert
              • Dec 2006
              • 8119

              #7
              Originally posted by vikas000000a
              Multiple rows can be inserted using only one insert statement only when you have got the data available in some other table in the database. In that case you can use following query:

              Code:
              insert into table1
              select * from table2
              assuming that the structures of table1 and table2 are the same.
              yes that is one option ,but the user was not certainly asking about that.

              Comment

              • vijay dev
                New Member
                • Jan 2008
                • 1

                #8
                Use triggers for insert or write PL/SQL for multiple insertition.

                Comment

                • bondwiththebest
                  New Member
                  • Jul 2008
                  • 1

                  #9
                  hi dear
                  if u want to insert the multiple values with single insert statement
                  then try this
                  insert into tablename values('&column 1',&column2,... ....);

                  actually column1 is in quotes because it is varchar or char
                  for number use the simple like column2
                  for date field u have to use like column1

                  on execution of statement it will ask to enter the values untill u will enter.

                  i hope it will help u.

                  Comment

                  • Pramma
                    New Member
                    • Jul 2008
                    • 2

                    #10
                    Yes. It is possible in Oracle.
                    Follow the query like

                    insert all
                    into table1 values(.,.,),
                    into table2 values(.,.,),
                    into table3 values(.,.,),
                    ...
                    ..
                    select * from dual;

                    Comment

                    • Pramma
                      New Member
                      • Jul 2008
                      • 2

                      #11
                      If u want to insert into same table multiple row, keep the tablename same in the above query. thats it.

                      Comment

                      Working...