Serge Rielau wrote:
[color=blue]
> Ian Boyd wrote:[color=green]
> > 5. Comments
> >
> > How to do comments in DB2-SQL?
> >
> > From:
> > IBM DB2 Universal Database SQL Reference Volume 1 Version 8.2
> > Chapter 2. Language Elements
> > Tokens
> >
> >
> > Comments
> > Static SQL statements may include host language comments or SQL
> > comments. Either type of comment may be specified wherever a space
> > may be specified, except within a delimiter token or between
> > the keywords EXEC and SQL. SQL comments are introduced by two
> > consecutive hyphens (--) and ended by the end of the line.
> >
> >
> >
> > The following DB2-SQL fails:
> >
> > INSERT INTO Daily_Logs (
> > Daily_Log_Number, Created_By_User_ID, Property_ID, Shift_ID,
> > Bay_Number, Supervisor_User_ID, Location_ID, Occurrence_ID,
> > Checklist_ID, Daily_Log_Type_ID, Daily_Log_SubType_ID,
> > Start_Date, End_Date, Description) VALUES (
> > 'DL-20060307-1', --DailyLogNumber
> > 0, --CreatedByUserID
> > 1, --PropertyID
> > 1, --ShiftID
> > "A74", --BayNumber
> > 1, --SupervisorUserID
> > 2, --LocationID
> > CAST(NULL AS bigint), --Occurrence_ID (must manually cast nulls)
> > CAST(NULL AS bigint), --ChecklistID (must manually cast nulls)
> > 2, --DailyLogTypeID
> > 5, --DailyLogSubTypeID
> > '2006-03-01 11:11:07.11111', --StartDate
> > '2006-03-01 11:21:18.22222', --EndDate
> > CAST(NULL AS varchar(1)) --Description (must manually cast nulls)
> > );
> >
> > But if a take out the comments, it works. i have no keywords EXEC
> > or SQL, and i am not putting my comments within a delimiter token
> > "," since i cannot split a comma into two parts.
> >
> > *so tired*
> >
> >[/color]
> Ian, what tool are you using. This works for me using CLP
> Please clarify your environment.[/color]
This works in CLP? Doesn't for me! From DB2 UDB v8 under Linux:
$ db2 -t
(c) Copyright IBM Corporation 1993,2002
Command Line Processor for DB2 SDK 8.2.0
[snip help stuff]
db2 => SELECT
db2 (cont.) => F1, -- A comment
db2 (cont.) => F2, -- Another comment
db2 (cont.) => F3 -- Yet another comment
db2 (cont.) => FROM
db2 (cont.) => (VALUES (1, 2, 3)) AS T(F1, F2, F3);
SQL0104N An unexpected token "," was found following "SELECT F1".
Expected
tokens may include: "
". SQLSTATE=42601
db2 => SELECT
db2 (cont.) => -- A comment
db2 (cont.) => F1,
db2 (cont.) => -- Another comment
db2 (cont.) => F2,
db2 (cont.) => -- Yet another comment
db2 (cont.) => F3
db2 (cont.) => FROM
db2 (cont.) => (VALUES (1, 2, 3)) AS T(F1, F2, F3);
F1 F2 F3
----------- ----------- -----------
1 2 3
1 record(s) selected.
[color=blue]
> The thing about -- is that if your client strips out line feeds then
> everything after the first -- will look like a comment. select *
> --hello from -- comment t -- more comment And of course select * is
> not legal SQL. There is nothing DB2 can do on -- if the client screws
> things up... so please clarify your client interface.[/color]
Nope, in this case I think it's the thing I mentioned in my other post:
comments can only appear as the first non-whitespace characters in a
line.
[color=blue]
> PS: I find this thread quite interesting actually.[/color]
Absolutely. In another post I was rambling on vaguely incoherently
about functional versus procedural styles in DB2 and other DBs ... I'm
beginning to suspect there's a whole different way of thinking required
when switching from certain relational systems to others (a bit like
learning functional programming after doing C/Pascal imperative stuff
for so long ... I remember feeling very fatigued at how difficult
everything seemed, until there came a point where I just "got it" and
it all just seemed to fall into place ... the relief was tangible!)
Cheers,
Dave.