我必须在mysql中创建一个返回整数的函数。 sql解释器一直告诉我,我的语法有问题。我尽我最大的努力看了一遍,尝试了很多东西,但我无法理解。
var arr = [ { id: 1, name: "Hello" }, { id: 2, name: "World" } ];
var data = _.find(arr, { id: 1 }); // => Object {id: 1, name: "Hello"}
var data = _.find(arr, { id: 3 }); // => undefined
错误输出:
CREATE FUNCTION no_of_paintings_exhibited (exhibition_name VARCHAR(45))
RETURNS INT
BEGIN
DECLARE number_of_paintings INT;
SELECT
COUNT(*)
INTO number_of_paintings
FROM Exhibition, Shown_at, Painting
WHERE name = exhibition_name AND Painting.id_no = Shown_at.art;
RETURN number_of_paintings;
END; //
答案 0 :(得分:0)
CREATE FUNCTION no_of_paintings_exhibited (exhibition_name VARCHAR(45))
RETURNS INT
BEGIN
DECLARE number_of_paintings INT;
set number_of_paintings=0;
SELECT
COUNT(*)
as number_of_paintings
FROM Exhibition ex, Shown_at shat, Painting ptng
WHERE ex.name = exhibition_name AND ptng.id_no = shat.art;
RETURN number_of_paintings;
END;
答案 1 :(得分:0)
您收到此错误是因为您没有设置DELIMITER,默认情况下,分号(;)是分隔符,一旦找到它尝试执行的第一个分号并抛出此错误
执行以下操作(在创建函数之前将分隔符设置为$$或//,下面我使用$$)然后再次创建函数后再次将DELIMITER设置为分号。
DELIMITER $$
CREATE FUNCTION ...
..
END;
$$
DELIMITER ;