SQL> Rem 1. For the given customer number, display as "No Account
for the given customer <number>" if the customer doesn't have any
account. If the customer has more than
SQL> Rem one account, display as "The given customer <number> have
more than one Account". If the customer has only one account, then
display as "The given customer
SQL> Rem <number> holds exactly one Account". Use predefined
exception handling.
SQL>
SQL> SET SERVEROUTPUT ON;
SQL> DECLARE
2 customer_id varchar2(5) := '&customer_id';
3 cnt number;
4 ex1 exception;
5 ex2 exception;
6 ex3 exception;
7 BEGIN
8 select count(*) into cnt from ACCOUNT where
ACCOUNT.CID=customer_id;
9 IF cnt=0 THEN
10 RAISE ex1;
11 ELSIF cnt>1 THEN
12 RAISE ex2;
13 ELSIF cnt=1 THEN
14 RAISE ex3;
15 END IF;
16 EXCEPTION
17 WHEN ex1 THEN
18 dbms_output.put_line('No account for the given customer
!');
19 WHEN ex2 THEN
20 dbms_output.put_line('The given customer has more than
one Account');
21 WHEN ex3 THEN
22 dbms_output.put_line('The given customer holds exactly
one Account');
23 END;
24 /
Procedure created.
SQL>
SQL> DECLARE
2 Tid varchar2(5):='&TransactionId';
3 Ano varchar2(5):='&Ano';
4 Ttype varchar2(40):='&Ttype';
5 Tdate date:='&Tdate';
6 Tamount number:=&Tamount;
7 ex exception;
8 temp number;
9 BEGIN
10 temp:=0;
11 Trans(Tid,Ano,Ttype,Tdate,Tamount,temp);
12 IF temp=0 THEN
13 RAISE ex;
14 END IF;
15 EXCEPTION
16 WHEN ex THEN
17 dbms_output.put_line('Transaction date is more than
todays date !');
18 END;
19 /
SQL>
Viel mehr als nur Dokumente.
Entdecken, was Scribd alles zu bieten hat, inklusive Bücher und Hörbücher von großen Verlagen.
Jederzeit kündbar.