sql >> Database >  >> RDS >> Oracle

Verwijder lege tag van xmltype oracle

Gebruik DELETEXML en zoek naar de XPath //*[not(text())][not(*)] om elementen te vinden die geen tekst en geen kinderen bevatten:

SQL Fiddle

Oracle 11g R2 Schema-instellingen :

CREATE TABLE table_name ( xml ) AS
SELECT XMLTYPE( '<MESSAGE>
<LOCATIONS>
  <LOCATION_ID>9999</LOCATION_ID>
  <LOC_TYPE>S</LOC_TYPE>
  <NAME>Test Location</NAME> 
  <PHONE_NUM>08 </PHONE_NUM>
   <LAST_MODIFIED_BY/>
   <LAST_MODIFIED_DATE/>
   <POS_CODE/>
</LOCATIONS>
</MESSAGE>' ) FROM DUAL;

Query 1 :

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

Resultaten :

|                                                                                            DELETEXML(XML,'//*[NOT(TEXT())][NOT(*)]').GETSTRINGVAL() |
|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| <MESSAGE><LOCATIONS><LOCATION_ID>9999</LOCATION_ID><LOC_TYPE>S</LOC_TYPE><NAME>Test Location</NAME><PHONE_NUM>08 </PHONE_NUM></LOCATIONS></MESSAGE> |


  1. Knee-Jerk Performance Tuning:voeg gewoon een SSD toe

  2. Retourneer rijen die overeenkomen met elementen van invoerarray in plpgsql-functie

  3. json_encode en highcharts

  4. SQL Server:de donkere kant van NVARCHAR