日期:2014-05-17 浏览次数:21137 次
EXECUTE IMMEDIATE 'select count(1) from '||v_table_name(i) into v_count;
------解决方案--------------------
我觉得你可以看看这个,使用with来将查询作为临时表
create or replace procedure proc_add(IN_DATE IN VARCHAR2)
AS
strSQLA varchar2(1000);
strSQLB VARCHAR2(1000);
begin
/*
strSQLA:='create table TABLE_TMP AS SELECT TOTAL FROM ( SELECT COUNT(*) TOTAL
FROM job_info WHERE JOBDATE=TO_DATE('||IN_DATE||','||'''YYYYMMDD'''||') UNION ALL
SELECT COUNT(*) TOTAL
FROM JOB_INFO_20100729 WHERE JOBDATE=TO_DATE('||IN_DATE||','||'''YYYYMMDD'''||')
)' ;
*/
strSQLA:='WITH TABLE_TMP AS (SELECT TOTAL FROM ( SELECT COUNT(*) TOTAL
FROM job_info WHERE JOBDATE=TO_DATE('||IN_DATE||','||'''YYYYMMDD'''||') UNION ALL
SELECT COUNT(*) TOTAL
FROM JOB_INFO_20100729 WHERE JOBDATE=TO_DATE('||IN_DATE||','||'''YYYYMMDD'''||')
)) SELECT * FROM TABLE_TMP' ;
DBMS_OUTPUT.put_line('strSQLA :'||strSQLA);
execute immediate strSQLA;
strSQLB:='INSERT INTO PRO_TABLE SELECT SUM(TOTAL) FROM TABLE_TMP';
DBMS_OUTPUT.put_line('strSQLB :'||strSQLB);
EXECUTE IMMEDIATE strSQLB;
COMMIT ;
END proc_add;
------解决方案--------------------
是不是 存在一些特殊的字符 导致拼接的SQL语句错误了 你打印出来再去查询
DBMS_OUTPUT.put_line('select count(1) from '||v_table_name(i))
看打印的结果