1

I have a mysql procedure that inserts a row to a table. Is it possible to pass the name of the table as a parameter?

I tried and got an unknown table exception.

EDIT:

my procedure is called from insaid a trriger:

CREATE  PROCEDURE `blabla`(tableName VARCHAR(255), var1 VARCHAR(255), var2 VARCHAR(255), var3 VARCHAR(255))
BEGIN
            INSERT INTO tableName 
            SET
                var1 = var1,
                var2= var2,
                var3= var3;

END

the error: ERROR 1146: 1146: Table 'xxx_xx_admin.tableName' doesn't exist

lior
  • 1,127
  • 3
  • 24
  • 43

1 Answers1

1

It is possible, but only if you use dynamic SQL to build your SQL. MySQL implements this using PREPARE and EXECUTE.

See How To have Dynamic SQL in MySQL Stored Procedure and http://rpbouman.blogspot.de/2005/11/mysql-5-prepared-statement-syntax-and.html

Community
  • 1
  • 1
davek
  • 22,499
  • 9
  • 75
  • 95