日付範囲の値に基づいてクエリのカウントを与えるPL/SQLプロシージャを作成しています。私は、日付範囲を動的に取得したいと私はそのためのカーソルを書いている。異なる日付範囲のコレクションに値を設定する
私はコレクションを使用しており、毎月のカウントを取得していますが、私が直面している問題は、コレクションに先月のカウントだけが入力されていることです。私はすべての月の数を取得したい。誰も助けることができますか?
この
は私が書かれている手順です:create or replace
Procedure Sample As
Cursor C1 Is
With T As (
select to_date('01-JAN-17') start_date,
Last_Day(Add_Months(Sysdate,-1)) end_date from dual
)
Select To_Char(Add_Months(Trunc(Start_Date,'mm'),Level - 1),'DD-MON-YY') St_Date,
to_char(add_months(trunc(start_date,'mm'),level),'DD-MON-YY') ed_date
From T
Connect By Trunc(End_Date,'mm') >= Add_Months(Trunc(Start_Date,'mm'),Level - 1);
Type T_count_Group_Id Is Table Of number;
V_count_Group_Id T_count_Group_Id;
Begin
For I In C1
Loop
Select Count(Distinct c1) bulk collect Into V_Count_Group_Id From T1
Where C2 Between I.St_Date And I.Ed_Date;
End Loop;
For J In V_Count_Group_Id.First..V_Count_Group_Id.Last
Loop
Dbms_Output.Put_Line(V_Count_Group_Id(J));
end loop;
END SAMPLE;
あなたはそれにスポットがあります。ありがとうございました...私は今、utl_fileを使ってxlsファイルにこれらの値を設定する必要があります。 –