Block Comment Confusion ...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard

    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_SOUR CE;

    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_SOUR CE;

    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_SOUR CE
    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
  • Jan M. Nelken

    #2
    Re: Block Comment Confusion ...

    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_SOUR CE;
    >
    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_SOUR CE;
    >
    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_SOUR CE
    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:




    Jan M. Nelken

    Comment

    • Richard

      #3
      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
      misunderstandin g the audience of the SQL Reference manual.

      Thanks.

      Comment

      • Jan M. Nelken

        #4
        Re: Block Comment Confusion ...

        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
        misunderstandin g 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

        Comment

        Working...