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
passing CONTACTINFO as "doc")
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.
MatthiasNicola 120000E28R322 Posts
Re: XMLQUERY help2011-12-21T11:31:10ZThis is the accepted answer. This is the accepted answer.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:
Enter the DB2 command line processor with this command: db2 -t
Then you get the db2 prompt that looks like this:
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.
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.