Having some problems with adding function calling exception in the procedure. I hope it's just some syntax misstake. The exception unauthorised is checking if the correct owner of the account deposits money in to the account. To handle that I call function get_authorisation. The code works itself without the exception. Could someone check it? Thank you!
create or replace procedure do_utt(
p_radnr in utt.radnr%type,
p_pnr in utt.pnr%type,
p_knr in utt.knr%type,
p_belopp in utt.belopp%type,
p_datum in utt.datum%type)
declare unauthorised exception;
as
begin
insert into utt(radnr, pnr, knr, belopp, datum)
values (radnr_seq.nextval, p_pnr, p_knr,
p_belopp, sysdate);
if get_authorisation(p_knr) = 0 then
raise unauthorised ;
end if;
commit;
dbms_output.put_line('Balance '|| p_knr || ' is:
'||get_saldo(p_knr));
exception
when unauthorised then
dbms_output.put_line('You are not the owner of the account!');
end;
/
Errors: PROCEDURE DO_UTT Line/Col: 8/2 PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following:
; is with default authid as cluster order using external deterministic parallel_enable pipelined result_cache accessible rewrite
The code for function:
create or replace function get_authorisation (
p_pnr in owner.pnr%type,
p_knr in owner.knr%type)
return number
as
v_authorised number;
v_no_authorised exception;
begin
select count(*)
into v_authorised
from owner
where pnr = p_pnr
and knr = p_knr;
return v_authorised;
exception
when v_no_authorised then
return 0;
end;