If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > declaring/setting variables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-12-08, 23:44
chesl73 chesl73 is offline
Registered User
 
Join Date: Oct 2008
Posts: 19
declaring/setting variables

Hi,

Can someone tell me what I'm doing wrong here as it appears pretty simple but it just doesn't work! I have the following stored proc:

CREATE PROCEDURE MYPROC(MYVAR VARCHAR10))
....
BEGIN
SET MYVAR = LCASE(MYVAR); --THIS LINE DOESN'T WORK
DECLARE C1 CURSOR FOR
SELECT * FROM TABLE
OPEN C1;
END @

Can anyone help with this? Am I setting the variable in the wrong place?
Reply With Quote
  #2 (permalink)  
Old 10-13-08, 03:01
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
CREATE PROCEDURE MYPROC(MYVAR VARCHAR10))
....
You didn't specify IN | OUT | INOUT for MYVAR.
So IN(default) was assumed.

Please try:
CREATE PROCEDURE MYPROC(INOUT MYVAR VARCHAR10))
....
Reply With Quote
  #3 (permalink)  
Old 10-13-08, 18:42
chesl73 chesl73 is offline
Registered User
 
Join Date: Oct 2008
Posts: 19
Hi, thanks for the reply.

This still isn't working though.

I still get an error saying:

SQL0104N An unexpected token "<cursor declaration>" was found following "".
Expected tokens may include: "<SQL statement>".

The SQL is as above with the SET after the BEGIN but before the cursor declaration.

Any ideas?
Reply With Quote
  #4 (permalink)  
Old 10-13-08, 23:50
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Order of declarations/statements in a Procedure are defined.

Please see "SQL Reference Volume 2" ---> "Statements" ---> "Compound SQL (Procedure)"

[label:]
BEGIN
[NOT ATOMIC | ATOMIC]
[SQL-variable-declaration; | condition-declaration; | return-codes-declaration;]
[statement-declaration;]
[DECLARE-CURSOR-statement;]
[handler-declaration;]
[SQL-procedure-statement;]
END
[label]

There is no “large bullets” between the elements in the syntax diagram.
This means that each elements in the diagram can't change the sequence of them.

You wrote a SET statement(SQL-procedure-statement) before DECLARE-CURSOR-statement.

Last edited by tonkuma; 10-14-08 at 00:02.
Reply With Quote
  #5 (permalink)  
Old 10-14-08, 06:57
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
In order to address those conditions, you can put the cursor declaration into a nested compound:
Code:
BEGIN
   SET MYVAR = LCASE(MYVAR);
   BEGIN
      DECLARE C1 CURSOR FOR
         SELECT * FROM TABLE
      OPEN C1;
   END;
END
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On