[英]Problem when using CASE function in mysql but getting Error Code: 1241. Operand should contain 1 column(s)
[英]Using a sp with an out variable get the following error message: Error Code: 1241. Operand should contain 1 column(s)
我在MySql中编写了一个存储过程,其中包含一个out变量,但是当我要调用它时,出现以下错误。 有人可以帮我了解我在做什么错吗? 这是sp:
CREATE DEFINER=`root`@`localhost` PROCEDURE `storedp2`(out shift nvarchar(40))
begin
set shift= (SELECT * FROM myblog.computed);
end
这就是我所说的:
set @test='';
call storedp2 (@test) ;
select @test as t;
这是错误:
错误代码:1241。操作数应包含1列
您需要返回单个值:
CREATE DEFINER=`root`@`localhost` PROCEDURE `storedp2`(out shift nvarchar(40))
begin
set shift= (SELECT col_name FROM myblog.computed WHERE id = ?);
-- (single column/single row)
-- set shift = (SELECT col_name FROM myblog.computed WHERE ... LIMIT 1);
end;
您不能将SELECT * FROM tab
结果分配给NVARCHAR(40)
:
scalar := (col1, col2, col3) -- won't work (multiple cols, single row)
scalar := (col1, col2), (col1, col2) -- won't work (multiple cols, multiple rows)
sclara := (col1), (col1) -- won't work (single col, multiple rows)
编辑:
如果我想返回整个选择的情感该怎么办
CREATE DEFINER=`root`@`localhost` PROCEDURE `storedp2`()
begin
-- some logic
SELECT * FROM myblog.computed;
end
call storedp2 ();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.