SELECT a.union_code,
(select count(1)
from UNION_MEMBER um
where um.delete_flag = '0'
and um.member_union_code in
(select ubi.union_code
from union_base_info ubi
where ubi.union_delete = '0'
start with ubi.union_code = a.union_code//找不到
connect by prior ubi.union_code =
ubi.superior_union)
) as UNION_MEMBER_NUM
FROM UNION_BASE_INFO a
where a.SUPERIOR_UNION = '0000000000'
现在想用存储过程处理 但是不懂怎么写 求大佬指导
针对您的问题,可以通过以下存储过程来处理:
CREATE OR REPLACE PROCEDURE PROC_NAME AS
BEGIN
FOR rec IN (SELECT a.union_code,
(SELECT COUNT(1)
FROM UNION_MEMBER um
WHERE um.delete_flag = '0'
AND um.member_union_code IN (SELECT ubi.union_code
FROM union_base_info ubi
WHERE ubi.union_delete = '0'
START WITH ubi.union_code = a.union_code
CONNECT BY prior ubi.union_code = ubi.superior_union)
) AS UNION_MEMBER_NUM
FROM UNION_BASE_INFO a
WHERE a.SUPERIOR_UNION = '0000000000')
LOOP
/* do something with rec.union_code and rec.UNION_MEMBER_NUM */
END LOOP;
END;
其中,存储过程的核心代码是一个简单的循环,遍历了 UNION_BASE_INFO 表中所有 SUPERIOR_UNION='0000000000' 的记录,并根据每条记录中的 union_code 执行子查询,最终将结果保存在 UNION_MEMBER_NUM 中。
在程序中使用存储过程时,只需要调用 PROC_NAME 即可,具体使用方式为:
CALL PROC_NAME;
注意,在调用存储过程之前,需要先创建该存储过程。此外,还可以根据实际需求,将上述代码进行修改和优化,以达到更好的性能和效率。