建立测试表
create table test_num_tab(a varchar(30));
insert into test_num_tab
values ('12432');
insert into test_num_tab
values ('32544');
insert into test_num_tab
values ('a3r3');
insert into test_num_tab
values ('33332d');
drop table test_performace_error_log;
create multiset table test_performace_error_log(a varchar(30),datetime varchar(100));
drop table test_performace_log;
create multiset table test_performace_log(a varchar(30),datetime varchar(100));
创建存储过程
replace PROCEDURE test_num()
BEGIN
DECLARE num INTEGER;
DECLARE var VARCHAR(30);
定义游标
declare loopvar cursor
for
select a
from dwzhangjh.test_num_tab;
定义游标退出处理器
DECLARE EXIT HANDLER
FOR NOT FOUND
BEGIN
set var='';
END ;
定义错误处理器
DECLARE CONTINUE HANDLER
FOR SQLEXCEPTION
BEGIN
insert into test_performace_error_log
values (var,date || time);
end ;
打开游标
OPEN loopvar;
Label1:
Loop
FETCH loopvar INTO var;
set num=var;
insert into test_performace_log values(num,date || time);
END LOOP Label1;
CLOSE loopvar;
end;
测试函数
delete from test_performace_error_log all;
delete from test_performace_log all;
CALL test_num();
select * from test_performace_error_log;
阅读(2570) | 评论(0) | 转发(0) |