dbTalk Databases Forums  

Execution plans for cursor FOR loops

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss Execution plans for cursor FOR loops in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Serge Rielau
 
Posts: n/a

Default Re: Execution plans for cursor FOR loops - 07-06-2009 , 05:54 AM






jefftyzzer wrote:
Quote:
On Jul 2, 11:44 pm, Serge Rielau <srie... (AT) ca (DOT) ibm.com> wrote:
DECLARE txt VARCHAR(32000);
SET txt = 'BEING ATOMIC '
|| 'FOR L_REPS AS '
|| ' SELECT X, Y FROM Z '
|| ' DO '
|| ' UPDATE A SET C = N WHERE A.C = L_REPS.X; '
|| ' UPDATE B SET C = N WHERE B.C = L_REPS.X; '
|| ' UPDATE C SET C = N WHERE C.C = L_REPS.X; '
|| ' UPDATE Z SET C = L_REPS.Y WHERE Z.C = L_REPS.X; '
|| ' END FOR; END'

EXECUTE IMMEDIATE txt;
If you EXPLAIN PLAN on this beats you should see a join between the FOR
LOOP query and either a FILTER or a UNION operator where each arm is an
UPDATE.

Incredible. I had no idea that you could put (procedural) control
structures in dynamic SQL like that. I'll let you know how it pans
out.
Hehe, that was my internship project thirteen years ago...
"inline SQL PL"

--
Serge Rielau
SQL Architect DB2 for LUW
IBM Toronto Lab

Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.