序言或查询主体中允许使用注释。注释不会影响查询处理。
注释由通过符号
(: 和
:) 定界的字符串组成。以下示例是 XQuery 中的注释:
(: A comment. You can use comments to make your code easier to understand. :)
下列通用规则适用于在
DB2® XQuery
中使用注释:
- 允许使用可忽略空格的位置都可以使用注释。可忽略空格就是对表达式结果没有意义的空格。
- 构造函数内容中不允许使用注释。
- 注释可相互嵌套,但每个嵌套注释必须具有左定界符和右定界符 (: 和 :)。
下列示例说明合法的注释以及会产生错误的注释:
- (: is this a comment? ::) 是合法注释。
- (: is this a comment? ::) or an error? :) 会产生错误,原因是符号
(: 和 :) 的嵌套失衡。
- (: commenting out a (: comment :) might be confusing, but is often
helpful :) 是合法注释,原因是允许进行平衡的注释嵌套。
- "this is just a string :)" 是合法表达式。
- (: "this is just a string :)" :) 会产生错误。同样,"this is another string (:"
是合法表达式,而 (: "this is another string (:" :) 会产生错误。文字内容可能会导致注释嵌套失衡。