0

i want to print one of the node value as Author ="" empty string in xml node element as below: This syntax is in oracle:

CREATE OR REPLACE FUNCTION GetRtData
(    
    pf_wkstn_oid_sh number, 
    pf_wkstn_oid_lng number
)
RETURN varchar2
IS RtData varchar2(10000);
BEGIN
    SELECT REPLACE(XMLElement("TableData", 
                         XMLAGG(XMLElement("rt",XMLAttributes(field_data_type as field_data_type,'' as Author))) 
                       ).getStringVal(),'></rt>','/>')
    INTO RtData
    FROM pmry_c_rt_flng  
    where wkstn_oid_sh = pf_wkstn_oid_sh 
    AND wkstn_oid_lng = pf_wkstn_oid_lng;  
    return RtData;
END;

it is returning as below.

SQL> select GetRtData(100,4223) from dual;
GETRTDATA(100,4223)
----------------------------------------------------------------------------
<TableData><rt FIELD_DATA_TYPE="N"/></TableData>

even Author has removed in oracle while creating the node using as ( '' as 
Author) in the above result.

i want the result as below format: 

<TableData><rt FIELD_DATA_TYPE="N" Author=""/></TableData>

once i am using as

' ' as Author
<TableData><rt FIELD_DATA_TYPE="N" Author=" "/></TableData> one extra space which is not empty string. 

so can any one help me how to handle this one to make as Author = "" only in oracle.

1 Answer 1

0

You use REPLACE in your code, with 1 more REPLACE:

SELECT REPLACE(XMLElement("TableData", 
          XMLAGG(XMLElement("rt",XMLAttributes(1 as file_data_type, '' as Author))) 
       ).getStringVal(),'></rt>','/>')
  as xml
FROM dual;

XML
--------------------------------------------------------------------------------
<TableData><rt FILE_DATA_TYPE="1"/></TableData>



SELECT REPLACE(XMLElement("TableData", 
          XMLAGG(XMLElement("rt",XMLAttributes(1 as file_data_type, 'dummy' as Author))) 
       ).getStringVal(),'></rt>','/>')
  as xml
FROM dual;

XML
--------------------------------------------------------------------------------
<TableData><rt FILE_DATA_TYPE="1" AUTHOR="dummy"/></TableData>



SELECT REPLACE(REPLACE(XMLElement("TableData", 
          XMLAGG(XMLElement("rt",XMLAttributes(1 as file_data_type, 'dummy' as Author))) 
        ).getStringVal(),'></rt>','/>'), 'dummy')
  as xml
FROM dual;

XML
--------------------------------------------------------------------------------
<TableData><rt FILE_DATA_TYPE="1" AUTHOR=""/></TableData>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.