Query data in Oracle XMLType

Source: Internet
Author: User

XMLtype query operations:
Example of the query object: Table Name: etab. The first column is varchar2 () and the second column is xmltype,
The id field value is aa.
The value of the xmlcol field is:
[Html]
<ProductMetaData>
<SatelliteID> 02B </SatelliteID>
<ReceiveStationID> BRA </ReceiveStationID>
<SensorID aa = 'exattr'> CCD </SensorID>
<ReceiveTime> 22:12:24 </ReceiveTime>
<OrbitID> 448 </OrbitID>
</ProductMetaData>


 
1: extract
Purpose: extract the value of the specified node in the XML string (including the tag at both ends of the node). The result is still in clob format.
Use the syntax of column. extract ('// xxx/xx') or extract (column,' // xxx/xx ').
For example:
Select t. id, t. xmlcol. extract ('// ProductMetaData/sensorid') from etab t
Select t. id, extract (t. xmlcol, '// ProductMetaData/sensorid') from etab t
Extracted content is (still in CLOB format): <SensorID aa = 'exattr '> BRA </SensorID>
 
You can also add/text () to the end to obtain the internal text (the result is still in clob format)
For example:
Select t. id, t. xmlcol. extract ('// ProductMetaData/SensorID/text ()') from etab t
Extracted content is (still in CLOB format): BRA
 
Or Add/@ att to get the node attribute value.
For example:
Select t. id, t. xmlcol. extract (www.2cto.com) from etab t
Extracted content is (still in CLOB format): ExAttr
 
You can use the getnumberval () or getstringval () function to convert the result to a required text or number.
For example:
Select t. id, t. xmlcol. extract ('// ProductMetaData/SensorID/text ()'). getstringval () from etab t
Extracted content is (Text Format): BRA
 
Select t. id, t. xmlcol. extract ('// ProductMetaData/OrbitID/text ()'). getnumberval () from etab t
Extracted content is (number format, which can be used for condition determination, for example, greater than or less than): 448
 
Extract content as condition judgment:
Select t. id from etab t where t. xmlcol. extract ('// ProductMetaData/OrbitID/text ()'). getnumberval ()> 440
 
2. extactrvalue
Purpose: extract the value of the specified node in the XML string (excluding the tag at both ends of the node). The result is in text format (if the value is a number, it may also be considered as a number, it can also be used for condition determination in queries)
Only the format of extractvalue (column, '// xxx/xx') can be used
For example:
Select t. id, extractvalue (t. xmlcol, '// ProductMetaData/sensorid') from etab t
Extracted content is the PMS in text format.

Select t. id from etab t where t. xmlcol. extract ('// ProductMetaData/OrbitID/text ()'). getnumberval ()> 2440
 

Author: rrrrssss00

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.