Unix Technical Forum

FUNCTION: MODIFIES SQL DATA

This is a discussion on FUNCTION: MODIFIES SQL DATA within the DB2 forums, part of the Database Server Software category; --> I am getting SQL0628N when I run function with INSERT and MODIFIES SQL DATA Version: DB2 v8.1.7.445 Fixpack 7. ...


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 03:07 AM
db2sysc@yahoo.com
 
Posts: n/a
Default 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?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 03:07 AM
amurchis
 
Posts: n/a
Default Re: FUNCTION: MODIFIES SQL DATA

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.



db2sysc@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?
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 03:07 AM
Serge Rielau
 
Posts: n/a
Default Re: FUNCTION: MODIFIES SQL DATA

db2sysc@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
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 02:11 AM.


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