作者 主題: oracle trigger問題一問  (閱讀 5329 次)

0 會員 與 1 訪客 正在閱讀本文。

noki

  • 活潑的大學生
  • ***
  • 文章數: 207
    • 檢視個人資料
oracle trigger問題一問
« 於: 2011-07-21 17:58 »
各位大大好
小弟在寫SQL的trigger一直不順,
想請教有經驗的大大應該如何解,萬分感激。

create or replace trigger GETRES_ID
BEFORE insert or update of RES_ID on AS_RES_SAVE
DECLARE
SERVICEID := 10439;
v_a RES_ID%type;
BEGIN
IF (RES_ID is null) THEN
SERVICEID := SERVICEID+1;
select seq_as_res.nextval into v_b from dual;
END IF;
END;
/

小弟想要當RES_ID為null時觸發,每筆資料中的RES_ID以seq_as_res.nextval代替,
並將SERVICEID加1
上面這段code在oracle執行時都會有Warning: Trigger created with compilation errors.訊息。
且在error中的訊息是
2/14     PLS-00103: Encountered the symbol "=" when expecting one of the
         following:
         constant exception <an identifier>
         <a double-quoted delimited-identifier> table LONG_ double ref
         char time timestamp interval date binary national character
         nchar
         The symbol "<an identifier>" was substituted for "=" to continue.

bunko

  • 懷疑的國中生
  • **
  • 文章數: 67
    • 檢視個人資料
Re: oracle trigger問題一問
« 回覆 #1 於: 2011-07-21 18:07 »
before trigger 拿要插入的值來判斷,要用  :New.var 來修飾,這樣才抓的到.

noki

  • 活潑的大學生
  • ***
  • 文章數: 207
    • 檢視個人資料
Re: oracle trigger問題一問
« 回覆 #2 於: 2011-07-21 21:35 »
before trigger 拿要插入的值來判斷,要用  :New.var 來修飾,這樣才抓的到.
但是要用:new就必須要使用for each row
小弟只要加入for each row就會有PLS-00103: Encountered the symbol "FOR" when expecting one of the
         following:這錯誤訊息
實在是看不懂到底哪裡出問題了.... ???