codes......cursor t_name is
    select table_name
      from user_tab_cols
     where column_name = 'AAC001'
          and (length(table_name) = 4 or length(table_name) = 5)
          and table_name not like 'S%'
          and table_name not like '%AC01%';codes...
open t_name;
  loop
    fetch t_name
      into v_tname;
    exit when t_name%notfound;
cursor t_cname is
      select column_name from user_tab_cols where table_name=v_tname;

codes...
end loop;
codes...分割线
==================================================================================
上段代码中的红色部分编译的时候报错,那应该怎么改才正确呢?!求高人指点!!

解决方案 »

  1.   

    亲,在ORACLE中,CURSOR的声明或者定义,是不能出现的实际的代码段中的。
    还是得放到codes前面。在codes里,直接使用就可以了
      

  2.   

    set serveroutput on;
    declare
      v_tname varchar2(100) := '';
      c_tname varchar2(100) := '';
      cursor t_name is
        select table_name  from user_tab_cols  where column_name = 'T3';
      
      cursor t_cname is
        select column_name from user_tab_cols where table_name = v_tname;begin
    open t_name;
    loop
      fetch t_name into v_tname;
      exit when t_name%notfound;
        open t_cname;
        loop fetch t_cname into c_tname;
        dbms_output.put_line(c_tname);
        exit when t_cname%notfound;
        end loop;
        close t_cname;
    end loop;
    close t_name;end;
      

  3.   

    你这有必要声明两个游标吗?declare
        cursor c_tab_col is
            select table_name, column_name
              from user_tab_cols
             where column_name = 'AAC001'
               and (length(table_name) = 4 or length(table_name) = 5)
               and table_name not like 'S%'
               and table_name not like '%AC01%';
    begin
        for tab in c_tab_col
        loop
            -- 代码中获取表名使用 tab.table_name
            -- 获取列名 tab.column_name
        end loop;
    end;
      

  4.   

    用隐式游标
    for i in (select * from tab)
    loop
    ……
    end loop;