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 > Db2 Stored Procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-13-06, 13:08
Ruttenj Ruttenj is offline
Registered User
 
Join Date: Oct 2005
Posts: 6
Db2 Stored Procedure

Hello All,

I am trying to write a Db2 Stored Procedure and getting an error.
The basic structure of my SP is

Create table a

Insert into table a

Create table b

Insert into table b

Create table c

Insert into table c

Cursor select statement

open cursor

I am getting the following error on the cursor select statement:

$$UUDVLP.SDG0012P - Build started.
DROP SPECIFIC PROCEDURE $$UUDVLP.SQL060113102640200
$$UUDVLP.SDG0012P - Drop stored procedure completed.
Create stored procedure returns -104.
$$UUDVLP.SDG0012P: 339: [IBM][CLI Driver][DB2/NT] SQL0104N An unexpected token "<cursor declaration>" was found following "". Expected tokens may include: "<SQL statement>". LINE NUMBER=339. SQLSTATE=42601

$$UUDVLP.SDG0012P - Build failed.
$$UUDVLP.SDG0012P - Roll back completed successfully.

Any ideas?
Reply With Quote
  #2 (permalink)  
Old 01-13-06, 13:10
Ruttenj Ruttenj is offline
Registered User
 
Join Date: Oct 2005
Posts: 6
Db2 Stored procedure

Also have ; after each statement
Reply With Quote
  #3 (permalink)  
Old 01-13-06, 14:16
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Cursor declaration must appear before any executable statements.
Reply With Quote
  #4 (permalink)  
Old 01-13-06, 15:19
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Unless of course the cursor is referencing the table they are creating. You can overcome this by putting your DECLARE CURSOR and OPEN CURSOR statements in a BEGIN--END block.

Andy
Reply With Quote
  #5 (permalink)  
Old 01-17-06, 08:43
Ruttenj Ruttenj is offline
Registered User
 
Join Date: Oct 2005
Posts: 6
Arwinner

THANKS! Arwinner. That did it.
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