I have the following stored procedure which we use to insert data into a table:
CREATE OR REPLACE PROCEDURE mySproc
(
 invoiceId IN NUMBER
 customerId IN NUMBER
)
IS
BEGIN 
    INSERT INTO myTable (INVOICE_ID) 
    VALUES (invoiceId);
END mySproc;
/
What I am trying to do is to get the last inserted ID (this is the primary key field on myTable and auto incremented using a sequence) and insert it into another table, I have tried the following but could not get it working:
CREATE OR REPLACE PROCEDURE mySproc
(
 invoiceId IN NUMBER
 customerId IN NUMBER
)
IS
BEGIN 
    INSERT INTO myTable (INVOICE_ID) 
    VALUES (invoiceId)
    returning id into v_id;
    INSERT INTO anotherTable (ID, customerID) 
    VALUES (v_id, customerId);  
END mySproc;
/
I am getting this error: [Error] PLS-00049 (59: 26): PLS-00049: bad bind variable 'V_ID' I think I need to declare v_id somewhere but I tried before and after the BEGIN statement but that gave another error.
Any ideas as to how to do this?
Thanks