Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql准备状态给定错误_Mysql - Fatal编程技术网

mysql准备状态给定错误

mysql准备状态给定错误,mysql,Mysql,我正在尝试编写一个存储过程来更新参数中指定的表字段。我在@sql station中遇到语法错误。请帮助 create procedure new_upd1(ind int(3),attribute varchar(30),pk int(11),new_value varchar(30)) begin set @att=attribute; set @primk=pk; set @updated=new_value; if ind=1 then

我正在尝试编写一个存储过程来更新参数中指定的表字段。我在@sql station中遇到语法错误。请帮助

 create procedure new_upd1(ind int(3),attribute varchar(30),pk int(11),new_value varchar(30))
begin
    set @att=attribute;
    set @primk=pk;
    set @updated=new_value;

    if ind=1 then
        set @sql='update department set ?=? where departmentid=?';
        prepare stmt from @sql;
        execute stmt using @att,@updated,@primk;
        deallocate prepare stmt;
    end if;
end

参数不适用于列或表名,仅适用于值。这样做:

create procedure new_upd1(ind int(3),attribute varchar(30),pk int(11),new_value varchar(30))
begin
    set @att=attribute;
    set @primk=pk;
    set @updated=new_value;

    if ind=1 then
        set @sql=CONCAT('update department set ', @att, '=? where departmentid=?;');
        prepare stmt from @sql;
        execute stmt using @updated,@primk;
        deallocate prepare stmt;
    end if;
end

如果不显示错误消息,我们怎么知道会出现什么语法错误呢?很抱歉,cmd只是说语法错误:(它通常说在哪一行。@fancyPants.非常感谢,我的问题解决了:)