简体   繁体   中英

How to handle a NULL Stored Proc return arg in Oracle XML DB Native Web Services?

I have a simple Oracle Package containing a simple Stored Procedure. The Stored Procedure declares 1 IN argument and several OUT arguments.

As long as the OUT arguments contain values I can successfully call the Stored Procedure using XML DB Native Web Services.

But if any of the OUT arguments contain NULL, I get a SOAP Fault containing an ORA-01405 Fetched column value is null.

I can see that there are options for handling NULL values when invoking SQL (using the <null_handling> element, but does anybody know how to do the same with PL/SQL ?

...

-- create a test table
CREATE TABLE xmldb_test
(
   key_value varchar2(32)
   ,value1 varchar2(32)
   ,value2 varchar2(32)
   ,value3 varchar2(32)
);

-- populate the table
insert into xmldb_test values ('key1', 'value1', 'value2', 'value3');
insert into xmldb_test values ('key2', 'value4', 'value5', null); -- this row has a null
commit;

-- create package
CREATE OR REPLACE package pack_xmldb_test
is
procedure getDataValue (ca_key in varchar2, ra_value1 out varchar2, ra_value2 out varchar2, ra_value3 out varchar2);
end;

-- create package body
create or replace package body pack_xmldb_test
is
procedure getDataValue (ca_key in varchar2, ra_value1 out varchar2, ra_value2 out varchar2, ra_value3 out varchar2)
IS
BEGIN
  select value1, value2, value3 
  into ra_value1, ra_value2, ra_value3
  from xmldb_test
  where key_value = ca_key;
END;
end;

-- test the package in pl/sql
declare
key_value varchar2(32) := 'key1';
value1 varchar2(32) := 'dog';
value2 varchar2(32) := null;
value3 varchar2(32) := null;
begin
dbms_output.put_line('before call, key_value:' || key_value);
pack_xmldb_test.getDataValue(key_value, value1, value2, value3);
dbms_output.put_line('after call, value1:' || value1 || ' value2:' || value2 || ' value3:' || value3);
end;

The WSDL for the Stored Procedure is at ...
http://node:port/orawsv/schema_name/pack_xmldb_test/getDataValue?wsdl

Build a soapUI project based on the WSDL, then ...

Sending the following request :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:get="http://xmlns.oracle.com/orawsv/CUSTOMER_FRAUD/PACK_XMLDB_TEST/GETDATAVALUE">
   <soapenv:Header/>
   <soapenv:Body>
      <get:GETDATAVALUEInput>
         <get:RA_VALUE3-VARCHAR2-OUT/>
         <get:RA_VALUE2-VARCHAR2-OUT/>
         <get:RA_VALUE1-VARCHAR2-OUT/>
         <get:CA_KEY-VARCHAR2-IN>key1</get:CA_KEY-VARCHAR2-IN>
      </get:GETDATAVALUEInput>
   </soapenv:Body>
</soapenv:Envelope>

... results in a successful call :

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <GETDATAVALUEOutput xmlns="http://xmlns.oracle.com/orawsv/CUSTOMER_FRAUD/PACK_XMLDB_TEST/GETDATAVALUE">
         <RA_VALUE1>value1</RA_VALUE1>
         <RA_VALUE2>value2</RA_VALUE2>
         <RA_VALUE3>value3</RA_VALUE3>
      </GETDATAVALUEOutput>
   </soap:Body>
</soap:Envelope>

... but calling with this request :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:get="http://xmlns.oracle.com/orawsv/CUSTOMER_FRAUD/PACK_XMLDB_TEST/GETDATAVALUE">
   <soapenv:Header/>
   <soapenv:Body>
      <get:GETDATAVALUEInput>
         <get:RA_VALUE3-VARCHAR2-OUT/>
         <get:RA_VALUE2-VARCHAR2-OUT/>
         <get:RA_VALUE1-VARCHAR2-OUT/>
         <get:CA_KEY-VARCHAR2-IN>key2</get:CA_KEY-VARCHAR2-IN>
      </get:GETDATAVALUEInput>
   </soapenv:Body>
</soapenv:Envelope>

... results in the following fault :

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>Error processing input</faultstring>
         <detail>
            <OracleErrors xmlns="http://xmlns.oracle.com/orawsv/faults">
               <OracleError>
                  <ErrorNumber>ORA-19202</ErrorNumber>
                  <Message>Error occurred in XML processing</Message>
               </OracleError>
               <OracleError>
                  <ErrorNumber>ORA-01405</ErrorNumber>
                  <Message>fetched column value is NULL</Message>
               </OracleError>
            </OracleErrors>
         </detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

Sorry this isn't a more eloquent solution, but maybe try in your pl/sql:

select nvl(ra_value1, '""'), nvl(ra_value2,'""'), nvl(ra_value3,'""')
into ra_value1, ra_value2, ra_value3
from xmldb_test
where key_value = ca_key;

I just converted the nulls to double quotes "", but change to whatever makes sense for the XML.

I admit this is a hack and there should be a more eloquent solution. Check the docs , honestly I'm not sure how to do this via the wsdl (if its even possible).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM