Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
mysql openssl Question
mysql:it 's a db not a dbms how it 's possible?!
Does the binary log enabling affect the MySQL performances?
Strange behavior, Table Level Permission
FULLTEXT query format question
Preventing Duplicate Entries
Comparing and writing out BLOBS
Executing MySQL Commands From Within C Program
Can 't access mysql after kernel upgrade
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Downgrade Mysql from 4 to 3 23
MySQL Cluster Software
mysql test 4 1 fails with the gis test
ERROR 2002: Can 't connect to local MySQL server through socket
Getting Identity after INSERT
Update one field with more fields from another table
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
mysql have same function mthod as Oracle decode()
 
UPDATE T SET X = X + 1 increments by 2 when executed inside a function

UPDATE T SET X = X + 1 increments by 2 when executed inside a function

2007-03-20       - By Martin Cordova

 Back
Reply:     1     2     3     4  

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/maxdb?unsub=mysql@(protected)