I am trying to insert below details in two table. but it shows error. where i am wrong?
create or replace PROCEDURE ADD_customer_order(
customer_id in varchar, Shipping_id_arg in number,
order_date_arg in date, Total_price_arg in decimal,
inventory_id_arg in number, order_quantity_arg in number)
AS
BEGIN
INSERT INTO customer_order (customer_id,Shipping_id,Order_date,total_price) VALUES(customer_id_arg,Shipping_id_arg,order_date_arg, total_price_arg);
insert into order_details (inventory_id,order_quantity) values(scope_identity(),inventory_id_arg,order_quantity_arg);
END;
It helps if you format it nicely.
Doing so, you easily note that the second
INSERTis invalid, as you're inserting 3 values into 2 columns:Either remove
scope_identity()(what is it?), or include additional column into the column list you're inserting into.After reading your comment, it seems that
returningclause might help. See the following example (somewhat simpler than yours; didn't feel like typing that much). Trigger is used to auto-incrementORDER_IDcolumn. inCUSTOMER_ORDERtable (I'm on 11g XE; don't have identity columns here).Procedure: note local variable declared in line #4 and
returningclause in line #7:Testing:
The same
ORDER_IDvalue is used in both tables.