Topic
2 replies Latest Post - ‏2011-12-23T04:52:55Z by SystemAdmin
SystemAdmin
SystemAdmin
230 Posts
ACCEPTED ANSWER

Pinned topic XMLQUERY help

‏2011-12-21T07:16:21Z |
Hello,

am trying to run the below query and facing some error.
Using putty so added escape character('\') before '$'.
db2 "SELECT XMLQUERY (
'for \$d in \$doc/Client/fax
return \$d'
passing CONTACTINFO as "doc")
FROM CLIENTS"


ERROR: SQL16005N An XQuery expression references an element name, attribute name,
type name, function name, namespace prefix, or variable name "doc" that is not
defined within the static context. Error QName=err:XPST0008. SQLSTATE=10506



your help will be highly apreciable.

Thanks!
Updated on 2011-12-23T04:52:55Z at 2011-12-23T04:52:55Z by SystemAdmin
  • MatthiasNicola
    MatthiasNicola
    303 Posts
    ACCEPTED ANSWER

    Re: XMLQUERY help

    ‏2011-12-21T11:31:10Z  in response to SystemAdmin
    You can avoid a lot of problems if you don't try to run such queries with the db2 command at the operating system prompt. The escaping of $-signs, the use of quotes, etc. can all interfere when the OS is parsing the input string.

    Here are two alternatives that usually work better:

    1.
    Enter the DB2 command line processor with this command: db2 -t
    Then you get the db2 prompt that looks like this:

    db2 =>

    There you can enter you queries without having to escape anything, and that avoids a lot of problems. The -t option means that each query needs to be terminated with the semicolon character.

    2.
    Type your query into a text file and save it, e.g. as myquery.sql. Then run the query with the following command:

    db2 -tvf myquery.sql
    Hope this helps.


    Matthias Nicola
    http://www.tinyurl.com/pureXML
    http://nativexmldatabase.com/