存储过程中“字段列表”中的未知列

时间:2013-11-27 11:55:49

标签: mysql sql stored-procedures prepared-statement

我正在创建一个存储过程但面临字段名称的问题...当我运行该过程时我有错误'字段列表中的未知列'pa'但我不明白为什么...... < / p>

CREATE PROCEDURE `deletePost`(IN p_id_post INT, IN p_Tbl_ref CHAR(2))
BEGIN

SET @id_post = p_id_post; 
SET @Tbl_ref = p_Tbl_ref;

DELETE FROM `tbl` WHERE tbl_ref_product = @Tbl_ref AND id_table = @id_post;

END

我也尝试过准备好的陈述......

CREATE PROCEDURE `deletePost`(IN p_id_post INT, IN p_Tbl_ref CHAR(2))
BEGIN

PREPARE STMT FROM 
"DELETE FROM `tbl` WHERE tbl_ref_product = ? AND id_table = @id_post";

SET @id_post = p_id_post; 
SET @Tbl_ref = p_Tbl_ref;

EXECUTE STMT USING @Tbl_ref;
DEALLOCATE PREPARE STMT;

END

......但同样的结果......任何想法?非常感谢!

2 个答案:

答案 0 :(得分:1)

你描述的问题根据程序定义完全没有意义,所以,如果你听到蹄声,并且你确定它不是马,你可能想要检查斑马:

尝试show triggers;

下一个可能的原因是该过程实际上工作正常,但表tbl定义了BEFORE DELETEAFTER DELETE触发器,并且该触发器有一个设计错误,引用了不存在的列称为“pa`。

答案 1 :(得分:0)

您在delete语句中使用列名作为表。因为表是在sql中预定义的,所以它会给你错误。 请尝试以下代码

`CREATE PROCEDURE deletePost(IN p_id_post INT, IN p_Tbl_ref CHAR(2))
BEGIN

SET @id_post = p_id_post; 
SET @Tbl_ref = p_Tbl_ref;

DELETE FROM `tbl` WHERE [table] = @Tbl_ref AND id_table = @id_post;

END`