sql - How do I execute a sequence of DB2 queries with a loop in the middle of them? -


i have been rolling around issue couple of days now. converting unix script uses sybase run in db2 instead , there loop in middle of it.

the script contains several temp tables , update statements reliant came before it... followed loop , few more temp tables, update statements, etc... before query @ end populates end result , exports spreadsheet.

the issue have can declare, insert, update, , select query blocks run @ same time. however, when try run @ once loop in middle, following error: " sql0104n unexpected token "end-of-statement" found following "ssion.min_assessment". expected tokens may include: "join ". line number=1. sqlstate=42601".

the blocks run fine when ran individually... need of blocks run can place them in unix script scheduled.

the structure looks this:

declare temp_table_a; insert temp_table_a (select ... <table> ...); declare temp_table_b; insert temp_table_b (select ... temp_table_a, <table> ...); update temp_table_b set <field> = (select <field> <table> ...); delete temp_table_b ...; declare temp_table_c; declare temp_table_d; begin atomic    v1        select ... temp_table_b           delete temp_table_c;        insert temp_table_c (select ...);        delete temp_table_b exists (select 1 temp_table_c);        update temp_table_d set <date_field> = temp_table_c.<date_field> exists (select 1 temp_table_b ...);        delete temp_table_c exists (select 1 temp_table_c ...);        insert temp_table_d select ... temp_table_c;    end for;  end declare temp_table_e; insert temp_table_e (select ... temp_table_d, <table> ...); update temp_table_e set <field> = (select <field> <table> ...); select ... temp_table_e; 

does have ideas can of query blocks run in sequence , include loop?

first, need put declare @ beginning. then, in order control execution use handler , variable, or fetching each row in for.

http://www.sqlpl-guide.com/declare


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -