我希望在很长一段时间内在每个分区中都有行计数。所以我使用了用于循环的地方,我试图提取将在分区中使用的日期。但是我遇到了错误。无法解决它。任何人都可以帮助我和一些可能增加我的专业知识的文件吗?谢谢。
declare
call_enddate date;
totalcount number;
begin
for curdate in (WITH x(d) AS
(SELECT TO_DATE('2016-09-01', 'yyyy-mm-dd')
FROM dual
UNION ALL
SELECT d + interval '1' day
FROM x
WHERE d < TO_DATE('2017-09-05', 'yyyy-mm-dd'))
SELECT to_char (d, 'YYYYMMDD') Date_Char FROM x
)
loop
execute immediate 'select --parallel(32)
trunc(call_end_time), count(*) into call_enddate, totalcount
from lic_msc_data partition(p'||TO_CHAR(curdate.Date_Char,'YYYYMMDD'||'))
where sp_number like ''88016%''
group by trunc(call_end_time)';
dbms_output.put_line(call_enddate||'----'||totalcount);
end loop;
end;
错误代码:
ORA-06550: line 19, column 55:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
) , * & = - + < / > at in is mod remainder not rem =>
<an exponent (**)> <> or != or ~= >= <= <> and or like
答案 0 :(得分:1)
问题是您在语句中嵌入了PL / SQL into
子句。这样做是这样的:
for curdate in (WITH x(d) AS
(SELECT DATE '2016-09-01'
FROM dual
UNION ALL
SELECT d + 1
FROM x
WHERE d < DATE '2017-09-05')
SELECT d FROM x
)
loop
execute immediate 'select --parallel(32)
trunc(call_end_time), count(*)
from lic_msc_data partition(p'||TO_CHAR(curdate.d,'YYYYMMDD'||'))
where sp_number like :n
group by trunc(call_end_time)'
into call_enddate, totalcount using '88016%';
也许这个更优雅:
BEGIN
d := DATE '2016-09-01';
LOOP
EXECUTE IMMEDIATE ...
dbms_output.put_line(call_enddate||'----'||totalcount);
d := d + 1;
EXIT WHEN d > DATE '2017-09-05';
END LOOP;
END;
顺便说一下,--parallel(32)
没有任何意义。你的意思是--+ parallel(32)
resp。 /*+ parallel(32) */
?