Code Listing 2: Use CASE expressions to eliminate null values.


SELECT XMLElement("Attraction", XMLAttributes(government_owned AS GOV),
          XMLElement("Name",attraction_name),
          XMLElement("Location",location),
          XMLElement("URL",attraction_url))
FROM attraction 

WHERE attraction_name='Mackinac Bridge';

XMLELEMENT("ATTRACTION",XMLATTRIBUTES(GOV
---------------------------------------------------------------------
<Attraction GOV="Y">
  <Name>Mackinac Bridge</Name>

  <Location/>
  <URL>http://www.mackinacbridge.org/</URL>
</Attraction>


SELECT XMLElement("Attraction", XMLAttributes(government_owned AS GOV),
          CASE WHEN attraction_name IS NULL THEN NULL

             ELSE XMLElement("Name",attraction_name) END,
          CASE WHEN location IS NULL THEN NULL 
             ELSE XMLElement("Location",location) END,
          CASE WHEN attraction_url IS NULL THEN NULL 
             ELSE XMLElement("URL",attraction_url) END)
FROM attraction 
WHERE attraction_name='Mackinac Bridge';


XMLELEMENT("ATTRACTION",XMLATTRIBUTES(GOV
---------------------------------------------------------------------
<Attraction GOV="Y">
  <Name>Mackinac Bridge</Name>
  <URL>http://www.mackinacbridge.org/</URL>
</Attraction>

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy