Hello Martin,

can you try to execute the SELECT that triggers the function with a FOR REUSE 
added? Does it 
change anything? 

Alexander Schröder
MaxDB & liveCache
SAP AG

Sitz der Gesellschaft/Registered Office: Walldorf, Germany
Vorstand/SAP Executive Board: Henning Kagermann (Sprecher/CEO), Shai Agassi, 
Léo Apotheker, Werner Brandt, Claus Heinrich, Gerhard Oswald, Peter Zencke
Vorsitzender des Aufsichtsrats/Chairperson of the SAP Supervisory Board: Hasso 
Plattner
Registergericht/Commercial Register Mannheim No HRB 350269

Diese E-Mail kann Betriebs- oder Geschäftsgeheimnisse oder sonstige 
vertrauliche Informationen enthalten. Sollten Sie diese E-Mail irrtümlich 
erhalten haben, ist Ihnen eine Kenntnisnahme des Inhalts, eine Vervielfältigung 
oder Weitergabe der E-Mail ausdrücklich untersagt.
Bitte benachrichtigen Sie uns und vernichten Sie die empfangene E-Mail. Vielen 
Dank.

This e-mail may contain trade secrets or privileged, undisclosed, or otherwise 
confidential information. If you have received this e-mail in error, you are 
hereby notified that any review, copying, or distribution of it is strictly 
prohibited. Please inform us immediately and destroy the original transmittal. 
Thank you for your cooperation.   

-----Original Message-----
From: Martin Cordova [mailto:[EMAIL PROTECTED] 
Sent: Dienstag, 20. März 2007 16:14
To: maxdb
Subject: UPDATE T SET X = X + 1 increments by 2 when executed inside a function

Hi, I am new to MAXDB functions, today I tried to create one that:

1) updates a table and increments a certain column value
2) returns a string that incorporates that value, combined with
another piece of data

The thing is that I execute a simple update to increment the value by
1, but it get incremented by 2!!!

I am missing something, any help will be appreciated.

I am using MaxDB 7.6.0.34 on WinXP SP1.

The code:

CREATE FUNCTION XXX.getNumCorrespE (dependencia_id INTEGER) RETURNS VARCHAR AS

    VAR ano INTEGER; cnum INTEGER; retval VARCHAR(20);

TRY

  SET ano = 0;
  SET cnum = 0;

update XXX.dependencia set num_corresp_e = num_corresp_e + 1
where dependencia_id = :dependencia_id;

DECLARE functionresult CURSOR FOR

select
    ano,
    num_corresp_e cnum
from XXX.dependencia
where
dependencia_id = :dependencia_id;

WHILE $rc = 0 DO BEGIN
      FETCH functionresult INTO :ano, :cnum;
    END;
CATCH
  IF $rc <> 100 THEN STOP ($rc, 'unexpected error');
CLOSE functionresult;

set retval = chr(ano) || '-' || LFILL(chr(cnum),'0',6);

RETURN retval;


Regards,
Martin Cordova
-- 
Dinamica - RADical J2EE framework
open source, easy and powerful
http://www.martincordova.com

-- 
MaxDB Discussion Mailing List
For list archives: http://lists.mysql.com/maxdb
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]


--
MaxDB Discussion Mailing List
For list archives: http://lists.mysql.com/maxdb
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to