help experts! i'm getting this error when i am running the below procedure. however, i do not get this error on a consistent basis. sometimes the process runs fine. other times i get this error, so i don't think it's a code problem. this is leading me to think that it is occuring as result of some limitation (memory, number of processes allowed, etc) on either my database or server (hp unix). can someone give me an idea as to what could be causing this? can you think of some system settings that i could raise to avoid this?
ORA-21560: argument 3 is null, invalid, or out of range
CREATE OR REPLACE PROCEDURE botables_proc (
p_tablename VARCHAR2,
p_xml_dir VARCHAR2,
p_parse_name VARCHAR2,
p_reqid NUMBER
)
IS
v_in_handle SYS.UTL_FILE.file_type;
v_insctx SYS.dbms_xmlsave.ctxtype;
n_rows NUMBER;
n_row_flag NUMBER := 0;
n_parse_file_flag NUMBER := 0;
n_record_count NUMBER := 0;
v_clob CLOB;
v_bfile BFILE;
n_amt BINARY_INTEGER;
v_offset INTEGER := 1;
c_xml_row VARCHAR2 (32767) := 'XXX';
n_substr_amount INTEGER;
n_instr_offset INTEGER := 1;
n_dest_offset NUMBER := 1;
n_src_offset NUMBER := 1;
n_lang_ctx NUMBER := DBMS_LOB.default_lang_ctx;
n_bfile_csid NUMBER := SYS.DBMS_LOB.default_csid;
n_warning NUMBER;
BEGIN
--sets context handle to reference table
v_insctx := SYS.dbms_xmlsave.newcontex
t (p_tablename);
--sets incoming date format
SYS.dbms_xmlsave.setdatefo
rmat (v_insctx, 'yyyy-MM-dd HH:mm:ss');
--ignores case differences between tags and column names
SYS.dbms_xmlsave.setignore
case (v_insctx, 1);
--create a bfile using the xml directory created by the DBA.
v_bfile := BFILENAME ('XML', p_reqid || '_INSERT_' || p_parse_name);
--create a temporary lob. this lob resides in RAM for the
--duration of the session.
SYS.DBMS_LOB.createtempora
ry (v_clob, TRUE, DBMS_LOB.SESSION);
--open the temporary lob for read/write. this is done implicitly
--by oracle, but is being left as a comment for reference so it is known
--that this step was not skipped.
--SYS.DBMS_LOB.OPEN (v_clob, SYS.DBMS_LOB.lob_readwrite
);
--get the length of the bfile so you know how much space
--you need to open it.
n_amt := DBMS_LOB.getlength (v_bfile);
--open the bfile for reading
SYS.DBMS_LOB.fileopen (v_bfile, SYS.DBMS_LOB.file_readonly
);
--load the contents of the bfile into the temporary lob
SYS.DBMS_LOB.loadclobfromf
ile (v_clob,
v_bfile,
n_amt,
n_dest_offset,
n_src_offset,
n_bfile_csid,
n_lang_ctx,
n_warning
);
--create a table context to save to
v_insctx := SYS.dbms_xmlsave.newcontex
t (p_tablename);
--set the date format for the insert
SYS.dbms_xmlsave.setdatefo
rmat (v_insctx, 'yyyy-MM-dd HH:mm:ss');
--set the package to ignore case
SYS.dbms_xmlsave.setignore
case (v_insctx, 1);
--while the end of the clob (xml file) has not been reached,
--read it line by line and insert and lines that contain "<ROW>"
--into the table.
WHILE c_xml_row NOT LIKE '%</ROWSET>%'
LOOP
n_substr_amount :=
(SYS.DBMS_LOB.INSTR (v_clob, CHR (10), n_instr_offset, 1) - 1
);
n_substr_amount := n_substr_amount - n_instr_offset + 1;
c_xml_row :=
SYS.DBMS_LOB.SUBSTR (v_clob, n_substr_amount, n_instr_offset);
IF c_xml_row LIKE '%<ROW>%'
THEN
BEGIN
n_rows := SYS.dbms_xmlsave.insertxml
(v_insctx, c_xml_row);
EXCEPTION
--any exception that is encased in the oracle java exception -29532 will be searched
--for the strings indicating that an index or constraint were violated. if these
--strings are found, then nothing will happen because those errors will intentionally
--occur frequently due to the indexes and constraints that have been added to the
--ODS tables.
WHEN OTHERS
THEN
IF INSTR (SQLERRM, 'ORA-00001', 1) > 0
OR INSTR (SQLERRM, 'ORA-01400', 1) > 0
THEN
NULL;
ELSE
DBMS_OUTPUT.put_line ( 'Error inserting to table '
|| p_tablename
|| ' by file '
|| p_parse_name
);
DBMS_OUTPUT.put_line ( 'Bad XML Line: '
|| SUBSTR (c_xml_row, 1, 225)
);
DBMS_OUTPUT.put_line ('ERROR: ' || SUBSTR (SQLERRM, 1, 175));
DBMS_OUTPUT.put_line ('');
END IF;
END;
END IF;
n_instr_offset := n_instr_offset + n_substr_amount + 1;
END LOOP;
--close the open file handles an lob and free the resources used.
SYS.dbms_xmlsave.closecont
ext (v_insctx);
SYS.DBMS_LOB.fileclose (v_bfile);
SYS.UTL_FILE.fclose (v_in_handle);
--the dbms_lob.close is not needed for temporary lobs and
--the freetemporary call is done implicitly by the
--dbms_lob.session parameter in the createtemporary call above.
--both statements are being left as comment so it is known that
--these steps were not skipped.
--SYS.DBMS_LOB.CLOSE (v_clob);
--SYS.DBMS_LOB.freetempora
ry (v_clob);
--insert a count of the total records inserted by a report
INSERT INTO ems_owner.rpt_sltn_err_lly
VALUES (p_parse_name, SYSDATE, n_record_count);
COMMIT;
EXCEPTION
--in case of any error encountered, close the open file
--handles an lob and free the resources used.
WHEN OTHERS
THEN
SYS.dbms_xmlsave.closecont
ext (v_insctx);
DBMS_LOB.fileclose (v_bfile);
SYS.UTL_FILE.fclose (v_in_handle);
--the dbms_lob.close is not needed for temporary lobs and
--the freetemporary call is done implicitly by the
--dbms_lob.session parameter in the createtemporary call above.
--both statements are being left as comment so it is known that
--these steps were not skipped.
--SYS.DBMS_LOB.CLOSE (v_clob);
--SYS.DBMS_LOB.freetempora
ry (v_clob);
DBMS_OUTPUT.put_line (SQLERRM);
COMMIT;
END;
/