Storing your Scripts in the XMLDB Repository

The underlying structure of the XMLDB repository is a blob, but why not…? The following code was once demonstrated by Mark Drake in May on the OTN XMLDB Forum. It is a very useful alternative way to store some of our code / scripts…

  res BOOLEAN;
  res := dbms_xdb.createResource('/public/q1.xqy','My Xquery');
SELECT xmlquery(xdburitype('/public/q1.xqy').getClob() 
       passing OBJECT_VALUE 
       returning content) 

Fill in “My XQuery” or else, with your code or statements. Secure it via XMLDB’s ACL security options and “voila” your own script repository, amongst others, maintainable via WebDAV.

Marco Gralike Written by:


  1. Robbie Vanhove
    August 5

    Hi Marco,

    I tried to implement this solution, but can not execute the xmlquery function like this. My xquery is saved in the ‘/public’ folder in the XML DB repository as you describe. But when I execute the xlmquery with xdburitype(‘/public/q1.xqy’).getClob(), I get an ORA-19102 – XQuery string literal expected – error. When I execute ‘select xdburitype(‘/public/q1.xqy’).getClob() from dual’, it works fine.

    Do you have any idea what can cause this problem?

    Kind regards,


  2. Robert
    August 26

    hi Marco,
    Sorry this question is not related to this post.

    I was reading XMLDB doc and came to this spot: [the spot]

    About using GLOBAL TEMPORARY TABLE under XMLDB…..

    The Schema-Based XMLType Tables under “structured storage” mode (xdb:defaultTable), this table can be GTT ?


  3. August 26

    The funny thing is that I “noticed” this a month ago myself (although I read the manual several times…)

    Now I just checked it…

    SQL*Plus: Release - Production 
    Copyright (c) 1982, 2007, Oracle.  
    ALL rights reserved.
    Enter user-name:
    Connected TO:
    Oracle DATABASE 11g Enterprise Edition 
    Release - Production
    WITH the Partitioning, OLAP, DATA Mining 
    AND REAL Application Testing options
    TABLE created.

    I can imagine that you could use this form of storage for temporarily storage of intermediate results of XML data or such…

    Regarding the xdb annotation “xdb:defaultTable”, I would have to look further into this although I can imagine that this can be done via also using the annotation “xdb:tableProps”. Although text specified in this clause is appended to the generated create table statement (using dbms_xmlschema).

  4. Robert
    August 27

    sigh…OTN forums still down….this is ridiculous

  5. Robert
    August 28

    Thanks Marco,

    In my previous post, I was thinking about
    * setting “GENTABLES => FALSE” in “DBMS_XMLSCHEMA.registerSchema’
    * *manually* create the xdb:defaultTable as GTT.

    what do you think ?

    PS: Reason for using GTT is because I’m doing “Truncate Table” on the xdb:defaultTable to speed up the cleanup
    (per Marks suggestion:
    (per Mark and your suggestion:

    This works like a charm except of course the DDL creates concurrency problem. :(

  6. August 28

    Manually is probably the only way to do a GTT

    I noticed though that deleting the folder resource is really fast while trying to get rid of the xml document “resources”

Comments are closed.