Monday, August 04, 2008

ORA-00942 and ORA-06512 at SYS.XMLTYPE

Always check out the original article at http://www.oraclequirks.com for latest comments, fixes and updates.

You may get the following puzzling stack of error messages when you attempt to use the XMLTYPE constructor on an empty CLOB.
This error can be easily reproduced in the following way:

select xmltype(empty_clob()) as x
from dual;
ORA-00942: table or view does not exist
ORA-06512: at "SYS.XMLTYPE", line 254
ORA-06512: at line 1
Most likely, in a real life scenario, you initialized a CLOB column with the special value EMPTY_CLOB(), that is standard practice when you need to insert a CLOB value into a table as the result of a conversion from a BLOB type, as shown in this PL/SQL snippet:
...
insert into file_store
( name, document, created_by)
values (l_name, empty_clob(), p_user)
returning id, document into l_id, l_clob;

dbms_lob.convertToClob(l_clob, l_blob, DBMS_LOB.LOBMAXSIZE, l_dest_off, l_src_off, l_csid, l_shift, l_warning);
...

Note that you can compare the lob locator with the value EMPTY_CLOB().
...
if l_clob = empty_clob() then
-- lob locator is empty
...
elsif l_clob is null then

-- lob locator is atomically null
...
else

-- lob locator contains a non empty CLOB
...
end if;
...
in case you need to distinguish between a null CLOB locator and an empty CLOB locator.

Once you are sure that the document is not empty, you can try to apply the XMLType constructor and see if you get any parsing errors.

See message translations for ORA-00942 and search additional resources.

2 comments:

  1. IF THIS WORKS I AM GOING TO BUILD AN ALTAR IN MY BACKYARD WITH YOUR STATUE AND I'LL TATOO YOUR NAME IN MY ASS. Let me check.

    ReplyDelete
  2. You are a life saver. Thanks a lot

    ReplyDelete

I appreciate your comment however bear in mind that I might not have the time to reply soon.
Normally I do not reply to all comments but I am glad if you found something useful or if you learned something new, in that case I strongly encourage you to promote the article with the +1 google button.
Flavio