MySQL Forums
Forum List  »  Stored Procedures

Create TEMPORARY Table using dynamic SQL
Posted by: John Noble
Date: October 28, 2022 03:44PM

Hi folks,

I am trying to create a Temporary table using variables

If I use:
CREATE TEMPORARY TABLE tempTable SELECT * FROM myTable;
it will work fine,

Except, I don't know the name of the table in advance. That is passed into the sproc.

So I need to use something more dynamic like

SET @vTableName= CONCAT("tableName", variableName);
SET @vSQL = CONCAT("SELECT * FROM ", @vTableName);
CREATE TEMPORARY TABLE tempTable @vSQL;

Except this wont compile.

Is there a way around this?

Thanks,

JOhn

Options: ReplyQuote


Subject
Views
Written By
Posted
Create TEMPORARY Table using dynamic SQL
440
October 28, 2022 03:44PM


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.