2

I have a requirement to load an xml file to a particular table. i have tried with below code but it did not solve my problem.

The xml data is:

<FAX>  
  <EMAILOG>  
    <ID>7839</ID>  
    <RESPONSE>FAX SENT</RESPONSE>  
  </EMAILOG>  
  <EMAILOG>  
    <ID>7566</ID>  
    <RESPONSE>FAX NOT SENT</RESPONSE>  
  </EMAILOG>  
</FAX>  

I was executing procedure with a help of pl/sql developer grid. right clicking the procedure Test --> Loading xml file from harddisk --> execute.

Here is the DDL explaining the procedure.

create table emp3 as select * From emp  where 1=1;    
alter table emp3 add (fax_response varchar2(50)); 
create global temporary table tmp_xml of xmltype xmltype store as securefile binary xml;

create or replace procedure proc_upd_email_records ( loc_xml in clob ) is
begin
  insert into tmp_xml
  values (xmlparse(document loc_xml)) ;

  merge into emp3 e
  using (
    select id
         , response 
    from tmp_xml t
       , xmltable(
           '/FAX/EMAILOG'
           passing t.object_value 
           columns id       number        path 'ID'
                 , response varchar2(250) path 'RESPONSE' 
         )
  ) v
  on ( e.empno = v.id )
  when matched then update
    set e.fax_response = v.response;
end;
/

by executing via the PL/SQL Developer "Test" procedure method I am getting below error

ora 22805 : can not insert null object into object tables or nested tables

Michael O'Neill
  • 946
  • 7
  • 22
ravt
  • 71
  • 2
  • 9
  • Can you share what you are executing? Your code is essentially correct. How you are invoking the procedure is the problem. – Michael O'Neill Jan 24 '14 at 19:51
  • Hi, i am using oracle pl sql developer and i am passing xml file as in mode parameter. simply loading xml file from computer hard disk.version i am using is version i am using is **Oracle Database 11g Enterprise Edition Release 11.2.0.1.0** – ravt Jan 25 '14 at 03:39

1 Answers1

1

This works just fine for me (using Oracle Database 11g Express Edition Release 11.2.0.2.0).

declare 
   v_xml clob;
begin
   v_xml := 
'<FAX>  
   <EMAILOG>  
      <ID>7839</ID>  
      <RESPONSE>FAX SENT</RESPONSE>  
   </EMAILOG>  
   <EMAILOG>  
      <ID>7566</ID>  
      <RESPONSE>FAX NOT SENT</RESPONSE>  
   </EMAILOG>  
</FAX>';

  proc_upd_email_records(v_xml);
end;
Michael O'Neill
  • 946
  • 7
  • 22
  • @ravt That's great, but you NEED to update the question with the code of how you were invoking your stored procedure. Without doing so, you are leaving nothing of value behind for anyone else. This answer doesn't actually answer the question without your question becoming meaningful. – Michael O'Neill Jan 27 '14 at 21:03
  • Hi Clever, Sorry for delay in reply. previously i was executing procedure with a help of pl/sql developer grid. right clicking the procedure Test --> Loading xml file from harddisk --> execute. by using above method i was getting error -->ora 22805 : can not insert null object into object tables or nested tables after that i have implemented your idea then instantly i got the answer. Please suggest me if any thing needs to added like attaching screen shot of executing the procedure. – ravt Jan 31 '14 at 10:56
  • I updated the question with your new facts. Truly, you left out the most important aspects of your question to begin with. Keep that in mind on your next question. – Michael O'Neill Jan 31 '14 at 15:05