PROCEDUREoracle_to_accessISconnection_idEXEC_SQL.ConnType;action_cursorEXEC_SQL.CursType;ignorePLS_INTEGER;t_namestudent.name%type;t_agestudent.age%type;cursortemp_cursorisselect*fromstudent;BEGINconnection_id:=EXEC_SQL.OPEN_CONNECTION('user/user@odbc:test');action_cursor:=EXEC_SQL.OPEN_CURSOR(connection_id);EXEC_SQL.PARSE(connection_id,action_cursor,'delete*fromstudent');ignore:=EXEC_SQL.EXECUTE(connection_id,action_cursor);EXEC_SQL.CLOSE_CURSOR(connection_id,action_cursor);opentemp_cursor;eXPort_count:=0;action_cursor:=EXEC_SQL.OPEN_CURSOR(connection_id);EXEC_SQL.PARSE(connection_id,action_cursor,'INSERTINTOstudent(name,age)values(:1,:2)');loopfetchtemp_cursorintot_name,t_age;exitwhentemp_cursor%notfound;EXEC_SQL.BIND_VARIABLE(connection_id,action_cursor,':1',t_name);EXEC_SQL.BIND_VARIABLE(connection_id,action_cursor,':2',t_age);ignore:=EXEC_SQL.EXECUTE(connection_id,action_cursor);endloop;closetemp_cursor;EXEC_SQL.PARSE(connection_id,action_cursor,'commit');ignore:=EXEC_SQL.EXECUTE(connection_id,action_cursor);EXEC_SQL.CLOSE_CURSOR(connection_id,action_cursor);EXEC_SQL.CLOSE_CONNECTION(connection_id);EXCEPTIONWHENEXEC_SQL.PACKAGE_ERRORTHENIFEXEC_SQL.LAST_ERROR_CODE(connection_id)!=0THENmessage('数据导出至ACCESS失败:'TO_CHAR(EXEC_SQL.LAST_ERROR_CODE(connection_id))':'EXEC_SQL.LAST_ERROR_MESG(connection_id));ENDIF;IFEXEC_SQL.IS_CONNECTED(connection_id)THENIFEXEC_SQL.IS_OPEN(connection_id,action_cursor)THENEXEC_SQL.CLOSE_CURSOR(connection_id,action_cursor);ENDIF;EXEC_SQL.CLOSE_CONNECTION(connection_id);ENDIF;END;下面为从Access导出到Oracles的procedure:PROCEDUREAccess_to_oracleISconnection_idEXEC_SQL.ConnType;action_cursorEXEC_SQL.CursType;ignorePLS_INTEGER;t_namestudent.name%type;t_agestudent.age%type;BEGINconnection_id:=EXEC_SQL.OPEN_CONNECTION('user/user@odbc:test');action_cursor:=EXEC_SQL.OPEN_CURSOR(connection_id);deletefromstudent;EXEC_SQL.PARSE(connection_id,action_cursor,'selectname,agefromstudent');ignore:=EXEC_SQL.EXECUTE(connection_id,action_cursor);exec_sql.define_column(connection_id,action_cursor,1,t_name,10);exec_sql.define_column(connection_id,action_cursor,2,t_age);ignore:=EXEC_SQL.EXECUTE(connection_id,action_cursor);while(exec_sql.fetch_rows(connection_id,action_cursor)>0)loopexec_sql.column_value(connection_id,action_cursor,1,t_name);exec_sql.column_value(connection_id,action_cursor,2,t_age);insertintotest(name,age)values(t_name,t_age);endloop;commit;EXEC_SQL.CLOSE_CURSOR(connection_id,action_cursor);EXEC_SQL.CLOSE_CONNECTION(connection_id);EXCEPTIONWHENEXEC_SQL.PACKAGE_ERRORTHENIFEXEC_SQL.LAST_ERROR_CODE(connection_id)!=0THENmessage('数据导入至ORACLE失败:'TO_CHAR(EXEC_SQL.LAST_ERROR_CODE(connection_id))':'EXEC_SQL.LAST_ERROR_MESG(connection_id));ENDIF;IFEXEC_SQL.IS_CONNECTED(connection_id)THENIFEXEC_SQL.IS_OPEN(connection_id,action_cursor)THENEXEC_SQL.CLOSE_CURSOR(connection_id,action_cursor);ENDIF;EXEC_SQL.CLOSE_CONNECTION(connection_id);ENDIF;END; |