Hi,
i need to create stored procedure with four arguments
IN T1 TIMESTAMP,
IN T2 TIMESTAMP,
IN COEFFICIENT INTEGER,
OUT ROWS_AFFECTED
This procedure should read rows from table TAB1 and mark rows with date between T1 and T2 as invalid (by setting STATE flag to 0, for example), but it also shoud create new rows with some old values and with the new value -COEFFCIENT and return numbr of processed rows.
Something like this:
Code:
CREATE PROCEDURE SP1 (args...)
BEGIN
? CREATE CURSOR c1 FOR SELECT ID, VAL1, VAL2, Tx FROM TAB1 WHERE (T1 < Tx AND Tx < T2);
OPEN c1;
? ROWS_AFFECTED = c1.NUMEBER_OF_ROWS in the cursor
? WHILE READ FROM CURSOR, FETCH or something like this---
? UPDATE TAB1 SET STATE = 0 WHERE ID = c1.ID;
? INSERT INTO TAB1 (VAL1, VAL2, COEFF, Tx) VALUES (c1.VAL1, c1.VAL2, COEFF, c1.Tx);
CLOSE c1;
END;
But there is a lot of things I don't know how to write. Is it posible to create cursor for select that updates data? How get number of affected rows, what is the syntax and so on...
Can somebody help me, please?
DB2 v9.5.0.808 (Express), OS Win 2003 Server
Thanks a lot.