gpt4 book ai didi

MYSQL存储过程INSERT失败

转载 作者:行者123 更新时间:2023-11-29 22:22:45 25 4
gpt4 key购买 nike

我使用的是 MYSQL 5.5 版本我正在尝试插入以下过程:

CREATE PROCEDURE  `myTestProceed3ure` ( IN _id INT ) 
IF( SELECT COUNT( * ) FROM `tbl_search_counter` WHERE user_id = u_userid ) >0
THEN
(SELECT COUNT( * ) FROM `tbl_search_counter` WHERE user_id = u_userid);
ELSE
(INSERT INTO `tbl_search_counter` (`user_id` ,`time_searched`) VALUES ('165', '7'));
END IF

但无论出于何种原因,我收到以下错误消息

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 'INSERT INTO tbl_search_counter (user_id ,time_searched) VALUE' at line 6

我真的不明白,因为当我执行以下请求时,我没有遇到问题

CREATE PROCEDURE  `myTestProceed2ure` ( IN  `_id` INT ) 
INSERT INTO `tbl_search_counter` (`user_id`, `time_searched`) VALUES ('15', '7')

或以下内容

CREATE PROCEDURE  `myTestProceed3ure` ( IN _id INT ) 
IF( SELECT COUNT( * ) FROM `tbl_search_counter` WHERE user_id = u_userid ) >0
THEN
(SELECT COUNT( * ) FROM `tbl_search_counter` WHERE user_id = u_userid);
ELSE
(SELECT COUNT( * ) FROM `tbl_search_counter` WHERE user_id = u_userid);
END IF

如果有人知道我做错了什么,请告诉我......

谢谢

最佳答案

你的存储过程应该做什么?您没有引用存储过程的参数,并且 u_userid 似乎未定义。

如果您只想插入当前不存在的id,那么这是一种方法:

CREATE PROCEDURE  `myTestProceed3ure` (IN _id INT ) 
INSERT INTO tbl_search_counter(user_id, time_searched)
VALUES (_id, '7')
ON DUPLICATE KEY UPDATE user_id = values(user_id)
END IF;

关于MYSQL存储过程INSERT失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30558670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com