WEB开发网
开发学院数据库Oracle 经验分享:Informix和Oracle存储过程的异同(一)... 阅读

经验分享:Informix和Oracle存储过程的异同(一)

 2008-10-25 12:57:39 来源:WEB开发网   
核心提示: 2)Oracle create or replace procedure pNormalParam(f1 number,f2 varchar2, v_Result out number)asbegininsert into t1 values(f1,f2);commit;v_Result

2)Oracle

create or replace procedure pNormalParam(f1 number,
f2 varchar2, v_Result out number)
as
begin
insert into t1 values(f1,f2);
commit;
v_Result = 0;
return;
exception
when others then
begin
rollback;
v_Result := -1;
end;
end pNormalParam;

需要注意的是,在oracle存储过程中,参数是不能加上size的,比如f1,在t1表中该字段是number(10,0),而这里只能写number,而不能写number(10,0)。

3、返回记录集

1)Informix

create procedure pReturnSet() returning integer, varchar(10);

define i integer;
define j varchar(10);
foreach
select f1, f2 into i, j from t1
return i, j with resume;
end foreach;
end procedure;

2)Oracle

create or replace package TestRefCursorPkg as type TestRefCursorTyp is ref cursor; procedure pReturnSet(RefCursor out TestRefCursorTyp); end TestRefCursorPkg;
create or replace package body TestRefCursorPkg as
procedure pReturnSet (RefCursor out TestRefCursorTyp)
as
localCursor TestRefCursorTyp;
begin
open localCursor for select f1, f2 from t1;
RefCursor := localCursor;
end pReturnSet;
end TestRefCursorPkg;
/

四、其他差异说明

1、错误捕捉

1)Informix

使用

on exception

end exception

2)Oracle

使用

exception

when others then

2、对游标的处理

1)Informix

create procedure pHasCursor()
define v_f1 integer;
begin
on exception
rollback work;
return;
end exception
begin work;
foreach curt1 with hold for
select f1 into v_f1 from t1 -- 注意这里没有分号
if (v_f1 = 1) then
update t1 set f2 = ’one’ where current of curt1;
elif (v_f1 = 2) then
update t1 set f2 = ’two’ where current of curt1;
else
update t1 set f2 = ’others’ where current of curt1;
end if;
end foreach;
commit work;
end;
end procedure;

2)Oracle

create or replace procedure pHasCursor
as
v_f1 number(10,0);
cursor curt1 is
select f1 from t1 for update;
begin
open curt1;
loop
fetch curt1 into v_f1;
exit when curt1%notfound;
if (v_f1 = 1) then
update t1 set f2 = ’one’ where current of curt1;
elsif (v_f1 = 2) then
update t1 set f2 = ’two’ where current of curt1;
else
update t1 set f2 = ’others’ where current of curt1;
end if;
end loop;
commit;
return;
exception
when others then
begin
rollback;
end;
end pHasCursor;

上一页  1 2 

Tags:经验 分享 Informix

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接