Topic
  • 2 replies
  • Latest Post - ‏2012-02-27T10:40:08Z by ghostrider2
ghostrider2
ghostrider2
4 Posts

Pinned topic unable to declare namespaces in db2 XQuery

‏2012-02-27T10:01:24Z |
Hi,
While trying to run this in db2 v9.5 platform AIX, in a text file


xquery declare namespace q1 = 
"http://www.xbrl.org/2003/instance" ; xquery declare namespace q =
"http://www.xbrl.org/in/2011-03-31/q"; 

for $d in db2-fn:xmlcolumn(
'XMLTEST.XML') let $abc := ($d/q1:xbrl/q:PercentageHeld/text()) 

return $d;


i am getting the error :

SQL16002N An XQuery expression has an unexpected token
""http://www.xbrl.org/2003/instance"" following "re namespace q1=".
Expected tokens may include: "<space>". Error QName=err:XPST0003.
SQLSTATE=10505

SQL16002N An XQuery expression has an unexpected token
""http://www.xbrl.org/in/2011-03-31/q" following "re namespace q".
Expected tokens may include: "<space>". Error QName=err:XPST0003.
SQLSTATE=10505

DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "for $d in" was found following
"BEGIN-OF-STATEMENT". Expected tokens may include: "<values>".
SQLSTATE=42601
Updated on 2012-02-27T10:40:08Z at 2012-02-27T10:40:08Z by ghostrider2
  • SystemAdmin
    SystemAdmin
    746 Posts

    Re: unable to declare namespaces in db2 XQuery

    ‏2012-02-27T10:11:39Z  
    Unless it's some kind of db2 peculiarity, the keyword "xquery" in your query doesn't belong - delete it, twice.
  • ghostrider2
    ghostrider2
    4 Posts

    Re: unable to declare namespaces in db2 XQuery

    ‏2012-02-27T10:40:08Z  
    Unless it's some kind of db2 peculiarity, the keyword "xquery" in your query doesn't belong - delete it, twice.
    Hi
    Incase i delete both the xquery keywords
    
    
    
    for $d in db2-fn:xmlcolumn(
    'XMLTEST.XML') let $abc := ($d/q:xbrl/q1:PercentageOfEquityHeld/text()) 
    
    return $d;
    


    i get the error :

    DB21034E The command was processed as an SQL statement because it was not a
    valid Command Line Processor command. During SQL processing it returned:
    SQL0104N An unexpected token "for $d in" was found following
    "BEGIN-OF-STATEMENT". Expected tokens may include: "<values>".
    SQLSTATE=42601
    also, when i remove the xquery keywords and define the namespaces

    
    declare namespace q = 
    "http://www.xbrl.org/2003/instance" ; declare namespace q1 =
    "http://www.xbrl.org/in/2011-03-31/in-gaap"; 
    
    for $d in db2-fn:xmlcolumn(
    'XMLTEST.XML') let $abc := ($d/q:xbrl/q1:PercentageOfEquityHeld/text()) 
    
    return $d;
    


    i get the following errors :
    DB21034E The command was processed as an SQL statement because it was not a
    valid Command Line Processor command. During SQL processing it returned:
    SQL0104N An unexpected token "declare namespace" was found following
    "BEGIN-OF-STATEMENT". Expected tokens may include: "<variable_set>".
    SQLSTATE=42601

    DB21034E The command was processed as an SQL statement because it was not a
    valid Command Line Processor command. During SQL processing it returned:
    SQL0104N An unexpected token "declare NAMESPACE q1" was found following
    "BEGIN-OF-STATEMENT". Expected tokens may include: "<variable_set>".
    SQLSTATE=42601

    DB21034E The command was processed as an SQL statement because it was not a
    valid Command Line Processor command. During SQL processing it returned:
    SQL0104N An unexpected token "for $d in" was found following
    "BEGIN-OF-STATEMENT". Expected tokens may include: "<values>".
    SQLSTATE=42601
    and

    when i run
    
    xquery 
    
    for $d in db2-fn:xmlcolumn(
    'XMLTEST.XML') 
    
    return $d;
    


    i get all the records of xml column.