T-SQL同名存储过程的Oracle版,数据表和列相应改变,结构不变
CREATE OR REPLACE PROCEDURE GetCategoryWays
IS
CACHE_PCID number(5); --缓存PCID
OUT_STR nvarchar2(500); --输出的类别链条
CACHE_PARENTID number(5); --缓存的父类别ID
CACHE_CATENAME nvarchar2(20); --缓存的类别名字
---------------------------------------------------------------------------
/*
* 创建:***
* 时间:200*/0*/**
* 用途:获取类别链条
*/
BEGIN
--声明游标:获取所有独立叶结点类别
DECLARE CURSOR ENDPOINT_CURSOR IS
SELECT B.Category_Code FROM
Category A,Category B
WHERE A.Category_Parent(+)=B.Category_Code AND
A.Category_Code IS NULL;
BEGIN
--打开游标
OPEN ENDPOINT_CURSOR;
FETCH ENDPOINT_CURSOR INTO CACHE_PCID;
--循环分析PCID、ParentID,获取类别链条
--获取父类别
LOOP FETCH ENDPOINT_CURSOR INTO CACHE_PCID;
EXIT WHEN ENDPOINT_CURSOR%NOTFOUND;
BEGIN
SELECT
Category_Parent,Category_Name into CACHE_PARENTID,OUT_STR
FROM Category WHERE Category_Code=CACHE_PCID;
--开始循环
LOOP EXIT WHEN CACHE_PARENTID=0;
BEGIN
SELECT Category_Name into CACHE_CATENAME From Category
WHERE Category_Code=CACHE_PARENTID;
OUT_STR:=CACHE_CATENAME||'----'||OUT_STR;
SELECT Category_Parent into CACHE_PARENTID FROM Category
WHERE Category_Code=CACHE_PARENTID;
END;
END LOOP;
DBMS_OUTPUT.PUT_LINE(OUT_STR);
--还原OUT_STR
OUT_STR:='';
END;
END LOOP;
CLOSE ENDPOINT_CURSOR;
END;
END;
---------------------------------------------------------------------------
IS
CACHE_PCID number(5); --缓存PCID
OUT_STR nvarchar2(500); --输出的类别链条
CACHE_PARENTID number(5); --缓存的父类别ID
CACHE_CATENAME nvarchar2(20); --缓存的类别名字
---------------------------------------------------------------------------
/*
* 创建:***
* 时间:200*/0*/**
* 用途:获取类别链条
*/
BEGIN
--声明游标:获取所有独立叶结点类别
DECLARE CURSOR ENDPOINT_CURSOR IS
SELECT B.Category_Code FROM
Category A,Category B
WHERE A.Category_Parent(+)=B.Category_Code AND
A.Category_Code IS NULL;
BEGIN
--打开游标
OPEN ENDPOINT_CURSOR;
FETCH ENDPOINT_CURSOR INTO CACHE_PCID;
--循环分析PCID、ParentID,获取类别链条
--获取父类别
LOOP FETCH ENDPOINT_CURSOR INTO CACHE_PCID;
EXIT WHEN ENDPOINT_CURSOR%NOTFOUND;
BEGIN
SELECT
Category_Parent,Category_Name into CACHE_PARENTID,OUT_STR
FROM Category WHERE Category_Code=CACHE_PCID;
--开始循环
LOOP EXIT WHEN CACHE_PARENTID=0;
BEGIN
SELECT Category_Name into CACHE_CATENAME From Category
WHERE Category_Code=CACHE_PARENTID;
OUT_STR:=CACHE_CATENAME||'----'||OUT_STR;
SELECT Category_Parent into CACHE_PARENTID FROM Category
WHERE Category_Code=CACHE_PARENTID;
END;
END LOOP;
DBMS_OUTPUT.PUT_LINE(OUT_STR);
--还原OUT_STR
OUT_STR:='';
END;
END LOOP;
CLOSE ENDPOINT_CURSOR;
END;
END;
---------------------------------------------------------------------------