我有一个要求,如果今天是星期一,则运行一个查询,否则运行另一个查询。为此,我编写了以下查询,但收到以下错误消息。
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;
这是我收到的错误消息
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.
有人可以帮我解决这个问题。此外,在每个 case 语句中运行的查询都可以单独工作。但是当我将它们重新组合在一起时,它们不会。