0
INSERT INTO billing
  (billing.emp_id, billing.billing_date, billing.billing_flag)
VALUES
  (1001, '2017-06-08', true),
  (1002, '2017-06-08', true) ON DUPLICATE KEY UPDATE billing_date =
VALUES
  (billing_date), billing_flag =
VALUES
  (billing_flag);

I use this query on MySQL for multiple inserts. Is this possible in Oracle?

2
  • Possible duplicate of Oracle: ON DUPLICATE KEY UPDATE Commented Jul 14, 2017 at 11:09
  • By 'update' I think you mean 'insert'. These are two different things in SQL. I have edited the question to reflect this. Please edit it if that is not what you are asking. Commented Jul 15, 2017 at 8:16

2 Answers 2

1

I assume you're using oracle. If you want to INSERT multiple rows in one go, you can do it like this:

INSERT ALL
  INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
  INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
  INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
SELECT * FROM dual;
Sign up to request clarification or add additional context in comments.

Comments

1

The example you posted will not work like that in PL/SQL.
If you would like to insert multiple columns in the same table you can do 2 things. You could use multiple insert into statements.

For example:

INSERT INTO Billing(Emp_Id, Biling_Date) VALUES ('1001', '2017-06-08');
INSERT INTO Billing(Emp_Id, Biling_Date) VALUES ('1002', '2017-06-08');

Or you could make a procedure where do the insert in the table, and then call that procedure. That way you don't have to constantly write out all column names.

For example:

CREATE OR REPLACE PROCEDURE InsertBilling (nEmp_Id IN NUMBER, vBiling_Date IN VARCHAR2)
AS 
BEGIN 
        INSERT INTO Billing(Emp_Id, Biling_Date)
        VALUES (nEmp_Id, vBiling_Date);

        COMMIT;
END; 
/

BEGIN
        InsertBilling('1001', '2017-06-08');
        InsertBilling('1002', '2017-06-08');
END;
/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.