473,320 Members | 1,839 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,320 software developers and data experts.

UDF error

CREATE FUNCTION MYSCHEMA.FUNCTION1(SEQNAME VARCHAR(100))
RETURNS CHAR(100)
LANGUAGE SQL
MODIFIES SQL DATA

------------------------------------------------------------------------
-- SQL UDF (Scalar)
------------------------------------------------------------------------
F1: BEGIN ATOMIC

DECLARE varsql CHAR(100);

SELECT CONCAT('SEQ=',CHAR(NEXTVAL FOR MYSCHEMA.LOAD_ID)) INTO varsql
FROM SYSIBM.SYSDUMMY1;

INSERT INTO MYSCHEMA.VSQLTEMP VALUES (varsql);

RETURN varsql;
END
The above function gives me the following error. I am new to writing UDFs.
This query runs fine in a SP but not in a UDF. Kindly help me out with the
solution:
[IBM][CLI Driver][DB2/AIX64] SQL0104N An unexpected token "varsql" was
found following "HEMA.LOAD_ID))) INTO". Expected tokens may include:
"<space>". LINE NUMBER=16. SQLSTATE=42601

Jun 30 '06 #1
2 2042
Hello.

You aren't allowed to use SELECT INTO statement in UDF, and you aren't
allowed to create a scalar SQL UDF that MODIFIES SQL DATA.
Declare your UDF as RETURNS TABLE (table UDF, not scalar) and you can:
1. use
---
....
SET varsql =
(
SELECT CONCAT('SEQ=',CHAR(NEXTVAL FOR MYSCHEMA.LOAD_ID))
FROM SYSIBM.SYSDUMMY1;
);
....
RETURN values (varsql);
END@
---
2. or rewrite your body as single return clause(without 'begin atomic'
and 'end' clauses) like
---
return
select v
from new table
(
insert into vsqltemp (v)
values(CONCAT('SEQ=',CHAR(NEXTVAL FOR MYSCHEMA.LOAD_ID))
) t
---

Sincerely,
Mark B.
CREATE FUNCTION MYSCHEMA.FUNCTION1(SEQNAME VARCHAR(100))
RETURNS CHAR(100)
LANGUAGE SQL
MODIFIES SQL DATA

------------------------------------------------------------------------
-- SQL UDF (Scalar)
------------------------------------------------------------------------
F1: BEGIN ATOMIC

DECLARE varsql CHAR(100);

SELECT CONCAT('SEQ=',CHAR(NEXTVAL FOR MYSCHEMA.LOAD_ID)) INTO varsql
FROM SYSIBM.SYSDUMMY1;

INSERT INTO MYSCHEMA.VSQLTEMP VALUES (varsql);

RETURN varsql;
END
The above function gives me the following error. I am new to writing UDFs.
This query runs fine in a SP but not in a UDF. Kindly help me out with the
solution:
[IBM][CLI Driver][DB2/AIX64] SQL0104N An unexpected token "varsql" was
found following "HEMA.LOAD_ID))) INTO". Expected tokens may include:
"<space>". LINE NUMBER=16. SQLSTATE=42601


Jun 30 '06 #2
4.****@mail.ru wrote:
Hello.

You aren't allowed to use SELECT INTO statement in UDF, and you aren't
allowed to create a scalar SQL UDF that MODIFIES SQL DATA.
Declare your UDF as RETURNS TABLE (table UDF, not scalar) and you can:
1. use
---
...
SET varsql =
(
SELECT CONCAT('SEQ=',CHAR(NEXTVAL FOR MYSCHEMA.LOAD_ID))
FROM SYSIBM.SYSDUMMY1;
);
...
RETURN values (varsql);
END@
---
2. or rewrite your body as single return clause(without 'begin atomic'
and 'end' clauses) like
---
return
select v
from new table
(
insert into vsqltemp (v)
values(CONCAT('SEQ=',CHAR(NEXTVAL FOR MYSCHEMA.LOAD_ID))
) t
---

Sincerely,
Mark B.
CREATE FUNCTION MYSCHEMA.FUNCTION1(SEQNAME VARCHAR(100))
RETURNS CHAR(100)
LANGUAGE SQL
MODIFIES SQL DATA

------------------------------------------------------------------------
-- SQL UDF (Scalar)
------------------------------------------------------------------------
F1: BEGIN ATOMIC

DECLARE varsql CHAR(100);

SELECT CONCAT('SEQ=',CHAR(NEXTVAL FOR MYSCHEMA.LOAD_ID)) INTO varsql
FROM SYSIBM.SYSDUMMY1;

INSERT INTO MYSCHEMA.VSQLTEMP VALUES (varsql);

RETURN varsql;
END
The above function gives me the following error. I am new to writing UDFs.
This query runs fine in a SP but not in a UDF. Kindly help me out with the
solution:
[IBM][CLI Driver][DB2/AIX64] SQL0104N An unexpected token "varsql" was
found following "HEMA.LOAD_ID))) INTO". Expected tokens may include:
"<space>". LINE NUMBER=16. SQLSTATE=42601

SET varsql = CONCAT('SEQ=',CHAR(NEXTVAL FOR MYSCHEMA.LOAD_ID));
will do..
or even better
INSERT INTO MYSCHEMA.VSQLTEMP VALUES (CONCAT('SEQ=',CHAR(NEXTVAL FOR
MYSCHEMA.LOAD_ID)))
or eeeven better (no BEGIN ATOMIC):

CREATE FUNCTION ...
RETURNS TABLE(...)
MODIFIES SQLDATA
RETURN (SELECT varsqlcolinvsqltemp FROM NEW TABLE(INSERT INTO
MYSCHEMA.VSQLTEMP VALUES (CONCAT('SEQ=',CHAR(NEXTVAL FOR MYSCHEMA.LOAD_ID)))

And THAT should fly.

Cheers
Serge

PS:
http://www-128.ibm.com/developerwork...dm-0411rielau/

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Jun 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
7
by: HSXWillH | last post by:
I have a field in a database that contains last names. In some of those names, like O'Brien and O'Connor, there is a ' symbol. I am using combo boxes on a form to build a form filter and in...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.