Search code examples
oracle-databasestored-proceduresplsqloracle12c

Why i'm getting "PLS-00302: component 'TABLE_NAME' must be declared"?


I'm trying to create a fairly simple stored procedure in 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

and i'm getting the following error:

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

the error occurs in the following line: dbms_output.put_line(x.table_name);

Question: what do I do wrong? I must be overseeing something very obvious...


UPDATE: the alias name has been "added" after pressing <TAB> by the dBeaver autocompletion - and I didn't notice it. ;)


Solution

  • Because you used column alias:

    select table_name name from
                      ----
    

    which means that you should have used

    dbms_output.put_line(x.name);
    

    instead.