免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2525 | 回复: 2
打印 上一主题 下一主题

DB2 Trigger问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-05-15 16:22 |只看该作者 |倒序浏览
有谁写过 trigger 插入的,我写了一个 怎么不能通过啊 。
着急
这是 从 center 拷贝出来的
- This script has been created using ^ as the termination character.
-- If you wish to execute this script through the CLP, you will need
-- to add the CLP option -td"^" to your command line,  for example:
-- db2 -td"^" -f filename.ddl

CONNECT TO SDDATA^
CREATE TRIGGER DB2ADMIN.TI_CARD_ACCT AFTER  INSERT  ON DB2ADMIN.CARD_ACCT  REFERENCING  NEW AS newamount  NEW_TABLE AS temp_card_acct  FOR EACH ROW  MODE DB2SQL
WHEN ( newamount = 0)
     
      insert  into temp_card_acct(no_card,amt,date_sys)
select no_card,sum(amount) as amt,max(date_sys) as date_sys
        from card_acct
        group by no_card;
   
END^
CONNECT RESET^

论坛徽章:
0
2 [报告]
发表于 2006-05-16 00:49 |只看该作者
what's the error msg?
if the error msg is:"SQL1024N  A database connection does not exist.  SQLSTATE=08003"
-- did you connect to your db first with the correct db name?
if the error msg is:"DB21007E  End of file reached while reading the command."
--did you execute the query using the command: db2 -td^ -f filename.ddl

论坛徽章:
0
3 [报告]
发表于 2006-05-16 08:24 |只看该作者
如何将以下语句更改成DB2 Trigger ?  有点难度,对于 trigger 声明的那个n 变量 ,如何使用,请教。 帮忙啊!

select no_card,sum(amount) as amt,max(date_sys) as date_sys
        into #temp_card_acct
        from inserted
        Group by no_card
        if @@error<>0
        begin
                raiserror 99999 'This is an error'
                return --rollback transaction
        end

        update card_info
        set balance=balance+amt
        from #temp_card_acct
        where card_info.no_card=#temp_card_acct.no_card
        if @@error<>0
        begin
                raiserror 99999 'This is an error'
                return --rollback transaction
        end

        update card_info
        set status=inserted.status
        from #temp_card_acct,inserted
        where         #temp_card_acct.no_card=card_info.no_card and
                #temp_card_acct.no_card=inserted.no_card  and
                    #temp_card_acct.date_sys=inserted.date_sys
        if @@error<>0
        begin
                raiserror 99999 'This is an error'
                return --rollback transaction
        end
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP