Delete Empty tag from xmltype oracle

后端 未结 2 977
遥遥无期
遥遥无期 2021-01-24 07:27

i want try to delete the empty tag from xmltype. I Have generate the below xml from oracle type. In the collection few elements does not have values so i generated with empty ta

2条回答
  •  星月不相逢
    2021-01-24 07:48

    Use DELETEXML and look for the XPath //*[not(text())][not(*)] to find elements that contain no text and no children:

    SQL Fiddle

    Oracle 11g R2 Schema Setup:

    CREATE TABLE table_name ( xml ) AS
    SELECT XMLTYPE( '
    
      9999
      S
      Test Location 
      08 
       
       
       
    
    ' ) FROM DUAL;
    

    Query 1:

    SELECT DELETEXML(
             xml,
             '//*[not(text())][not(*)]'
           ).getStringVal()
    FROM   table_name
    

    Results:

    |                                                                                            DELETEXML(XML,'//*[NOT(TEXT())][NOT(*)]').GETSTRINGVAL() |
    |-----------------------------------------------------------------------------------------------------------------------------------------------------|
    | 9999STest Location08  |
    

提交回复
热议问题