Dynamic SQL: Add column from variable.
Here is what I'm trying to do from within a stored procedure:
SET @c = code_val;
SET @s = CONCAT('ALTER TABLE MyDB.tmp_Totals ADD COLUMN ',@c,' varchar(4)');
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
Executing the statements one at at time from the interactive mysql prompt works. However, when running the stored proc:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CALL varchar(4)' at line 1
Any ideas why this is failing?
Subject
Views
Written By
Posted
Dynamic SQL: Add column from variable.
2528
January 07, 2012 01:15PM
883
January 08, 2012 01:57AM
912
January 08, 2012 11:28AM
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.