If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Simple function with Update and Insert

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-21-11, 10:34
ai_zaviour ai_zaviour is offline
Registered User
 
Join Date: Sep 2011
Posts: 53
Question Simple function with Update and Insert

Hi all

I need a DB2 function to Update a table and Insert some records to another table

Then return 1

No IF statements..

This will help me to further develop this function in future..

I have done this..

CREATE FUNCTION "DB2ADMIN"."DTV_SCHEDULE_PUBLISH1" ( "PERIOD" INTEGER )
RETURNS INTEGER
LANGUAGE SQL
MODIFIES SQL DATA
NO EXTERNAL ACTION
DETERMINISTIC

BEGIN ATOMIC
UPDATE DB2ADMIN.PROGRAMME_SCHEDULE_HDR_TEST
SET PUBLISHED_STATUS = 1 , INIT_PUBLISHED_DATE = CURRENT_DATE ,LAST_UPDATE_DATE = CURRENT_DATE
WHERE PERIOD = TO_CHAR (SCHEDULE_DATE, 'YYYYMM');

INSERT INTO DTV_SCHEDULE_PUBLISH_TEST (CHANNEL_ID,SCHEDULE_PERIOD,INIT_PUB_DATE,LAST_PUB _DATE,ACTIVE_STATUS,USER_ENTERED,DATE_ENTERED)
SELECT P.CHANNEL_ID,PERIOD,CURRENT_DATE,CURRENT_DATE,'1', CURRENT_USER,CURRENT_DATE FROM PROGRAMME_SCHEDULE_HDR_TEST P WHERE PERIOD = TO_CHAR (SCHEDULE_DATE, 'YYYYMM');

RETURN 1;

END;

But getting a error of..

DB2 Database Error: ERROR [42613] [IBM][DB2/NT] SQL0628N Multiple or conflicting keywords involving the "MODIFIES SQL DATA" clause are present. LINE NUMBER=18. SQLSTATE=42613

I was taken the help of this link [Example 4]

DB2 Database for Linux, UNIX, and Windows

Plz help me..
Reply With Quote
  #2 (permalink)  
Old 09-21-11, 10:50
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
The manual states that MODIFIES SQL DATA can only be used for a function that returns a TABLE.

Andy
Reply With Quote
  #3 (permalink)  
Old 09-21-11, 10:57
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by ai_zaviour View Post
I was taken the help of this link [Example 4]

DB2 Database for Linux, UNIX, and Windows
Make sure you reading the correct InfoCenter webpage for the release of DB2 you have. The link you provided is for V9 (which is 9.1). There are separate InfoCenters for V9R5 and V9R7.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #4 (permalink)  
Old 09-21-11, 10:58
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Have a look at a recent discussion :

DB2 Function Return
DB2 Function Return

HTH

Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On