MySQL Forums
Forum List  »  Stored Procedures

Insert into dynamic tableName
Posted by: John Noble
Date: August 17, 2019 10:43AM

Hi folks,

I am struggling trying to insert into a table where the table name is sent to the sproc as a parameter...

DECLARE vLedgerYear varchar(20) default "";
DECLARE vInsert varchar(255) default "";

SET @vLedgerYear = "ledger" + substring(p_period, 1, 2);

SET @vInsert = CONCAT("INSERT INTO ledger19 (credit, reference1,vesselID) VALUES ('", p_credit, "','" , p_reference1, "','" , p_vesselID, "')");

The above works fine.

But I need to make like...

SET @vInsert = CONCAT("INSERT INTO ", @vLedgerYear, " (credit,reference1, vesselID) VALUES ('", p_credit, "','" , p_reference1, "','" , p_vesselID, "')");

Any ideas on how to do this ??


Options: ReplyQuote

Written By
Insert into dynamic tableName
August 17, 2019 10:43AM
August 17, 2019 11:33AM
August 17, 2019 02:28PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.