Unix Technical Forum

Cursor

This is a discussion on Cursor within the DB2 forums, part of the Database Server Software category; --> hi, While creating following UDF I am getting an error (I have removed the some statements). CREATE FUNCTION CONVERTROW(VAR1 ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 04:10 AM
Suresh D
 
Posts: n/a
Default Cursor

hi,

While creating following UDF I am getting an error (I have removed the
some statements).

CREATE FUNCTION CONVERTROW(VAR1 VARCHAR(50))
RETURNS VARCHAR(205)
DETERMINISTIC NO EXTERNAL ACTION
CONTAINS SQL
LANGUAGE SQL
BEGIN ATOMIC

DECLARE C1 CURSOR FOR
SELECT COL FROM SURI;

RETURN RESULT;
END
@


error messages is :
SQL0104N An unexpected token "FOR" was found following "C DECLARE C1
CURSOR". Expected tokens may include: "<SQL_variable_declarations>".
LINE
NUMBER=8. SQLSTATE=42601

thanks in advance,
Suresh D
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 04:10 AM
Serge Rielau
 
Posts: n/a
Default Re: Cursor

Suresh D wrote:
> hi,
>
> While creating following UDF I am getting an error (I have removed the
> some statements).
>
> CREATE FUNCTION CONVERTROW(VAR1 VARCHAR(50))
> RETURNS VARCHAR(205)
> DETERMINISTIC NO EXTERNAL ACTION
> CONTAINS SQL
> LANGUAGE SQL
> BEGIN ATOMIC
>
> DECLARE C1 CURSOR FOR
> SELECT COL FROM SURI;
>
> RETURN RESULT;
> END
> @
>
>
> error messages is :
> SQL0104N An unexpected token "FOR" was found following "C DECLARE C1
> CURSOR". Expected tokens may include: "<SQL_variable_declarations>".
> LINE
> NUMBER=8. SQLSTATE=42601
>
> thanks in advance,
> Suresh D

inline SQL PL does not support cursors (see the compound statement
(dynamic) definition in teh SQL Ref.
Instead use a FOR loop (which I find much nicer, btw).

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 04:10 AM
Shyam Peri
 
Posts: n/a
Default Re: Cursor

Looks like the cursor declaration in functions is not supported(
correct me if I am wrong). Instead u can update your function by the
following statements or u can use procedure to perform similar task.

CREATE FUNCTION CONVERTROW(VAR1 VARCHAR(50))
RETURNS VARCHAR(205)
DETERMINISTIC NO EXTERNAL ACTION
CONTAINS SQL
LANGUAGE SQL
BEGIN ATOMIC
FOR row as SELECT COL FROM SURI;
DO
END FOR;
RETURN RESULT;
END @

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:18 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com