[英]Using a sp with an out variable get the following error message: Error Code: 1241. Operand should contain 1 column(s)
I wrote a stored procedure in MySql that contains an out variable but when I want to call it, I get the below error. 我在MySql中编写了一个存储过程,其中包含一个out变量,但是当我要调用它时,出现以下错误。 Can someone please help me understand what am I doing wrong?
有人可以帮我了解我在做什么错吗? Here is the sp:
这是sp:
CREATE DEFINER=`root`@`localhost` PROCEDURE `storedp2`(out shift nvarchar(40))
begin
set shift= (SELECT * FROM myblog.computed);
end
and here is how I call it: 这就是我所说的:
set @test='';
call storedp2 (@test) ;
select @test as t;
and here is error: 这是错误:
Error Code: 1241. Operand should contain 1 column(s)
错误代码:1241。操作数应包含1列
You need to return single value: 您需要返回单个值:
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;
You cannot assign result of SELECT * FROM tab
to NVARCHAR(40)
: 您不能将
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)
EDIT: 编辑:
what should I do if I want to return the whole select sentance
如果我想返回整个选择的情感该怎么办
CREATE DEFINER=`root`@`localhost` PROCEDURE `storedp2`()
begin
-- some logic
SELECT * FROM myblog.computed;
end
call storedp2 ();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.