Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old October 10th, 2008, 06:35 PM
Richard
Guest
 
Posts: n/a
Default 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
  #2  
Old October 10th, 2008, 07:25 PM
Jan M. Nelken
Guest
 
Posts: n/a
Default Re: Block Comment Confusion ...

Richard wrote:
Quote:
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
  #3  
Old October 10th, 2008, 08:45 PM
Richard
Guest
 
Posts: n/a
Default Re: Block Comment Confusion ...

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.
  #4  
Old October 10th, 2008, 10:05 PM
Jan M. Nelken
Guest
 
Posts: n/a
Default Re: Block Comment Confusion ...

Richard wrote:
Quote:
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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles