台灣最大程式設計社群網站
線上人數
801
 
會員總數:245475
討論主題:189234
歡迎您免費加入會員
討論區列表 >> Oracle >> SQL trigger To Oracle trigger
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
SQL trigger To Oracle trigger
價值 : 50 QP  點閱數:1198 回應數:1

樓主

阿凱
門外漢
0 3
76 1
發送站內信

請教各位原本有撰寫trigger是SQL如下:
Create TRIGGER [dbo].[WF_MailInfo_IRMSTRIG]
ON [dbo].[WF_MailInfo]
AFTER INSERT,UPDATE,DELETE
AS DECLARE @INSERTCOUNT INT, @DELETECOUNT INT, @T_INSERT_NUM INT, @T_DELETE_NUM INT, @NOWCOUNT INT

IF @@ROWCOUNT = 0 RETURN
SET @T_INSERT_NUM = (SELECT COUNT(*) FROM INSERTED)
SET @NOWCOUNT = (SELECT COUNT(*) FROM WF_MailInfo_BK)

/*當WF_MailInfo_BK大於5000筆時,刪除其中最舊一筆*/
IF (@NOWCOUNT >= 5000) DELETE FROM WF_MailInfo_BK WHERE CreateDTime IN (SELECT CreateDTime FROM (SELECT ROW_NUMBER() OVER (ORDER BY CreateDTime) AS RowNumber,* FROM WF_MailInfo_BK) AS TEMP WHERE TEMP.RowNumber='1')

/*將信件備份至WF_MailInfo_BK*/
IF (@T_INSERT_NUM <> 0) INSERT INTO WF_MailInfo_BK (RequestSource,CreateDTime,MailTo,MailCc,Subject,Content,BodyType,Priority,Retry,AddressType,MailFrom,MailReplyTo,SendingTime)(SELECT RequestSource,CreateDTime,MailTo,MailCc,Subject,Content,BodyType,Priority,Retry,AddressType,MailFrom,MailReplyTo,SendingTime FROM (SELECT ROW_NUMBER() OVER (ORDER BY CreateDTime DESC) AS RowNumber,* FROM WF_MailInfo) AS TEMP WHERE TEMP.RowNumber='1')

</pre>
但現在想轉成Oracle版本,如何修改???感謝幫忙

本篇文章發表於2014-12-08 12:20
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
1樓
作者回應

阿凱
檢舉此回應

請問我已改寫成這樣,但為何在DELETE FROM WF_MailInfo_BK和INSERT INTO WF_MailInfo_BK都發生錯誤,單獨執行就不會出錯,請指教???
本篇文章回覆於2014-12-08 16:27
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.