Create table Bank_Mas(Accno Varchar2(10),
Cname Varchar2(10),
Odate Date,
Acc_type Varchar2(1),
Balance Number(8,2));
Trigger Name: Bank_Mas_Trig
Table Name: Bank_Mas
Trigger Event: Before Insert
Create or Replace Trigger Bank_Mas_Trig
Before Insert on Bank_Mas
for each row
Begin
SELECT 'SBI'|| (NVL(MAX(TO_NUMBER(SUBSTR(ACCNO,4) )),0)+1)
into :[Link] from Bank_Mas;
:[Link]:=upper(:[Link]);
:[Link]:=Sysdate;
if Upper(:new.acc_type)='S' Then
if :[Link]<500 then
Raise_Application_error(-20001,'Min. Savings A/c. Bal. Rs.500/-.');
end if;
elsif Upper(:new.acc_type)='C' then
if :[Link]<1000 then
Raise_Application_error(-20002,'Min. Current A/c. Bal. Rs.1000/-.');
end if;
else
Raise_Application_error(-20003,'Invalid Account Type!!!!!');
End if;
End;
Package Specification:
-----------------------------
Create or replace package Bank_Pack
is
Function Chk_Bal(Taccno [Link]%type,
Tamount [Link]%type) Return Boolean;
Procedure Upd_Bal(Taccno [Link]%type,
Ttype [Link]%type,
Tamount [Link]%type);
End Bank_Pack;
Package Body:
-------------------
Create or replace Package Body Bank_pack
is
Function Chk_Bal(Taccno [Link]%type,
Tamount [Link]%type) Return Boolean
is
tacc_type bank_mas.acc_type%type;
tbal bank_mas.Balance%type;
Begin
Select acc_type, Balance into Tacc_type, Tbal from bank_mas
where Accno=Taccno;
if Upper(Tacc_type)='S' then
if (Tbal-Tamount)>=500 then
Return(True);
else
Return(False);
end if;
elsif Upper(Tacc_type)='C' then
if (tbal-Tamount)>=1000 then
Return(True);
else
Return(False);
end if;
End if;
End Chk_bal;
Procedure Upd_Bal(Taccno [Link]%type,
Ttype [Link]%type,
Tamount [Link]%type)
is
Begin
if upper(Ttype)='W' then
Update Bank_Mas Set Balance=Balance-Tamount where
Accno=Taccno;
elsif upper(Ttype)='D' then
Update Bank_mas Set Balance=Balance+Tamount where
Accno=Taccno;
end if;
End Upd_Bal;
End Bank_Pack;
/
Trigger Name: Trans_Trig
Table Name: Trans
Trigger Event: Before Insert
Create or Replace Trigger Trans_Trig
Before Insert on Trans
for each row
declare
Cnt Number(2);
Tamt_Limit Number;
Begin
Select Count(*) into cnt from bank_mas
where accno=:[Link];
if cnt=0 then
Raise_Application_error(-20001,'Invalid Account Number.');
end if;
:[Link]:=Sysdate;
if :[Link]<100 then
Raise_Application_error(-20002,'Min. Trans. Amount Rs.100/-.');
end if;
if upper(:[Link])='W' then
if Bank_Pack.Chk_Bal(:[Link], :[Link])=True then
Bank_Pack.Upd_Bal(:[Link], :[Link], :[Link]);
else
Select Balance - :[Link] into Tamt_Limit from Bank_mas
where Accno=:[Link];
Raise_Application_error(-20003,'In-Sufficient Balance. and Ur With Drawing
Power Rs.'||Tamt_Limit);
end if;
elsif upper(:[Link])='D' then
Bank_Pack.Upd_Bal(:[Link], :[Link], :[Link]);
else
Raise_Application_error(-20004,'Invalid Trans. Type!!!!!');
end if;
End;