create procedure pro(p_col in varchar2) as v_col varchar2(50):=p_col||','; num number; type mycursor is ref cursor; v_sor mycursor; str varchar2(100); begin num:=length(v_col); str:='select '; for i in 1..100 loop num:=instr(v_col,',',1,i); if num=length(v_col) then exit; end if; if i=1 then str:=str||'col'||substr(v_col,1,instr(v_col,',',1,1)-1)||','; end if; str:=str||'col'||substr(v_col,instr(v_col,',',1,i-1)+1,instr(v_col,',',1,i)-1)||','; end loop; str:=substr(str,1,length(str)-1); open v_sor for str||' from TEST…'; end; /
as
v_col varchar2(50):=p_col||',';
num number;
type mycursor is ref cursor;
v_sor mycursor;
str varchar2(100);
begin
num:=length(v_col);
str:='select ';
for i in 1..100 loop
num:=instr(v_col,',',1,i);
if num=length(v_col) then
exit;
end if;
if i=1 then
str:=str||'col'||substr(v_col,1,instr(v_col,',',1,1)-1)||',';
end if;
str:=str||'col'||substr(v_col,instr(v_col,',',1,i-1)+1,instr(v_col,',',1,i)-1)||',';
end loop;
str:=substr(str,1,length(str)-1);
open v_sor for str||' from TEST…';
end;
/
也可以到存放字段的系统表去取的!