2017-07-04 109 views
-1
PL/SQL: SQL Statement ignored 
21/25 PL/SQL: ORA-00927: missing equal sign 
22/2  PL/SQL: SQL Statement ignored 
22/31 PL/SQL: ORA-00927: missing equal sign 
26/1  PL/SQL: SQL Statement ignored 
27/13 PL/SQL: ORA-00927: missing equal sign 
32/1  PL/SQL: SQL Statement ignored 
33/13 PL/SQL: ORA-00927: missing equal sign 
38/1  PL/SQL: SQL Statement ignored 
39/13 PL/SQL: ORA-00927: missing equal sign 
44/1  PL/SQL: SQL Statement ignored 

我想創建一個觸發器,當我插入表4主體的價值會自動計算比例,並設置獎學金的折扣一樣,如果學生有60%然後設置一些盧比折扣,如果80%比設置一些盧比折扣觸發更新值

+0

哪裏是你的代碼?將無法幫助只有錯誤。 – Nitish

+0

創建或更換觸發器vi_insert 更新前ON學生 FOR EACH ROW ENABLE 聲明 t student.total%type; p student.percentage%type; d student.discount%type; vs1 student.s1%類型; vs2 student.s2%類型; vs3 student.s3%type; vs4 student.s4%type; vrno student.rno%type;光標s​​tu是select * from學生; rw stu%rowtype; begin open stu; loop fetch stu into rw; t:= rw.vs1 + rw.vs2 + rw.vs3 + rw.vs4; p:= t * 0.25; 更新學生組總數:= t其中rno:= rw.rno; 更新學生設置百分比:= p其中rno:= rw.rno; –

+0

if(r.p> = 95) then 更新學生 設置折扣:= 25000其中rno:= rw.rno; ----- COND 2 ELSIF(r.p> = 90) 然後 更新學生 組折扣:= 20000,其中RNO:= rw.rno; --- cond 3 elsif(r.p> = 80) 然後 更新學生 設置折扣:= 15000其中rno:= rw.rno; --- cond 4 elsif(r.p> = 75) 然後 更新學生 設置折扣:= 10000其中rno:= rw.rno; ---- cond 5 else 更新學生 設置折扣:= 0其中rno:= rw.rno; end if; 退出 退出stu時未找到; end loop; close stu; vi_insert; 結束; –

回答

0

你需要寫簡單的BEFORE INSERT觸發器。你甚至不需要有遊標。嘗試觸發下方。以下語法

CREATE OR REPLACE TRIGGER stud_percent_disc 
BEFORE INSERT 
ON student 
FOR EACH ROW 
    DECLARE 
    v_total student.total%type; 
    v_percent student.percentage%type; 
    v_discount student.discount%type; 
    BEGIN 
    -- calculate total 
    v_total := (:new.s1 + :new.s2 + :new.s3 + :new.s4); 
    -- calculate percentage 
    v_percent := (v_total * 0.25); 
    -- calculate discount value 
    if (v_percent >= 95) then 
     v_discount := 25000; 
    elsif (v_percent >= 90) then 
     v_discount := 20000; 
    elsif (v_percent >= 80) then 
     v_discount := 15000; 
    elsif (v_percent >= 75) then 
     v_discount := 10000; 
    else 
     v_discount := 0; 
    end if; 
    :new.total := v_total; 
    :new.percentage := v_percent; 
    :new.discount := v_discount; 
    END; 
/

用戶插入:

insert into student(s1,s2,s3,s4,total,percentage,discount) values(88,88,88,88,0,0,0); 
+0

但運行此觸發器時,我插入表中的值的學生像s1 s2 s3 s4中的值然後沒有更新執行總計,百分比和折扣 –

+0

觸發器創建成功嗎?或者有一些錯誤? –

+0

YES SUCCESFULLY CREATED –