简体   繁体   中英

Select into Table from Table2 where column in (Subquer)

I wrote in plsql:

w_table    USER_TAB_COLS.TABLE_NAME%TYPE  :='T481INPUTRIGADOC' ;

cursor selecttable is

select cols.*
FROM USER_TAB_COLS cols 
JOIN USER_TABLES tabs ON cols.TABLE_NAME = tabs.TABLE_NAME
WHERE 1=1
AND cols.COLUMN_NAME LIKE '%IDANAGPROPRIETARIO%' --Dovrei prenedere ogni i-esimo elemento della lista
ORDER BY cols.TABLE_NAME, cols.COLUMN_ID;


BEGIN
    tmpVar := 0;

    w_esitoElaborazione:='OK';
    w_descrizioneErrore:='';

    FOR REC IN selecttable LOOP
        w_cnt_record := w_cnt_record+1;
        w_table := REC.TABLE_NAME;
        w_col := REC.COLUMN_NAME;

        select w_col into a from w_table;

    end loop

but the problem is in the select query because there is written in output

[Error] ORA-00942 (76: 30): PL/SQL: ORA-00942: table or view does not exist

You have make the SQL call dynamic using EXECUTE IMMEDIATE , after forming the entire quire string.

 FOR REC IN selecttable LOOP
        w_cnt_record := w_cnt_record+1;
        w_table := REC.TABLE_NAME;
        w_col := REC.COLUMN_NAME;

        EXECUTE IMMEDIATE 'select '||w_col||' from '||w_table INTO a;

end loop

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM