Personal tools
You are here: Home DB2 How To's How to move data between tables with LOAD FROM CURSOR
Navigation
Log in


Forgot your password?
 
Document Actions

How to move data between tables with LOAD FROM CURSOR

using load from cursor to data movement

See the example below, how to use db2 load from cursor to data movement


Table EMP.TABLE_1 has 4 columns:

    COD INT

    NAME  CHAR(10)

    PROJECT INT

    HIRED DATE



Table EMP.TABLE_2 has 4 columns:
   

    COD INT

    NAME  CHAR(10)

    HIRED DATE

    PROJECT INT

   

Executing the following commands will load all the data from EMP.TABLE_1 into EMP.TABLE_2:

db2 declare cursor_x cursor for select cod, name, hired project from emp.table_1
db2 load from cursor_x of cursor insert into emp.table_2 nonrecoverable

After load, some tables can be in pending state, so apply the command below to generate a scrit to set all pending tables to normal state

db2 -x "select 'set integrity for ',substr(rtrim(tabschema)||'.'||rtrim(tabname),1,40),'immediate checked;' from \
syscat.tables where status = 'C' order by tabschema, tabname"


If EMP.TABLE_1 resides in a database different from the database EMP.TABLE_2 is in, the DATABASE, USER, and USING options of the DECLARE CURSOR command can be used to perform the load. For example, if EMP.TABLE_1 resides in database DB1, and the user ID and password for DB1 are user1 and pwd1 respectively, executing the following commands will load all the data from EMP.TABLE_1 into EMP.TABLE_2:

db2 declare cursor_x cursor database DB1 user user1 using pwd1 for select cod, name, hired project from emp.table_1     
db2 load from cursor_x of cursor insert into emp.table_2 nonrecoverable
db2 -x "select 'set integrity for ',substr(rtrim(tabschema)||'.'||rtrim(tabname),1,40),'immediate checked;' from \
syscat.tables where status = 'C' order by tabschema, tabname"
Security Awareness
Would you like your company to implement gamification into your security awareness program?





Polls