业务是这样的有一个部门树,当点击某个部门时,需要查出当前部门及其所有子部门的部门id,然后用in过滤,
其中<查出当前部门及其所有子部门的部门id>,我打算写一个递归的存储过程(因为部门与部门之间靠parent_id关联),如下,
create or replace procedure sp_test1(p_id varchar2,ids out clob) is
cursor cur is select t.id from depts t where t.parent_id = p_id;
id_string clob;
begin
for cur1 in cur loop
id_string := id_string|| ',' || cur1.id;
sp_test1(cur1.id,id_string);
end loop;
ids := id_string;
end;然后是调用函数,
create or replace function get_value(parent_id varchar2) return clob
as
ids clob;
begin
sp_test1(parent_id,ids);
return ids;
end;然后执行 select get_value('ff8080812b0cafcf012b0f84ad8d0006') from dual
结果查出来一个是一个clob字段,但是里面什么都没有,不应该啊,不知道错在哪里,求各位大师指点,感激涕零!
其中<查出当前部门及其所有子部门的部门id>,我打算写一个递归的存储过程(因为部门与部门之间靠parent_id关联),如下,
create or replace procedure sp_test1(p_id varchar2,ids out clob) is
cursor cur is select t.id from depts t where t.parent_id = p_id;
id_string clob;
begin
for cur1 in cur loop
id_string := id_string|| ',' || cur1.id;
sp_test1(cur1.id,id_string);
end loop;
ids := id_string;
end;然后是调用函数,
create or replace function get_value(parent_id varchar2) return clob
as
ids clob;
begin
sp_test1(parent_id,ids);
return ids;
end;然后执行 select get_value('ff8080812b0cafcf012b0f84ad8d0006') from dual
结果查出来一个是一个clob字段,但是里面什么都没有,不应该啊,不知道错在哪里,求各位大师指点,感激涕零!
--这是一次赋值
sp_test1(cur1.id,id_string);
--它在输出参数的位置,又一次赋值好了,只要它拼接出来一次,下次马上会被换成其它的值而不是累加最后一次,肯定是查询出来一个null,否则就是死循环。然后它被赋值成null,结束。
这种方法。
注意where使用的地方不同会导致去除单一节点或是一个分支