473,385 Members | 2,013 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,385 software developers and data experts.

FUNCTION: MODIFIES SQL DATA

I am getting SQL0628N when I run function with INSERT and MODIFIES SQL
DATA

Version:

DB2 v8.1.7.445 Fixpack 7.

Create function test1( a int, b int)
returns integer
language sql
modifies sql data
begin atomic
insert into test1 values(1,2);
return 1;
end@

Am I missing something?

Nov 12 '05 #1
2 7770
Why are you writing this as a function instead of a stored procedure? A
UDF typically takes inputs, performs some calculation and returns a
result based on those inputs.

A procedure is designed to take series of inputs, do some actions based
on those inputs (select & return results, do inserts, etc) and possibly
return some values through output parameters based on the actions it
performed. Even then, it's designed for BATCHES of SQL statements -- a
simple insert statement like what you have below will actually perform
SLOWER if you do it inside a procedure instead of directly in your
application -- it takes just and long to send a single call statement
from your client to DB2 as a simple insert statement, and then you add
the processing of the insert itself.

Anyway to the problem at hand: the documentation notes that I found
state that "MODIFIES SQL DATA" can only be specified for SQL table
functions, not SQL scalar functions.

=======================================
.-EXTERNAL ACTION----. .-READS SQL DATA---------.
--*--+--------------------+--*--+------------------------+-----> '-NO EXTERNAL ACTION-' +-CONTAINS SQL-----------+
| (1) |
'- MODIFIES SQL DATA ---'

(1) Valid only if RETURNS specifies a table (TABLE column-list)
=======================================

You cannot write a scalar function that modifies SQL.

db*****@yahoo.com wrote: I am getting SQL0628N when I run function with INSERT and MODIFIES SQL
DATA

Version:

DB2 v8.1.7.445 Fixpack 7.

Create function test1( a int, b int)
returns integer
language sql
modifies sql data
begin atomic
insert into test1 values(1,2);
return 1;
end@

Am I missing something?

Nov 12 '05 #2
db*****@yahoo.com wrote:
I am getting SQL0628N when I run function with INSERT and MODIFIES SQL
DATA

Version:

DB2 v8.1.7.445 Fixpack 7.

Create function test1( a int, b int)
returns integer
language sql
modifies sql data
begin atomic
insert into test1 values(1,2);
return 1;
end@

Am I missing something?

Only SQL Table functions are allowed to be MODIFIES SQL DATA.
(see syntax diagram)
The reason is that modifying SQL data inside of a WHERE clause or SELECT
list get srather bizarre semantically.
Note that the usage of SQL Table functions which modify SQL dat ais also
limited. Only in to level queries, and if there is a join they must
correlate to all other joined tables to enforce a clear ordering.

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3

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

Similar topics

4
by: amoL | last post by:
when specifying modifies sql data option ... getting following error.. SQL0104N An unexpected token "MODIFIES SQL DATA" was found following "". Expected tokens may include: "READS SQL DATA". ...
11
by: thborges | last post by:
I tried create this function with DB2 Express and received the error message: -104 Thiago.FUNCTION1: 9: SQL0104N An inexpected token "TABLE SESSION.TESTE(C1 INTEGER) ON CO" was found...
2
by: 4.spam | last post by:
Hello. v8.2. Is it possible? Example: --------------- create function t(v varchar(1)) modifies sql data returns table(c varchar(1))
16
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the...
0
by: maliks | last post by:
Hi all, I am very new to the DB2 environment. I am facing a problem in deploying a function on the database. Function is calling a procedure which contains the update statement in it. The...
14
by: subramanian100in | last post by:
In the following link, http://www.c-faq.com/malloc/retaggr.html The following ANSWER is given to a question(comp.lang.c FAQ list · Question 7.5a) : Whenever a function returns a pointer, make...
6
by: subramanian100in | last post by:
why can't a static member function be declared as const ? We can declare a non-static member function as const, to indicate that it does not modify the non-mutable data members. In the same way, is...
0
by: davidsavill | last post by:
Hi All, I am migrating a database from Firebird/Interbase to DB2 and have having issues with the stored procedures/functions. I have a number of functions that loop over a FOR loop, each pass...
1
by: pkaival | last post by:
i want to call procedure from function In DB2 i create function but it is giving an error like...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.