PROCEDUREoracle_to_accessIS
connection_idEXEC_SQL.ConnType;
action_cursorEXEC_SQL.CursType;
ignorePLS_INTEGER;
t_namestudent.name%type;
t_agestudent.age%type;
cursortemp_cursorisselect*fromstudent;
BEGIN
connection_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)');
loop
fetchtemp_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);
EXCEPTION
WHENEXEC_SQL.PACKAGE_ERRORTHEN
IFEXEC_SQL.LAST_ERROR_CODE(connection_id)!=0THEN
message('数据导出至ACCESS失败:'
||TO_CHAR(EXEC_SQL.LAST_ERROR_CODE(connection_id))||'
:'||EXEC_SQL.LAST_ERROR_MESG(connection_id));
ENDIF;
IFEXEC_SQL.IS_CONNECTED(connection_id)THEN
IFEXEC_SQL.IS_OPEN(connection_id,action_cursor)THEN
EXEC_SQL.CLOSE_CURSOR(connection_id,action_cursor);
ENDIF;
EXEC_SQL.CLOSE_CONNECTION(connection_id);
ENDIF;
END;
下面为从Access导出到Oracles的procedure:
PROCEDUREAccess_to_oracleIS
connection_idEXEC_SQL.ConnType;
action_cursorEXEC_SQL.CursType;
ignorePLS_INTEGER;
t_namestudent.name%type;
t_agestudent.age%type;
BEGIN
connection_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)
loop
exec_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);
EXCEPTION
WHENEXEC_SQL.PACKAGE_ERRORTHEN
IFEXEC_SQL.LAST_ERROR_CODE(connection_id)!=0THEN
message('数据导入至ORACLE失败:'
||TO_CHAR(EXEC_SQL.LAST_ERROR_CODE(connection_id))||'
:'||EXEC_SQL.LAST_ERROR_MESG(connection_id));
ENDIF;
IFEXEC_SQL.IS_CONNECTED(connection_id)THEN
IFEXEC_SQL.IS_OPEN(connection_id,action_cursor)THEN
EXEC_SQL.CLOSE_CURSOR(connection_id,action_cursor);
ENDIF;
EXEC_SQL.CLOSE_CONNECTION(connection_id);
ENDIF;
END; |