473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

error in Stored procedure while using cursor

19
When I am trying to declare a cursor over a temproay table in my stored procedure I am getting some errors.
Below are the piece of code from my stored procedure in which I am getting error.

Expand|Select|Wrap|Line Numbers
  1. DECLARE GLOBAL TEMPORARY TABLE
  2.            SESSION.TEMP_TABLE(PERM_ID_TEMP VARCHAR(50));
  3.     INSERT INTO SESSION.TEMP_TABLE(PERM_ID_TEMP) VALUES(SELECT VARCHAR(elem, 50) FROM TABLE ( teimt00.elements(PERMISSIONS) ) AS t(elem));
  4.    DECLARE c1 CURSOR FOR 
  5.   SELECT PERM_ID_TEMP from SESSION.TEMP_TABLE;
I am getting following error
Expand|Select|Wrap|Line Numbers
  1. DB21034E  The command was processed as an SQL statement because it was not a 
  2. valid Command Line Processor command.  During SQL processing it returned:
  3. SQL0104N  An unexpected token "<cursor declaration>" was found following "".  
  4. Expected tokens may include:  "<SQL statement>".  LINE NUMBER=33.  
  5. SQLSTATE=4260
Pleae suggest what is the reason for this error.
Sep 18 '09 #1
2 4855
vijay2082
112 100+
Hi,

Looks like a syntax error rather than any issue with the temporary table. Went fine in my case with the piece of code. Probably you
need to check at the specific location for the error and before the line for any missing clause etc (Expected tokens may include: "<SQL statement>". LINE NUMBER=33. )

D:\vijay>db2 connect to mydb user db2admin
Enter current password for db2admin:

Database Connection Information

Database server = DB2/NT 8.2.9
SQL authorization ID = DB2ADMIN
Local database alias = mydb


D:\vijay>db2 "DECLARE GLOBAL TEMPORARY TABLE SESSION.TEMP_TABLE(PERM_ID_TEMP VARCHAR(50))"
DB20000I The SQL command completed successfully.

D:\vijay>db2 "insert into SESSION.TEMP_TABLE(PERM_ID_TEMP) VALUES (select 'long character value for the column' from sysibm.sysdummy1)"
DB20000I The SQL command completed successfully.

D:\vijay>db2 "declare c1 cursor for select PERM_ID_TEMP from SESSION.TEMP_TABLE"
DB20000I The SQL command completed successfully.

D:\vijay>db2 +c select * from SESSION.TEMP_TABLE

PERM_ID_TEMP
--------------------------------------------------
long character value for the column


*************

SQL0104N An unexpected token "<token>" was found following
"<text>". Expected tokens may include:
"<token-list>".

Explanation:

A syntax error in the SQL statement or the input command string
for the SYSPROC.ADMIN_CMD procedure was detected at the specified
token following the text "<text>". The "<text>" field indicates
the 20 characters of the SQL statement or the input command
string for the SYSPROC.ADMIN_CMD procedure that preceded the
token that is not valid.

As an aid, a partial list of valid tokens is provided in the
SQLERRM field of the SQLCA as "<token-list>". This list assumes
the statement is correct to that point.

The statement cannot be processed.

User Response:

Examine and correct the statement in the area of the specified
token.

sqlcode : -104

sqlstate : 42601

***********

Cheers, Vijay
Sep 18 '09 #2
gjain12
19
I checked the statement but couldn't find any error but still m getting same error in the line
[code]DECLARE C1 CURSOR FOR
SELECT PERM_ID_TEMP
from SESSION.TEMP_TABLE;[\code]
Sep 22 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Michael Trosen | last post by:
Hi Everyone, I hope someone can help, I'm pretty new to pro*c programming. I have the following application setup: a pro*c program calls a stored procedure and recieves a cursor back: the...
3
by: aaj | last post by:
SQL SERVER 2000 Hi all This is my first attempt at writing a stored procedure. I have managed to get it working but its unlikely to be the best way of handling the problem. While writing it I...
15
by: Philip Mette | last post by:
I am begginner at best so I hope someone that is better can help. I have a stored procedure that updates a view that I wrote using 2 cursors.(Kind of a Inner Loop) I wrote it this way Because I...
3
by: N. Shamsundar | last post by:
A stored procedure (listed below) that loads fine on Windows XP with DB2 V8.1.4 Express fails to load on Linux DB2 Workgroup server V8.1, with the following message: > sh-2.05a$ db2 -td@ -f...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
12
by: Lucky | last post by:
Hi guys! i want to create one cursor in the t-sql. the problem is i want to use stored procedure instead of select command in cursor. can anyone tell me how can i use stored procedure's o/p to...
3
by: leesquare | last post by:
Hello, I need some help getting output values from my stored procedures when using adodbapi. There's an example testVariableReturningStoredProcedure in adodbapitest.py, and that works for my...
2
by: Jeganath | last post by:
Hi, I have written a Stored Procedure. I'm getting the error as below. Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32). Can any one give me a solution...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.