代码之家  ›  专栏  ›  技术社区  ›  MaxU - stand with Ukraine

为什么我得到“PLS-00302:必须声明组件‘表\名称’”?

  •  0
  • MaxU - stand with Ukraine  · 技术社区  · 4 年前

    我试图在Oracle 12.2 DB中创建一个相当简单的存储过程:

    create or replace procedure list_tables (
        p_src_schema    varchar2
    )
    as
        l_src_schema    varchar2(30)    := upper(p_src_schema);
    begin
        for x in (select table_name name from all_tables where owner = l_src_schema
                  and not regexp_like(table_name, '(AAA|BKP_|LOG_|TMP_|TEST|XX).*')
                  order by table_name)
        loop
            dbms_output.put_line(x.table_name);
        end loop;
    end;
    /
    show errors
    

    我得到以下错误:

    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    11/9     PL/SQL: Statement ignored
    11/32    PLS-00302: component 'TABLE_NAME' must be declared
    

    dbms_output.put_line(x.table_name);

    问题:

    1 回复  |  直到 4 年前
        1
  •  1
  •   Littlefoot    4 年前

    因为你用了专栏 :

    select table_name name from
                      ----
    

    也就是说你应该用

    dbms_output.put_line(x.name);
    

    相反。