简体   繁体   English

MySQL错误1241操作数应在IF EXISTS上包含1列

[英]MySQL Error 1241 Operand should contain 1 column(s) on IF EXISTS

I have been getting this Error 1241 Operand should contain 1 column(s) in a Stored Procedure in MySQL. 我得到了这个错误1241操作数在MySQL的存储过程中应该包含1列。

This error has been highly cited in other posts, but none of these fitted my situation, and so I have created a question & answer to help others who may be struggling with the source of this error, and in which the other answers do not lead to the solution. 该错误在其他帖子中得到了很高的引用,但是这些都不适合我的情况,因此,我创建了一个问题与解答来帮助其他可能会为该错误的源头而苦苦挣扎的人,而其他答案却没有导致解决方案。

Here is a reduction of my code: 这是我的代码的简化:

DELIMITER //
DROP PROCEDURE IF EXISTS TEST
//
CREATE PROCEDURE TEST()
BEGIN
    IF NOT (SELECT * FROM categories) THEN
        SELECT 1;
    END IF;
END;
//

CALL TEST();

This compiles OK, but generates the runtime error 1241 error. 这将编译确定,但会生成运行时错误1241错误。

The error is caused by my failing to include the EXISTS keyword, and this statement should have read: 该错误是由于我未能包含EXISTS关键字引起的,该语句应为:

IF NOT EXISTS (SELECT * FROM categories) THEN

The challenge is that the original compiles without an error. 挑战在于原始文件的编译没有错误。

Whereas this clearly falls under the heading of "silly mistakes", it is often these types of mistakes which hold us up in our work, when we look in the wrong place for a solution, and it is my experience that these kinds of silly mistakes are made by both novice and experienced developers. 尽管这显然属于“愚蠢的错误”的标题,但是当我们在错误的位置寻找解决方案时,往往是这些类型的错误使我们无法开展工作,而根据我的经验,这些愚蠢的错误由新手和经验丰富的开发人员共同完成。

I hope that this may help to reduce your time wasted in searching for more complex solutions when this simple fix will suffice. 我希望这可以减少您在简单的解决方案就足够的情况下在寻找更复杂的解决方案上浪费的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM