[英]How to fix “ERROR 1241 (21000): Operand should contain 1 column(s)” in mysql?
i want to display details of drivers working in morning shift.. 我想显示早上上班的司机的详细信息。
delimiter //
create function dShift(n int)
returns varchar(128)
deterministic
begin
return (select driver.driver_no,driver_name,licence_no,address,d_age,salary
from driver,bus_driver as bd where bd.shift=n and bd.driver_no =
driver.driver_no);
end //
In your function the return type is varchar returns varchar(128)
. 在您的函数中,返回类型为varchar
returns varchar(128)
。 So it expects a single string as output. 因此,它期望将单个字符串作为输出。 But you are returning 6 columns as output.
但是您将返回6列作为输出。
You can use the following way to get the list of columns as output: 您可以使用以下方法获取列列表作为输出:
delimiter //
CREATE FUNCTION dShift (n INT)
BEGIN
SELECT driver.driver_no
,driver_name
,licence_no
,address
,d_age
,salary
FROM driver
JOIN bus_driver AS bd ON bd.driver_no = driver.driver_no
WHERE bd.shift = n;
END //
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.