Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个从某个表中选择的存储过程。该表作为参数传递给过程。SELECT * FROM ParamName 当我尝试运行它时它告诉我的只是'表参数名称不存在。任何建议都非常感谢?
ParamName在 MySQL 看来,它本身就是一个表/字段名,这是正确的抱怨。如果 Paramname 是存储过程的参数,则必须使用它@ParamName来告诉 MySQL 查找该名称的变量。
ParamName
@ParamName
但是,你不能简单地做
SELECT * FROM @ParamName
mysql 不允许通过变量指定表/字段名。您必须先准备一份声明:
SET @sql=CONCAT('SELECT * FROM ', @ParamName); PREPARE s1 FROM @sql; EXECUTE s1;