
Signature
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Hi Serge,
Thanks for the tips.
I tried to add EXECUTE IMMEDIATE ALTER TABLE DB.A ACTIVATE NOT
LOGGED INITIALLY
in my procedure. But it failed to create. Am I not putting it in the
right place ? Or is my syntax incorrect ?
Can I activate not logged for more than 1 table at a time ?
CREATE PROCEDURE DB.PWC (V_ID CHAR(6), OUT RETURN_VAL INT)
LANGUAGE SQL
BEGIN
EXECUTE IMMEDIATE ALTER TABLE DB.A ACTIVATE NOT LOGGED INITIALLY
DECLARE..
DECLARE..
INSERT INTO TABLE A..
UPDATE TABLE A..
.
.
INSERT INTO TABLE B..
UPDATE TABLE B..
.
.
INSERT INTO TABLE C..
UPDATE TABLE C..
END
Serge Rielau - 25 Jun 2005 14:31 GMT
> Hi Serge,
> Thanks for the tips.
[quoted text clipped - 26 lines]
>
> END
Try
EXECUTE IMMEDIATE 'ALTER TABLE ...';
If that does not work:
SET txt = 'ALTER TABLE ...';
EXECUTE IMMEDIATE txt;
will work for sure.. I do it rarely myself.
Cheers
Serge

Signature
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Matt Emmerton - 25 Jun 2005 14:33 GMT
> Hi Serge,
> Thanks for the tips.
> I tried to add EXECUTE IMMEDIATE ALTER TABLE DB.A ACTIVATE NOT
> LOGGED INITIALLY
> in my procedure. But it failed to create. Am I not putting it in the
> right place ? Or is my syntax incorrect ?
It needs to come after the DECLARE statements but before your insert/update
queries.
--
Matt Emmerton
Hi, Serge
Here is an example of our code. Basically, we manually do the
looping
and set our variables and use those variables to INSERT/UPDATE into the
underlying tables. I'm interested in using CURSOR WITH HOLD. But I
guess
I'm not very experienced. I tried to use EXECUTE IMMEDIATE. It built
and ran, but I got some other errors saying that the table is not
accessible (can't insert/update). It was very strange. I think the
safest way is to
try to commit every n rows, so that the transaction log is not filled
up.
I'm looping through around 1 million rows from TABLE1 into variables,
and
use them to populate 3 tables accordingly. Maybe my code is not very
efficient. Do you have any advice on how to work around this
transaction log ? We do not want to increase our Log Size because this
is a migration script. It will be run only once in a blue moon.
Thanks,
CREATE PROCEDURE db2.pkc (v_in_proc_id CHAR(6),
OUT RETURN_VAL INTEGER )
LANGUAGE SQL
BEGIN
DECLARE ...;
DECLARE ...;
DECLARE ...;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
BEGIN
INSERT INTO TABLE (..) VALUES (..);
END;
FOR DUMMY_LOOP AS SELECT
COL1,
COL2,
COL3
FROM TABLE1
DO
SET v_1 = COL1;
SET v_2 = COL2;
SET v_3 = COL3;
BEGIN
BEGIN
DECLARE continue HANDLER FOR dup_key
BEGIN
UPDATE TABLE_A
SET COL_A = ..
END;
INSERT INTO TABLE_A VALUES ( .. );
END ;
BEGIN
DECLARE continue HANDLER FOR dup_key
BEGIN
UPDATE TABLE_B
SET COL_B = ..
END;
INSERT INTO TABLE_B VALUES ( .. );
.
.
.
END
> > Hi Ian,
> > Thank you for the reply. I have been trying to figure out
[quoted text clipped - 16 lines]
> Cheers
> Serge
Serge Rielau - 28 Jun 2005 12:38 GMT
> Hi, Serge
> Here is an example of our code. Basically, we manually do the
[quoted text clipped - 80 lines]
>
> END
This isn't what I thought you did... I thought you picked teh tabel name
from the FOR loop itself....
First of: Good going with the nested handlers! Nice to see someone use
neste compounds as they are meant to be used.
You can simply the code quite a bit by using MERGE.
BEGIN
FOR THIS AS dummy CURSOR WITH HOLD
FOR SELECT PK1, COL1, PK2, COL2, PK3, COL3 FROM TABLE1
DO
MERGE INTO TABLEA AS T
USING (VALUES(THIS.PK1, THIS.COL1)) AS S(PK, C1)
ON T.PK = S.PK
WHEN MATCHED THEN UPDATE SET T.C1 = S.C1;
WHEN NOT MATCHED THEN INSERT VALUES (S.PK, S.C1);
MERGE .... ;
COMMIT;
END FOR;
END
Cheers
Serge

Signature
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab