I have a requirement which says run one query if today is monday, else run another query. For this I have wrote the below query, but I am getting the below error message.
DECLARE
l_today_date VARCHAR2(15) := TO_CHAR(SYSDATE, 'DAY');
BEGIN
CASE l_today_date
WHEN 'MONDAY' THEN
(SELECT st_time AS SYS_DATE,
start_time AS JOB_START_TIME,
COALESCE (end_job,'Job Is Running') AS JOB_END_TIME,
CASE duration_job
WHEN ' min'
THEN 'Job is Running'
ELSE duration_job
END AS JOB_DURATION,
CASE duration_job
WHEN ' min'
THEN 'Job is Running'
ELSE 'Complete'
END AS job_status
FROM
(SELECT name,
st_time,
ABS(floor(((((st_time - lag(end_time) over (order by end_time desc))*24*60*60)/3600)*3600)/60))
|| ' min' duration_job,
TO_CHAR(st_time, 'hh24:mi:ss') AS start_time,
TO_CHAR(lag(end_time)over(order by end_time desc),'hh24:mi:ss') AS end_job
FROM sc_stask
WHERE name IN ( '111 has started' ,'111 has ended' )
ORDER BY st_time DESC
)
WHERE name = '111 has started');
ELSE
(SELECT st_time AS SYS_DATE,
start_time AS JOB_START_TIME,
COALESCE (end_job,'Job Is Running') AS JOB_END_TIME,
CASE duration_job
WHEN ' min'
THEN 'Job is Running'
ELSE duration_job
END AS JOB_DURATION,
CASE duration_job
WHEN ' min'
THEN 'Job is Running'
ELSE 'Complete'
END AS job_status
FROM
(SELECT name,
st_time,
ABS(floor(((((st_time - lag(end_time)over(order by end_time desc) )*24*60*60)/3600)*3600)/60))
|| ' min' duration_job,
TO_CHAR(st_time, 'hh24:mi:ss') AS start_time,
TO_CHAR(lag(end_time)over(order by end_time desc),'hh24:mi:ss') AS end_job
FROM sc_stask
WHERE name IN ( '111 has started' ,'111 has completed' )
AND TO_CHAR(st_time,'DD/MM/YYYY')=TO_CHAR(SYSDATE,'DD/MM/YYYY')
ORDER BY st_time DESC
)
WHERE name = '111 has started'
);
END CASE;
dbms_output.Put_line(l_today_date);
END;
Here is the error message I am having
Error report -
ORA-06550: line 6, column 6:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql stddev
sum variance execute forall merge time timestamp interval
date <a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an alternat
ORA-06550: line 22, column 47:
PLS-00103: Encountered the symbol "OVER" when expecting one of the following:
. ( ) , * % & = - + < / > at in is mod remainder not rem =>
<an exponent (**)> <> or != or ~= >= <= <> and or like like2
like4 likec as between || member submultiset
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
Can someone please help me how to get over this. Also, the queries that run in each of the case statement work absolutely fine individually. But when I put them back into one, they don't.
Not
CASE, butIF:[EDIT: added example for the INTO clause]