我继续使用以下查询获取SQL查询:
CREATE FUNCTION qualCand(salary int, gpa decimal(5,3), city varchar(255), state char(2)) returns VARCHAR(255)
DECLARE r VARCHAR(255)
SET r = (SELECT ca.firstname, ca.lastname, ca.phone, ca.email
FROM Candidates ca
JOIN education e
ON ca.candID = e.candID
JOIN desiredPos dPos
ON ca.candID = dPos.candID
JOIN desiredLocation dLoc
ON ca.candID = dloc.candID
WHERE dPos.desiredSalary >= salary AND
dLoc.sity = city AND
dLoc.state = state AND
e.GPA >= gpa);
MySQL说:
#1064 - 您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在'DECLARE r VARCHAR(255)附近使用正确的语法
SET r =(在第3行选择ca.firstname,ca.lastname,ca.phone,c'
答案 0 :(得分:1)
这个例子有几个问题。
首先,您宣布r
为VARCHAR
,但您正在尝试为其分配结果集。
其次,要从SELECT查询中将变量设置为列的值,语法将如下所示:
SELECT @r = firstname FROM Table ...
这是MySQL文档的链接,可帮助您更好地理解您尝试执行的操作的不同语法规则:http://dev.mysql.com/doc/refman/5.7/en/user-variables.html