Can I use a variable as the column name or table name in a stored procedure. I want to use it for update and insert statements
Variable as column or table name
Collapse
X
-
Yes, it is possible to have table/column names as variables. In that case, you will have to use dynamic statements to execute the commands. For example:Originally posted by devikacsCan I use a variable as the column name or table name in a stored procedure. I want to use it for update and insert statements
RegardsCode:CREATE PROCEDURE test (IN tabname CHAR(6)) LANGUAGE SQL BEGIN DECLARE stmt VARCHAR(1000); SET stmt = 'INSERT INTO '|| tabname || 'values (1)'; PREPARE s1 FROM stmt; EXECUTE s1; END @
-- Sanjay -
Thanks a lot. ..........
Originally posted by sakumar9Yes, it is possible to have table/column names as variables. In that case, you will have to use dynamic statements to execute the commands. For example:
RegardsCode:CREATE PROCEDURE test (IN tabname CHAR(6)) LANGUAGE SQL BEGIN DECLARE stmt VARCHAR(1000); SET stmt = 'INSERT INTO '|| tabname || 'values (1)'; PREPARE s1 FROM stmt; EXECUTE s1; END @
-- SanjayComment
Comment