469,366 Members | 2,408 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

Block Comment Confusion ...

Again, new to DB2. Trying to do something I can do in Sybase ASE.

In any Sybase SQL script I can use /* */ to comment out a block of
code.

In the DB2 9.0 SQL Reference Manual V1 it says:
Comments: SQL comments are either bracketed (introduced by /* and end
with */) or simple (introduced by two consecutive hyphens and end with
the end of line). Static SQL statements can include host language
comments or SQL comments. Comments can be specified wherever a space
can be specified, except within a delimiter token or between the
keywords EXEC and SQL.
I have this piece of DB2 SQL

connect to DB_PPES;

select count(*) from PPES_REQUEST;

select count(*) from PPES_DISPATCHER;

select count(*) from PPES_ADMIN_SOURCE;

which runs fine. But, when I try to use /* */ to block out the middle
select I get
errors.

So, this:
connect to DB_PPES;

select count(*) from PPES_REQUEST;
/*
select count(*) from PPES_DISPATCHER;
*/
select count(*) from PPES_ADMIN_SOURCE;

produces this:
select count(*) from PPES_REQUEST

1
-----------
369955

1 record(s) selected.
/* select count(*) from PPES_DISPATCHER
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 "/* select count(*) from
PPES_DISPATCHER" was
found following "BEGIN-OF-STATEMENT". Expected tokens may include:
"<space>". SQLSTATE=42601

*/ select count(*) from PPES_ADMIN_SOURCE
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 "*/" was found following "BEGIN-OF-
STATEMENT".
Expected tokens may include: "<space>". SQLSTATE=42601
I realize that I could just put -- in front of the line I want to
comment out, but what if I wanted to
comment out 1000's of lines. The manual says it should work, yet I
can't it to. Our DB2 version is
9.1.0.4. The command I'm executing the query with is "db2 -tf x.sql"

Thanks
Oct 10 '08 #1
3 10337
Richard wrote:
Again, new to DB2. Trying to do something I can do in Sybase ASE.

In any Sybase SQL script I can use /* */ to comment out a block of
code.

In the DB2 9.0 SQL Reference Manual V1 it says:
Comments: SQL comments are either bracketed (introduced by /* and end
with */) or simple (introduced by two consecutive hyphens and end with
the end of line). Static SQL statements can include host language
comments or SQL comments. Comments can be specified wherever a space
can be specified, except within a delimiter token or between the
keywords EXEC and SQL.
I have this piece of DB2 SQL

connect to DB_PPES;

select count(*) from PPES_REQUEST;

select count(*) from PPES_DISPATCHER;

select count(*) from PPES_ADMIN_SOURCE;

which runs fine. But, when I try to use /* */ to block out the middle
select I get
errors.

So, this:
connect to DB_PPES;

select count(*) from PPES_REQUEST;
/*
select count(*) from PPES_DISPATCHER;
*/
select count(*) from PPES_ADMIN_SOURCE;

produces this:
select count(*) from PPES_REQUEST

1
-----------
369955

1 record(s) selected.
/* select count(*) from PPES_DISPATCHER
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 "/* select count(*) from
PPES_DISPATCHER" was
found following "BEGIN-OF-STATEMENT". Expected tokens may include:
"<space>". SQLSTATE=42601

*/ select count(*) from PPES_ADMIN_SOURCE
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 "*/" was found following "BEGIN-OF-
STATEMENT".
Expected tokens may include: "<space>". SQLSTATE=42601
I realize that I could just put -- in front of the line I want to
comment out, but what if I wanted to
comment out 1000's of lines. The manual says it should work, yet I
can't it to. Our DB2 version is
9.1.0.4. The command I'm executing the query with is "db2 -tf x.sql"

Thanks
Use (= and =) to denote block comments. From V9 documentation:

Input file lines which begin with (= are treated as the beginning of a
comment block. Lines which end with =) mark the end of a comment block.
The block of input lines that begins at (= and ends at =) is treated as
a continuous comment by the command line processor. Spaces before (= and
after =) are allowed. Comments may be nested, and may be used nested in
statements. The command termination character (;) cannot be used after =).

Link to documentation page describing this:

http://publib.boulder.ibm.com/infoce...c/r0010410.htm
Jan M. Nelken
Oct 10 '08 #2
Thanks. :-) That worked on my 9.1 server. A coworker tried on an 8.x
server and got
an error with the (= , so I'll assume it only works in 9.x.

So what am I intrepreting incorrectly. In the 9.0 SQL Reference
Manual is says use /* */, yet the CLP manual says (= =). Since I'm
running a SQL script in the CLP, shouldn't either work? Maybe I'm
misunderstanding the audience of the SQL Reference manual.

Thanks.
Oct 10 '08 #3
Richard wrote:
Thanks. :-) That worked on my 9.1 server. A coworker tried on an 8.x
server and got
an error with the (= , so I'll assume it only works in 9.x.

So what am I intrepreting incorrectly. In the 9.0 SQL Reference
Manual is says use /* */, yet the CLP manual says (= =). Since I'm
running a SQL script in the CLP, shouldn't either work? Maybe I'm
misunderstanding the audience of the SQL Reference manual.

Thanks.
To be precise:

SQL Reference states:
SQL comments

Static SQL statements can include host language or SQL comments. Dynamic
SQL statements can include SQL comments. There are two types of SQL
comments:

simple comments
Simple comments are introduced by two consecutive hyphens (--) and
end with the end of line.
bracketed comments
Bracketed comments are introduced by /* and end with */.

The following rules apply to the use of simple comments:

* The two hyphens must be on the same line and must not be
separated by a space.
* Simple comments can be started wherever a space is valid (except
within a delimiter token or between 'EXEC' and 'SQL').
* Simple comments cannot be continued to the next line.
* In COBOL, the hyphens must be preceded by a space.

The following rules apply to the use of bracketed comments:

* The /* must be on the same line and must not be separated by a space.
* The */ must be on the same line and must not be separated by a space.
* Bracketed comments can be started wherever a space is valid
(except within a delimiter token or between 'EXEC' and 'SQL').
* Bracketed comments can be continued to subsequent lines.
Let me show this again:

*Static SQL statements* can include host language or SQL comments.
*Dynamic SQL statements* can include SQL comments.

This would be correct:

select /* I am using
SELECT keyword
*/
count /* I am going
to count
rows
*/
(*) from /* I will use
Sample database
ORG table
here
*/
ORG;
but you *WERE NOT* including bracketed comments in Static or dynamic SQL
statement; you were trying to comment out lines in CLP script - hence
you have to use CLP syntax.
Jan M. Nelken
Oct 10 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Xah Lee | last post: by
11 posts views Thread by Mark Schneider | last post: by
4 posts views Thread by William | last post: by
18 posts views Thread by John Salerno | last post: by
4 posts views Thread by ksukhonosenko | last post: by
3 posts views Thread by GS | last post: by
3 posts views Thread by MartinRinehart | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.