我的存储过程中的插入查询未运行。 没有错误,但Query无法插入记录。 我可以知道这是什么问题吗?
CREATE DEFINER=`root`@`localhost` PROCEDURE `trip`(IN trip INT, IN rate INT, IN remark VARCHAR(1000))
BEGIN
UPDATE booking SET STATUS = "2" WHERE TRIP= trip;
SELECT rate AS RATE, remark AS REMARK, t.DRIVER_ID = @driver_id FROM trip_offer t WHERE t.TRIP = trip;
INSERT INTO rating(TRIP_ID, U_ID, RATE, REMARK, CRT_TMS) VALUES(trip, @driver_id, rate, remark, now());
END
答案 0 :(得分:1)
我怀疑你有几个问题。
一个明确的问题是MySQL无法区分变量(存储过程的参数)和列。您应始终使用变量前缀。其次,你要做的事情并不完全清楚。这是我最好的猜测:
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `trip`(
IN p_trip INT,
IN p_rate INT,
IN p_remark VARCHAR(1000))
BEGIN
UPDATE booking SET STATUS = "2" WHERE TRIP = v_trip;
INSERT INTO rating(TRIP_ID, U_ID, RATE, REMARK, CRT_TMS)
SELECT t.trip, t.driver_id, v_rate, v_remark, now()
FROM trip_offer t
WHERE t.TRIP = v_trip;
END;$$
DELIMITER $$
答案 1 :(得分:0)
问题:
t.DRIVER_ID = @driver_id
SELECT
中的错误。
@driver_id
似乎没有被定义。