在Procedures中执行对应的脚本,可以实现数据导入的功能,具体的脚本代码见下:
create or replace procedure p_update_data(vi_month number)
as
v_month number;
v_count number :=0;
v_errcode int;
v_errmsg varchar2(200);
v_table varchar2(30);
ex_errmonth exception;
cursor c_table is
select table_name
from user_tables
where table_name like 'TAB_%';
begin
if length(vi_month)<> 6 then
raise ex_errmonth;
end if;
v_month := vi_month;
open c_table;
loop
fetch c_table into v_table;
exit when c_table%notfound;
select count(1)
into v_count
from cols
where table_name = v_table
and column_name = upper('month_id');
if v_count = 0 then
continue;
end if;
dbms_output.put_line('正在更新表数据:'||v_table||'...');
begin
execute immediate 'alter table '||v_table||' nologging';
execute immediate 'alter table '||v_table||' enable row movement';
execute immediate 'update '||v_table||' set month_id = '||v_month;
commit;
dbms_output.put_line('成功更新表数据:'||v_table||'...');
exception
when others then
v_errcode := sqlcode;
v_errmsg := substr(sqlerrm,1,200);
dbms_output.put_line('更新表数据失败:'||v_table||'---ORA:'||v_errcode||'-'||v_errmsg);
end;
end loop;
exception
when ex_errmonth then
dbms_output.put_line('请输入正确的日期格式');
when others then
rollback;
end p_update_data;
/