Question: (By David Gray) I'm trying to
catch an ORA-01284 error in a stored procedure. Looking around it
seems as if I have to define my own exception using the PRAGMA
EXCEPTION_INIT key words and then tray the error in a when block.
The problem is I'm getting the following error when compiling:
Error(24,31): PLS-00109: unknown
exception name 'FILE_NOT_AVAILABLE' in PRAGMA EXCEPTION_INIT
The procedure is show below with the new code show in bold.
create or replace
PROCEDURE "MATERIALISE_DATA" (
p_filename varchar2,
p_recordcount OUT number,
p_errorcode OUT number
)
as
begin
declare
cursor c_v_logmnr_contents is
select
logmnr.logmnr_sequence.nextval as IDX,
V.*
from
v$logmnr_contents V
where
seg_owner = 'SONICA' and
operation in ('INSERT','UPDATE','DELETE');
output_rec
c_v_logmnr_contents%ROWTYPE;
v_idx number;
PRAGMA EXCEPTION_INIT(file_not_available,
-1284);
begin
p_recordcount := 0;
p_errorcode := 0;
begin
execute immediate 'truncate table
logmnr.logmnr_contents';
execute immediate 'commit';
end;
dbms_logmnr.add_logfile(LogFileName => p_filename, Options =>
dbms_logmnr.NEW);
dbms_logmnr.start_logmnr(DictFileName
=> 'G:\dtb1\TURLIVE\utl_dir_file\TURLIVE_DICTIONARY.ORA',
Options => dbms_logmnr.committed_data_only);
open c_v_logmnr_contents;
v_idx
:= 0;
loop
fetch c_v_logmnr_contents
into output_rec;
exit when c_v_logmnr_contents%NOTFOUND;
insert into logmnr.logmnr_contents values
output_rec;
v_idx
:= v_idx + 1;
end
loop;
commit;
close
c_v_logmnr_contents;
dbms_logmnr.end_logmnr;
dbms_output.put_line('.
');
dbms_output.put_line('Records fetched in cursor loop = ' || TO_CHAR(v_idx));
dbms_output.put_line('. ');
p_recordcount := v_idx;
rollback;
exception
when
file_not_available
then null;
when others then
p_errorcode := sqlcode;
end;
end;
Answer:
By Steve Callan: You need to declare declare
file_not_available as a
PL/SQL exception:
output_rec c_v_logmnr_contents%ROWTYPE;
v_idx number;
file_not_available
exception; --***********************
PRAGMA EXCEPTION_INIT(file_not_available,
-1284);
|
|
Get the Complete
Oracle SQL Tuning Information
The landmark book
"Advanced Oracle
SQL Tuning The Definitive Reference" is
filled with valuable information on Oracle SQL Tuning.
This book includes scripts and tools to hypercharge Oracle 11g
performance and you can
buy it
for 30% off directly from the publisher.
|