&&&&&求助啊..SQL SERVER中的一个带游标和递归的存储过程.j要改成能在ORACLE中能运行的
哪位大G帮忙看看啊..在SQL SERVER 的存储过程改成oracle中能运行的.改来改去还是报错...哭死了..哪位GG帮忙看看正确的改法啊.不甚感激呀....SQL SERVER的存储过程是:
CREATE Procedure GetChildID
@CustomerNo varchar(20)
as
set nocount on
if @CustomerNo<>''
begin
declare @T_ID int,@T_No varchar(20),@T_LAB int
declare My_Cursor cursor local for select ID,CustomerNo,ParentID from Customer where ParentID=(select ID from customer where CustomerNo=@CustomerNo)
open My_Cursor
fetch next from My_Cursor into @T_ID,@T_No,@T_LAB --游标指向第一条记录
while @@fetch_status=0 begin
insert into temptable(ID ,ParentID) values(@T_ID,@T_LAB)
Execute GetChildID @T_No
fetch next from My_Cursor into @T_ID,@T_No,@T_LAB
end
close My_Cursor
deallocate My_Cursor
end
set nocount off
GO
------解决方案--------------------
SQL code
CREATE OR REPLACE PROCEDURE GETCHILDID(CUSTOMERNO VARCHAR2) IS
T_ID INT;
T_NO VARCHAR2(20);
T_LAB INT;
CURSOR MY_CURSOR(X VARCHAR2) IS
SELECT ID, CUSTOMERNO, PARENTID
FROM CUSTOMER
WHERE PARENTID = (SELECT ID FROM CUSTOMER WHERE CUSTOMERNO = X);
BEGIN
IF CUSTOMERNO IS NOT NULL THEN
OPEN MY_CURSOR(CUSTOMERNO);
LOOP
FETCH MY_CURSOR
INTO T_ID, T_NO, T_LAB;
EXIT WHEN MY_CURSOR%NOTFOUND;
INSERT INTO TEMPTABLE (ID, PARENTID) VALUES (T_ID, T_LAB);
END LOOP;
END IF;
CLOSE MY_CURSOR;
END;
/
我的异常网推荐解决方案:oracle存储过程,http://www.aiyiweb.com/oracle-develop/177537.html