这个mysql 存储过程 哪里有问题 如果存在记录就 更新 count + 1,不存在就插入

2025-02-27 03:11:48
推荐回答(1个)
回答1:

searchrecord 表里面的 username 的数据类型, 是 char(32) ?

searchrecord 表里面的 type 的数据类型, 是 char(16) ?

还有就是你调用存储过程的时候, 是怎么调用的?

还有就是

select count(*),id,count INTO p_isexist,p_id,p_count from searchrecord Where username = usernamep And type = typep;

这个 sql 语句上面, 有点问题。

可以修改为
select count(*) INTO p_isexist from searchrecord Where username = usernamep And type = typep;

然后后面的
update searchrecord set opdate=NOW(),count = p_count +1 where id = p_id

修改为

update searchrecord set opdate=NOW(),count = count + 1 where username = usernamep And type = typep;