Exforsys

Home arrow Reviews arrow PHP Oracle Training Tutorials

Accessing Repository Resources with SQL

Author : Exforsys Inc.     Published on: 3rd May 2008

Accessing Repository Resources with SQL

In fact, Oracle XML DB repository resources are stored in a set of database tables and indexes, which can be accessed via SQL. You are not supposed to access those tables directly. Instead, Oracle XML DB provides two public views RESOURCE_VIEW and PATH_VIEW through which you can access repository resources.

Ads

For example, you might issue the following query against the RESOURCE_VIEW view to access the employee XML document stored in the XML repository as /public/xmlusr/emps/emp303.xml, assuming that you have executed the PL/SQL block shown in the preceding section.

Sample Code
  1. SELECT extract(r.RES, '/Resource/Contents/*').getStringVal()
  2. RESULT FROM RESOURCE_VIEW r
  3. WHERE equals_path(res, '/public/xmlusr/emps/emp303.xml') = 1;
  4.  
Copyright exforsys.com


This should produce the following result:

Sample Code
  1.  
  2. <EMPLOYEE
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" target="_blank" rel="nofollow"
  4. xsi:noNamespaceSchemaLocation="employee.xsd"
  5. id="303">
  6. <ENAME>Locke</ENAME>
  7. <SALARY>7000</SALARY>
  8. </EMPLOYEE>
Copyright exforsys.com


However, in this particular example you don't have to query RESOURCE_VIEW to retrieve the above XML document through SQL. Instead, you might issue the following query against the employees XMLType table:

Sample Code
  1. SELECT extract(OBJECT_VALUE,'/').getStringVal()
  2. RESULT FROM employees
  3. WHERE existsNode(OBJECT_VALUE, '/EMPLOYEE/@id="303"') = 1;
  4.  
Copyright exforsys.com


You might be asking yourself: How could that have happened?a document uploaded into the XML repository appeared in an XMLType table? As you might recall from the listing describing the employee.xsd XML schema registration in the

Ads

Using XML Schemas section, the employees XMLType table is specifi ed as a default table in the employee.xsd XML schema and so it must have been generated during the schema registration process. Since the employee XML document inserted into the XML repository by the PL/SQL code as discussed in the preceding section is based on the employee.xsd XML schema, this document has been automatically inserted into the employees XMLType table.



 
This tutorial is part of a PHP Oracle Training Tutorials tutorial series. Read it from the beginning and learn yourself.

PHP Oracle Training Tutorials

 

Comments