有没有任何方法可以使MySQL函数接收表名或字段名?
类似的东西:
CREATE PROCEDURE delete_row(the_id INT UNSIGNED , @table_name )
BEGIN
IF ....... THEN
BEGIN
DELETE FROM @table_name WHERE id = the_id ;
.............
END
END
我用字符串(SET @ table_name =“table_name”)测试了它,但它不起作用。
答案 0 :(得分:-1)
declare varchar(max) @mySQL
set @mySQL = 'DELETE FROM ' + @tablename + 'WHERE id = ' + Convert(varchar, @the_id)
sp_executeSQL @mySQL
并且使这项工作在MySQL上(正如评论者指出的那样)它应该如下所示:
mysql> prepare stmt from -> 'DELETE FROM ' + @tablename + 'WHERE id = ' + Convert(varchar, @the_id)
mysql> execute stmt;