我使用來自兩個不同帖子的建議將以下代碼拼湊在一起,並且碰壁了。我的代碼的最終目標是從當年的10月1日至9月30日查找記錄,而不會提示用戶輸入或不必在兩者之間硬編碼日期範圍。在運行代碼時,我目前收到以下錯誤「綁定變量」End_Year「未聲明」。Toad For Oracle:綁定變量「End_Year」未聲明
declare
begin_Year date;
begin
select trunc(sysdate, 'YEAR')-92 FY_begin_year
Into begin_Year
from Dual;
end;
declare
End_Year date;
begin
select add_months(trunc(sysdate, 'YEAR'), 12)-93 FY_end_year
into End_Year
from dual;
end;
SELECT inv.company as company
, inv.customer_id as cust
, inv.address_id
,inv.invdate
, SUM(inv.sales) as sales
, SUM(inv.cost) as costs
FROM ifsinfo.hb_invoicing_all inv
WHERE inv.site IN ('06','01')
AND TO_DATE(inv.invdate) between :begin_Year and :End_Year
GROUP BY inv.company
, inv.customer_id
, inv.address_id
, inv.invdate
':var_name'是一個綁定變量::告訴編譯器期望用戶輸入。更改您的var_names以刪除:假定定義的end_year和Begin_year變量不是hb_invoicing_All中的列名稱,否則還要重命名這些變量。喜歡'var_Begin_year' http://stackoverflow.com/questions/1597806/what-is-wrong-with-this-pl-sql-bind-variable-is-not-declared – xQbert