我正在尝试在Oracle中使用日期变量,我写了一个简单的声明,但它没有用,任何人都可以帮我解决这个问题,thx
谢
Declare
StartDate Date := to_date('03/11/2017', 'dd/mm/yyyy');
Begin
SELECT
REQUESTED_DATE.CALENDAR_DATE,
Count( distinct FD_DW.SALES_HEADER_FACT.SALE_ID) INTO StartDate
FROM
FD_DW.DATE_DIM REQUESTED_DATE,
FD_DW.SALES_HEADER_FACT
WHERE
( REQUESTED_DATE.DATE_KEY=FD_DW.SALES_HEADER_FACT.REQUESTED_DATE_KEY )
AND
REQUESTED_DATE.CALENDAR_DATE = StartDate
GROUP BY
REQUESTED_DATE.CALENDAR_DATE;
End;
错误讯息:
答案 0 :(得分:1)
试试这个
declare
StartDate Date := to_date('03/11/2017', 'dd/mm/yyyy');
n_count integer;
begin
select cnt INTO n_count from
(
SELECT
REQUESTED_DATE.CALENDAR_DATE,
Count( distinct HEADER_FACT.SALE_ID) as cnt
FROM
FD_DW.DATE_DIM REQUESTED_DATE,
FD_DW.SALES_HEADER_FACT HEADER_FACT
WHERE
REQUESTED_DATE.DATE_KEY = HEADER_FACT.REQUESTED_DATE_KEY and
REQUESTED_DATE.CALENDAR_DATE = StartDate
GROUP BY REQUESTED_DATE.CALENDAR_DATE
)
;
end;