mysql 触发器中参数传递

legend_jhz 2008-12-16 05:05:46
在触发器中需要传递多个参数,我开始这样写:

DECLARE total int;
DECLARE tp int;
DECLARE nian int;
DECLARE i int;
DECLARE ff int;
DECLARE seasion int;
DECLARE half int;
DECLARE sfc timestamp;
DECLARE efc timestamp;
DECLARE dend timestamp;
SELECT period_diff(DATE_FORMAT(contectend,'%Y%m'),DATE_FORMAT(jfstdate,'%Y%m')) into total ,pricetype into tp ,fftype into ff,jfstdate into sfcfrom jz_contect where ctid = new.ctid;

不行,说不认识pricetype,后来又改为这样:

DECLARE efc timestamp;
DECLARE dend timestamp;
SELECT period_diff(DATE_FORMAT(contectend,'%Y%m'),DATE_FORMAT(jfstdate,'%Y%m')) into total from jz_contect where ctid = new.ctid;
SELECT pricetype into tp from jz_contect where ctid = new.ctid;
SELECT fftype into ff from jz_contect where ctid = new.ctid;
SELECT jfstdate into sfc from jz_contect where ctid = new.ctid;

结果在调用的时候出现了锁定现象,说是用的innodb型,造成链接超时,我怎样把查询出的多个数据赋值给变量呢?
...全文
757 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
WWWWA 2008-12-16
  • 打赏
  • 举报
回复
如果只是
SELECT period_diff(DATE_FORMAT(contectend,'%Y%m'),DATE_FORMAT(jfstdate,'%Y%m')) into total ,pricetype into tp ,fftype into ff,jfstdate into sfcfrom jz_contect where ctid = new.ctid;

这个问题,上述代码应该可以了,其它的明日我看看,现在有事
WWWWA 2008-12-16
  • 打赏
  • 举报
回复
SELECT period_diff(DATE_FORMAT(contectend,'%Y%m'),DATE_FORMAT(jfstdate,'%Y%m'))
,pricetype,fftype,jfstdate
into total , tp , ff, `sfcfrom jz_contect` where ctid = new.ctid;
legend_jhz 2008-12-16
  • 打赏
  • 举报
回复
这个触发器是每次当向一个表中插入数据的时候,就调用他:
CREATE
/*!50017 DEFINER = 'root'@'localhost' */
TRIGGER `trigger_jz_guestcard` AFTER INSERT ON `jz_contect`

每次新生成了数据:

SELECT period_diff(DATE_FORMAT(contectend,'%Y%m'),DATE_FORMAT(jfstdate,'%Y%m')) into total from jz_contect where ctid = new.ctid;

然后插入另一个表中,当然需要根据取出来的内容判断一下才插入。
WWWWA 2008-12-16
  • 打赏
  • 举报
回复
如只有一条记录
select ff,gg into @dd,@dd1 from aa where ff=1;
有多条,用游标
WWWWA 2008-12-16
  • 打赏
  • 举报
回复
只生成一条记录?

57,062

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧