MySQL在表中插入行的功能。
CREATE FUNCTION create_business(
phone_number TEXT,
open_time TIME,
close_time TIME,
est_date DATE,
bus_desc VARCHAR(500),
bus_name VARCHAR(30),
off_phones VARCHAR(100),
off_email VARCHAR(100)
) RETURNS INT(6)
BEGIN
declare bus_id INT; <===
INSERT INTO business
(
Name,OpenTime,CloseTime,EstDate,Description,OfficialPhone,OfficialEmail
)
VALUES
(
bus_name,open_time,close_time,est_date,bus_desc,off_phones,off_email
); <===
SET bus_id = SELECT LAST_INSERT_ID();
RETURN bus_id;
END $$
DELIMITER ;
我找不到任何错误,并且日志也没有提供太多有关上述内容的信息。
09:58:16 CREATE FUNCTION create_business( phone_number TEXT, open_time TIME, close_time TIME, est_date DATE, bus_desc VARCHAR(500), bus_name VARCHAR(30), off_phones VARCHAR(100), off_email VARCHAR(100) ) RETURNS INT(6) BEGIN declare bus_id INT Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 12 0.033 sec
答案 0 :(得分:1)
您的功能似乎有几个问题,
SET bus_id = SELECT LAST_INSERT_ID()
应该更改为`SET bus_id = LAST_INSERT_ID(); 应该是下面的样子,
DELIMITER $$
CREATE FUNCTION create_business(
phone_number TEXT,
open_time TIME,
close_time TIME,
est_date DATE,
bus_desc VARCHAR(500),
bus_name VARCHAR(30),
off_phones VARCHAR(100),
off_email VARCHAR(100)
) RETURNS INT(6)
BEGIN
declare bus_id varchar(2);
INSERT INTO business
(
Name,OpenTime,CloseTime,EstDate,Description,OfficialPhone,OfficialEmail
)
VALUES
(
bus_name,open_time,close_time,est_date,bus_desc,off_phones,off_email
);
SET bus_id = LAST_INSERT_ID() ;
RETURN bus_id;
END $$
DELIMITER ;