LZ是要这种的吗: declare v1 varchar2(200); begin for c1 in (select语句) loop v1:=c1.字段名; end loop; end; 还是说不知道游标里面有哪些列,要遍历游标列呢?
给个例子,游标遍历select table_name from user_tablesset serveroutput on;declare type sp_test1_cursor is ref cursor; test1_cursor sp_test1_cursor; v_name user_tables.TABLE_NAME%type; v_count number; strsql varchar2(100); begin open test1_cursor for select table_name from user_tables; loop fetch test1_cursor into v_name; if v_name is not null then strsql:='select count(*) from ' || v_name; execute immediate strsql into v_count; end if; exit when test1_cursor%notfound; dbms_output.put_line(v_name||' '||v_count); end loop; close test1_cursor; end;
declare cursor mysor is select * from emp; begin for i in mysor loop dbms_output.put_line(i.ename||e.deptno); end loop; end; 这样就可以获得全部信息
set serveroutput on;declare type sp_test1_cursor is ref cursor; test1_cursor sp_test1_cursor; v_name user_tables.TABLE_NAME%type; v_count number; strsql varchar2(100); begin open test1_cursor for select table_name from user_tables; loop fetch test1_cursor into v_name; if v_name is not null then strsql:='select count(*) from ' || v_name; execute immediate strsql into v_count; end if; exit when test1_cursor%notfound; dbms_output.put_line(v_name||' '||v_count); end loop; close test1_cursor; end;
declare
v1 varchar2(200);
begin
for c1 in (select语句) loop
v1:=c1.字段名;
end loop;
end;
还是说不知道游标里面有哪些列,要遍历游标列呢?
test1_cursor sp_test1_cursor;
v_name user_tables.TABLE_NAME%type;
v_count number;
strsql varchar2(100);
begin
open test1_cursor for select table_name from user_tables;
loop
fetch test1_cursor into v_name;
if v_name is not null then
strsql:='select count(*) from ' || v_name;
execute immediate strsql into v_count;
end if;
exit when test1_cursor%notfound;
dbms_output.put_line(v_name||' '||v_count);
end loop;
close test1_cursor;
end;
cursor mysor is select * from emp;
begin
for i in mysor
loop
dbms_output.put_line(i.ename||e.deptno);
end loop;
end;
这样就可以获得全部信息
test1_cursor sp_test1_cursor;
v_name user_tables.TABLE_NAME%type;
v_count number;
strsql varchar2(100);
begin
open test1_cursor for select table_name from user_tables;
loop
fetch test1_cursor into v_name;
if v_name is not null then
strsql:='select count(*) from ' || v_name;
execute immediate strsql into v_count;
end if;
exit when test1_cursor%notfound;
dbms_output.put_line(v_name||' '||v_count);
end loop;
close test1_cursor;
end;