How to print empty string as a result from xml node creation using oracle in a procedure

oracle

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.

Best Answer

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>