SQL>select c1,c2 from pp_test;
C1 C2
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------a d
a c
a b
b c
c e
d f
e g
f h
8 rows selected
SQL>
SQL>select sys_connect_by_path(c1, '-')
2from pp_test
3 start with c1 ='a' connect by prior c2 = c1;
SYS_CONNECT_BY_PATH(C1,'-')
---------------------------------------------------------------------------------a
-a
-a-c
-a-c-e
-a
-a-b
-a-b-c
-a-b-c-e
8 rows selected
SQL>
createorreplacefunction ffindmd(c_cf varchar2)
returnvarchar2is
type tb1_cursor_type is ref cursor;
tb1_cursor tb1_cursor_type;
amount int:=0;
v_cf tb1.cf%type;
res varchar2(500);
v_temp tb1.cf%type;
beginselectcount(*) into amount from tb1 where cf=c_cf and md<>'a';
if amount=0thenreturn'';
elseopen tb1_cursor forselect md from tb1 where cf=c_cf and md<>'a';
dbms_output.put_line('出发点:'||c_cf);
loop
fetch tb1_cursor into v_cf;
exitwhen tb1_cursor%notfound;
dbms_output.put_line(c_cf||'的目的:'||v_cf);
--res:=res||' , '||v_cf; v_temp:=ffindmd(v_cf);
res:=res||v_temp||v_cf;
--dbms_output.put_line(res);end loop;
close tb1_cursor;
--dbms_output.put_line(res);return res;
endif;
end ffindmd;
select ffindmd('a') from dual ;