CREATE OR REPLACE PROCEDURE p_demo(
p_id varchar2,
p_demo_code varchar2,
clicked_on varchar2 default to_char(sysdate,'MM/DD/YYYY hh24:mi:ss')
) as
l_internal_id number;
l_user_demo_comment varchar2(100);
cursor cur_demo is
select 'x'
from user_demo
where internal_id = l_internal_id
and demo_code = demo_code;
r_demo cur_demo%rowtype;
e_user_already_demoed exception;
BEGIN
select internal_id
into l_internal_id
from users
where user_facing_id = p_id;
open cur_demo;
fetch cur_demo into r_demo;
if cur_demo%found then
close cur_demo;
raise e_user_already_demoed;
else
select demo_desc||' '||clicked_on
into l_user_demo_comment
from demos
where demo_code = p_demo_code;
insert into user_demo (
internal_id, demo_code, user_demo_comment, date_inserted
) values (
l_internal_id, p_demo_code, l_user_demo_comment, sysdate
);
commit;
end if;
close cur_demo;
EXCEPTION
when e_user_already_demoed then
/* insert into log table (not null in real life) */ null;
when no_data_found then
/* inserts into log table (not null in real life) */ null;
commit;
END p_demo;