title: Handling nulls when using Oracle XMLType
body: <p>I am using Oracle's XMLType function to get XML data from a stored procedure that returns a cursor. My SQL looks something like this:</p>
  
  <pre><code>select 
  XMLType(
      package_name.storedProcName('PARAM1', 'PARAM2', 'PARAM3')
  ) as sresult 
  from dual;
  </code></pre>
  
  <p>In cases where the stored procedure returns records, this works fine and I get the XML result that I expect. However, when the procedure returns no records, I get the following error(s):</p>
  
  <pre><code>ORA-06502: PL/SQL: numeric or value error
  ORA-06512: at "SYS.XMLTYPE", line 334
  ORA-06512: at line 1
  </code></pre>
  
  <p>Preferably, I'd like to return null, a blank string or some other value in this case. Certainly I want to avoid raising an Oracle exception every time this happens. What can I do to achieve this?</p>
  
  <p><strong>Clarification:</strong> My problem is that when the stored procedure returns an empty cursor, the XMLType constructor raises an exception. How can I detect an empty cursor inside my SQL query? (Unfortunately, I don't have the luxury of programming on the Oracle side - I am programming a Java client.)</p>