MySQL database (8.0.30) - Error Code: 1241. Operand should contain 1 column(s) - Error on stored procedure and cursor

62 Views Asked by At

I'm struggling with a MySQL 1241 "Operand should contain 1 column(s)" error.

This is a test stored procedure. I cannot figure out where's the problem. I'm learning MySQL, thanks!

DECLARE c_Property_URL varchar(250) DEFAULT ""; 
DECLARE finished int DEFAULT 0;

-- declare cursor for property URL
DECLARE curPropertyURL CURSOR FOR SELECT URL FROM `dbmaster`.`KIC_TB_Property`;
-- declare NOT FOUND handler
DECLARE CONTINUE HANDLER 
FOR NOT FOUND SET finished = 1;
OPEN curPropertyURL;
    getPropertyURL: LOOP
    FETCH curPropertyURL INTO c_Property_URL;
        SELECT ('property URL is: ',c_Property_URL);
        IF finished = 1 THEN 
            LEAVE getPropertyURL;
        END IF;
    END LOOP getPropertyURL;
CLOSE curPropertyURL;
1

There are 1 best solutions below

1
Bill Karwin On

You seem to be using tuple syntax in your select-list:

SELECT ('property URL is: ',c_Property_URL);

I assume you intended this to be string concatenation, but this is not MySQL's syntax for string concatenation. If you want that, use:

SELECT CONCAT('property URL is: ',c_Property_URL);

Tuple syntax is allowed in some SQL expressions, but not for scalar expressions in the select-list.