Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 使用带有out变量的sp时,会收到以下错误消息:错误代码:1241。操作数应包含1列_Mysql_Sql - Fatal编程技术网

Mysql 使用带有out变量的sp时,会收到以下错误消息:错误代码:1241。操作数应包含1列

Mysql 使用带有out变量的sp时,会收到以下错误消息:错误代码:1241。操作数应包含1列,mysql,sql,Mysql,Sql,我在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) ;

我在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选项卡
的结果分配给
NVARCHAR(40)

编辑:

如果我想返回整个select语句,该怎么办


谢谢。如果我想返回整个select语句,我该怎么办@卢卡斯·索兹达
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 ();