I'm (attempting) to write a query which will use the same date at several points in the query. I'd like to use a variable to make it easier to run the query for different dates. How would I do that? I'm getting assorted errors when I try to execute the query as it is.
ORA-06550: line 25, column 5: PLS-00103: Encountered the symbol "END" when expecting one of the following:
DECLARE
CalendarDate Date := TO_DATE('1/20/2015','MM/DD/YYYY');
BEGIN
SELECT
TIME_OF_DAY, COUNT(TIME_OF_DAY) ISSUE_ACTIVITY_COUNT
FROM
(SELECT
case
when to_char(CREATED_DT,'mi') between '00' and '14' then TO_CHAR(trunc(CREATED_DT,'HH24') + interVal '15' minute,'HH24:MI')
when to_char(CREATED_DT,'mi') between '15' and '29' then TO_CHAR(trunc(CREATED_DT,'HH24') + interVal '30' minute,'HH24:MI')
when to_char(CREATED_DT,'mi') between '30' and '44' then TO_CHAR(trunc(CREATED_DT,'HH24') + interVal '45' minute,'HH24:MI')
when to_char(CREATED_DT,'mi') between '45' and '59' then TO_CHAR(trunc(CREATED_DT,'HH24') + interVal '60' minute,'HH24:MI')
end as TIME_OF_DAY
FROM
CE.ISSUE_ITEM i
WHERE
(TRUNC(i.CREATED_DT) = CalendarDate))
GROUP BY
TIME_OF_DAY
ORDER BY
TIME_OF_DAY;
EXECUTE IMMEDIATE
END;