2015-11-06 47 views
1
CREATE OR REPLACE PROCEDURE ZAD_CZWARTE AS 

row_num number; 
sql_stmnt varchar2(200); 
cursor kursor is 
select table_name from user_tables; 
tab_name varchar2(200); 
BEGIN 

    FOR c_kur IN kursor LOOP 
    tab_name := c_kur.table_name; 
    --dbms_output.put_line(tab_name); 
    sql_stmnt :='SELECT COUNT(*) FROM :1'; 
    execute immediate sql_stmnt into row_num using tab_name; 
    DBMS_OUTPUT.PUT_LINE(tab_name||' : '||row_num); 

    END LOOP; 

END zad_czwarte; 

還有s a problem with execute immediate line. Anybody knows what有問題嗎?一切對我來說似乎都很好。任務是輸出用戶的表格名稱以及其中的行數。PL/SQL用光標立即執行參數

+0

可能重複[如何在EXECUTE IMMEDIATE查詢中添加表名稱?](http://stackoverflow.com/questions/8441064/how-to-add-a-table-名稱即執行即時查詢) –

回答

4

無法將物理表綁定爲綁定變量。您的命令必須是sql_stmnt :='SELECT COUNT(*) FROM ' || tab_name;,然後execute immediate sql_stmnt into row_num;

+0

thx很多;)工作正常 – fearox