oracle存储过程写法。

时间:2023-03-09 01:25:42
oracle存储过程写法。

create or replace procedure testwzm(v_gdjdm in varchar2) is
v_id varchar2(10);
v_xlname varchar2(100);
v_count number(4);
begin
v_count:=0;

//定义游标
declare cursor line_cur is
select line_code,line_name from ods_yx.line where gdjdm=v_gdjdm and rownum<10;

//自定义内部异常错误。(如果是oracle内部已经定义的错误,就不能再次定义了。)

zfcd_error exception;
pragma exception_init(zfcd_error,-06502);

begin
for my_data in line_cur loop

//处理异常模块需要加begin end;
begin
v_id:=my_data.line_code;

//处理ora06502异常模块。
exception when zfcd_error then
v_id:=substr(my_data.line_code, 1, 5);
dbms_output.put_line('出现异常啦'||v_id);
end;
v_xlname:=my_data.line_name;
v_count:=v_count+1;
dbms_output.put_line(v_id||v_xlname);
if v_count=6 then
goto line6 //跳出该循环到line6 中进行数据处理。
elsif v_count=9 then
begin
select line_name into v_xlname from ods_yx.line where line_code=v_id;
dbms_output.put_line('哈哈哈'||v_xlname);
exception when no_data_found then
dbms_output.put_line('no_data_found');
end;
end if;

end loop;
end;

定义外部goto处理内容。
<<line6>>
dbms_output.put_line('我是线路6666');
end testwzm;