表DESC:創建觸發器的查詢ORACLE SQL
Customer (Custid, Custname, Addr, phno,panno)
Loan (Loanid, Amount, Interest, Custid)
Account (Accd, Accbal, Custid)
查詢:
Create a Trigger which checks whether the Accbal is atleast 25% of amount to be inserted in Loan.
下了扳機代碼是:
create or replace trigger claim before
insert on loan for each row
declare
ex exception;
bal number;
begin
select accbal into bal from account where :new.custid=account.custid;
if(bal < 0.25*:new.amount)then
raise ex;
end if;
EXCEPTION
when ex then
raise_application_error(-20001,'Balance is not sufficient');
end;
/
我的觸發創建。但是,在貸款中插入值(意圖獲取錯誤)時,錯誤不會被提升。任何更正將在我的代碼中進行?
假設這些都是值:
LOANID AMOUNT INTEREST CUSTID
------- ---------- ---------- ------
1001 100000 2000 C01
1002 200000 4081.41 C02
1003 50000 1000 C03
ACCD ACCBAL CUSTID
---------- ------ ------
2001 5000 C01
2002 105000 C02
2003 24000 C03
如果我要插入此:
insert into loan values(1004,100000,2000,'C02');
它必須產生一個錯誤作爲新量的四分之一「100000」 = 25000 [ 0.25 *:new.amount]小於accbal,即對應的角點「C02」爲105000。
但是這個觸發代碼沒有發生。相反,它直接插入表中的值。
我想提出一個錯誤。當bal <0.25 *金額時,此金額爲新插入的值。 – Goks
您對此測試的數據是什麼 - 請在表格中添加一些示例數據以及您要發佈的確切聲明。而且「custid」只有一個「帳戶」記錄嗎?似乎觸發器正在假設。 –
對不起。我現在會改變。 – Goks