猿问

想要定义一个oracle自定义函数function,如下内容是错在哪里?

用oracle 自定义函数 function定义一个能对交易记录表tbl_business(business_id,user_id,business_date,business_amt,content)
如(1 ,1 ,2011/4/19 ,23012 00,‘七匹狼鞋子’)
的交易额business_amt进行判断,当交易额大于200万时将该交易记录添加到风险交易表tbl_Rbusiness(business_id,user_id,business_date,business_amt)中的函数

慕哥9229398
浏览 150回答 2
2回答

MM们

两种方法,建议你用触发器:create or replace trigger businessafter insert on tbl_businessfor each rowbeginif :new.business_amt =2000000 theninsert into tbl_Rbusiness(business_id,user_id,business_date,business_amt) values (:new.business_id,:new.user_id,:new.business_date,:new.business_amt);end if;end;函数:create or replace function amount return number asv_exists number;beginfor v in (select * from tbl_business) loopif (v.business_amt = 2000000) thenselect count(*) into v_exists from ipwhere business_id = v.business_idand user_id = v.user_idand business_date = v.business_dateand business_amt = v.business_amt;if v_exists = 0 theninsert into ip (business_id,user_id,business_date,business_amt)values (v.business_id,v.user_id,v.business_date,v.business_amt);commit;end if;end if;end loop;end;

慕虎7371278

这不是应该写一个触发器吗?
随时随地看视频慕课网APP

相关分类

Oracle
我要回答