It turns out that ORDS will treat the xml data only as BLOB, So we will need to parse the data inside our plsql.
Here is how it works:
1. create a web rest service(PUT operation in my case, application/xml in content type..) the same way you create a json based rest web service.
2. in the plsql, use :body to refer the incoming xml data from the client.
3. parse the xml data and use whatever needed in your plsql.
Here is the protocol of the plsql code:
declare
bb varchar2(50);
cc varchar2(40);
aa varchar2(4000);
begin
aa:=UTL_RAW.CAST_TO_VARCHAR2(:body); ---use :body to refer the xml data. and convert it to varchar2, :body will be BLOB type
SELECT xt.* into bb,cc
FROM
XMLTABLE('/Data'
PASSING aa
COLUMNS
"RG_GROUP" VARCHAR2(40) PATH 'rs_group',
"Status" VARCHAR2(10) PATH 'status'
) xt;
-- parsing the xml data to get the data you wanted based on the xml format
insert into mytrace values(bb||'/'||cc); --- do whatever you want here.
end;
in my case, the xml data is something like this:
<rs_group>xxxx-prd</rs_group>
<status>Success</status>
</Data>
So the key here is that ORDS will accept the xml data as BLOB data and then we can refer it as :body in our plsql.
Hi There
ReplyDeleteI see a reference to :body in many docs - but how is it routed from the ORDS request? It is not defined as a parameter ORDS.DEFINE_PARAMETER
Can you please explain how I get access to the body of a custom service (POST)? You cannot just put it in a PL/SQL package - it needs to be defined somewhere and passed.
thanks
Basically the :body is whatever the caller is put in their post calls.
ReplyDeleteYou don't need to declare, you can just use it in your plsql.
Hope this helps!