我有将值从一个表传递到另一个表的过程。
create table t_num(num number(10,2));
create table t_str(str varchar2(10));
insert into t_str (str) values('23');
insert into t_str (str) values('2 3');
insert into t_str (str) values('2 3,3 2');
insert into t_str (str) values('2 3,3 223');
commit;
create or replace procedure put_to_t_num
as
type t_num_t is table of t_num%rowtype index by binary_integer;
tn t_num_t;
n binary_integer := 0;
begin
delete from t_num;
--tn := t_num_t();
for rec in ( select * from t_str )
loop
n := n + 1;
--tn.extend;
tn(n).num := to_number( regexp_replace( regexp_replace( rec.str, ',', '.'), ' ', '' ) );
end loop;
forall i in 1..n
insert into t_num (
num
) values (
tn(i).num
);
--commit;
end;弦
tn(n).num := to_number( regexp_replace( regexp_replace( rec.str, ',', '.'), ' ', '' ) );可能引发异常VALUE_ERROR。
但是我需要在这段代码中插入所有的值,例如,如果异常,则插入0而不是实际值,这些值不进行转换(类似于在其他语言中尝试捕获)。
我如何在我的代码中做到这一点?
谢谢!
发布于 2015-03-26 20:36:58
而不是这一行:
tn(n).num := to_number( regexp_replace( regexp_replace( rec.str, ',', '.'), ' ', '' ) );使用此子块处理异常:
begin
tn(n).num := to_number( regexp_replace( regexp_replace( rec.str, ',', '.'), ' ', '' ) );
exception when VALUE_ERROR
then tn(n).num := 0;
end;https://stackoverflow.com/questions/29288146
复制相似问题