日期:2014-05-17 浏览次数:20851 次
set serveroutput on --打开sqlplus输出,如果是用plsqldev 这个忽略 DECLARE V_CNT INT; BEGIN FOR REC IN (SELECT CODE FROM B) LOOP EXECUTE IMMEDIATE 'select count(1) from t_' || REC.CODE INTO V_CNT; DBMS_OUTPUT.PUT_LINE('表[t_' || REC.CODE || ']数据条数:' || V_CNT); END LOOP; END;
------解决方案--------------------
DECLARE V_CNT INT; V_SUM INT;--总条数。 BEGIN V_SUM :=0; FOR REC IN (SELECT CODE FROM B) LOOP EXECUTE IMMEDIATE 'select count(1) from t_' || REC.CODE INTO V_CNT; V_SUM := V_SUM + V_CNT; END LOOP; END;