I’m starting to work with PL/SQL and learning how to write procedures and exceptions but I cant seem to grasp how to show an error. The procedure is a simple one, its only supposed to do simple math as you can see below:
create or replace
procedure get_simple_math
(n_num1 in number,
n_num2 in number,
n_answer out number,
n_err_code out number,
n_err_msg out varchar2)
as
begin
n_answer := (n_num1 / n_num2);
dbms_output.put_line('Answer is '||n_answer);
n_err_code := 0;
exception
when others
then
n_err_code := SQLCODE;
n_err_msg := 'Error in get_simple_math '||SQLERRM;
raise_application_error (-20002,n_err_msg);
end get_simple_math;
As you can see its nothing fancy, but I cant for the life of me get the block to run:
set serveroutput on
declare
n_answer number := 0;
n_err_code number;
n_err_msg varchar2;
begin
get_simple_math(10,5,n_answer);
end;
I’m assuming I need to declare the variables that are set to out, which is why they are there. I also tried adding them to the procedure execute like:
get_simple_math(10,5,n_answer,n_err_code,n_err_msg);
But that didn’t seem to do the trick, so I am just looking for some help in solving this problem. Thanks in advance.
Run this and you’ll get your answer:
General suggestion for the procedure part: use substr – optional: