我需要通过递增日期来根据一个日期值分配许多日期值。
以下代码是一个示例。但它会引发错误。我错了,建议。
DECLARE
issuedate date:='27-JAN-12';
issuedate_1 date;
issuedate_2 date;
issuedate_3 date;
BEGIN
for cnt in 1..5
loop
issuedate_||cnt := issuedate+cnt;
DBMS_OUTPUT.PUT_LINE(cnt);
DBMS_OUTPUT.PUT_LINE( issuedate_1);
DBMS_OUTPUT.PUT_LINE( issuedate_2);
DBMS_OUTPUT.PUT_LINE( issuedate_3);
end loop;
END;
答案 0 :(得分:0)
您可以使用plsql集合来分配日期值而不是100个变量
答案 1 :(得分:0)
试试这个
DECLARE
issuedate date ;
l_issuedate date;
BEGIN
issuedate := TO_DATE('27-JAN-12') ;
for cnt in 0..5
loop
SELECT issuedate+cnt
INTO l_issuedate
FROM DUAL ;
DBMS_OUTPUT.PUT_LINE(l_issuedate);
end loop;
END;
Out put:
27-JAN-12
28-JAN-12
29-JAN-12
30-JAN-12
31-JAN-12
01-FEB-12
答案 2 :(得分:0)
您无法动态形成变量名称,创建日期数组并增加和分配值。 TRY THIS LINK
authorate_ || cnt := issate + cnt; - 问题出在 BOLD 部分
示例:
SQL> declare
2
3 type date_aa is table of date index by pls_integer;
4 l_date_aa date_aa;
5 temp date:= to_date('27-mar-2012');
6 buckets number:=5;
7 begin
8 for elem in 1 .. buckets loop
9 select temp+1 into temp from dual;
10 l_date_aa(elem) := temp;
11 dbms_output.put_line(l_date_aa(elem));
12 end loop;
13 end;
14 /
输出:
28-MAR-12
29-MAR-12
30-MAR-12
31-MAR-12
01-APR-12
PL/SQL procedure successfully completed