ORA-00923: plsql 算术运算符和 INTO
ORA-00923 : plsql Arithmetic operator and INTO
这个 sql 代码 运行 很好
SELECT
primax-stdmax ,
stdmax-stdmaxapp
FROM
(SELECT MAX(sequence#) stdmax, thread#, resetlogs_change#
FROM v$archived_log
WHERE standby_dest='YES'
GROUP BY thread#, resetlogs_change#) a,
(SELECT MAX(sequence#) stdmaxapp, thread#, resetlogs_change#
FROM v$archived_log
WHERE standby_dest='YES'
AND applied='YES'
GROUP BY thread#, resetlogs_change#) b,
(SELECT MAX(sequence#) primax, thread#, resetlogs_change#
FROM v$archived_log
WHERE standby_dest='NO'
GROUP BY thread#, resetlogs_change#) c
WHERE a.thread# = b.thread#
AND b.thread# = c.thread#;
但是当我转换成如下 pl/sql 代码时,它失败了。
declare
l_shipgap NUMBER := 0;
l_applygap NUMBER := 0;
begin
SELECT
primax-stdmax into l_shipgap,
stdmax-stdmaxapp into l_applygap
FROM
(SELECT MAX(sequence#) stdmax, thread#, resetlogs_change#
FROM v$archived_log
WHERE standby_dest='YES'
GROUP BY thread#, resetlogs_change#) a,
(SELECT MAX(sequence#) stdmaxapp, thread#, resetlogs_change#
FROM v$archived_log
WHERE standby_dest='YES'
AND applied='YES'
GROUP BY thread#, resetlogs_change#) b,
(SELECT MAX(sequence#) primax, thread#, resetlogs_change#
FROM v$archived_log
WHERE standby_dest='NO'
GROUP BY thread#, resetlogs_change#) c
WHERE a.thread# = b.thread#
AND b.thread# = c.thread#;
end;
/
执行:
错误:
SQL> @aa.sql
stdmax-stdmaxapp 到 l_applygap
*
第 7 行的错误:
ORA-06550:第 7 行,第 20 列:
PL/SQL: ORA-00923: 在预期的位置找不到 FROM 关键字
ORA-06550:第 5 行,第 1 列:
PL/SQL:SQL 语句被忽略
语法错误。
由于一条语句包含一个 SELECT
、一个 FROM
、一个 WHERE
子句,因此 INTO
也是如此 - 只有一个:
SELECT
primax - stdmax,
stdmax - stdmaxapp
INTO l_shipgap, l_applygap
FROM ...
(对于“one”,我不是在谈论子查询 - 就像您一样,而是 general SELECT
语句语法)。
这个 sql 代码 运行 很好
SELECT
primax-stdmax ,
stdmax-stdmaxapp
FROM
(SELECT MAX(sequence#) stdmax, thread#, resetlogs_change#
FROM v$archived_log
WHERE standby_dest='YES'
GROUP BY thread#, resetlogs_change#) a,
(SELECT MAX(sequence#) stdmaxapp, thread#, resetlogs_change#
FROM v$archived_log
WHERE standby_dest='YES'
AND applied='YES'
GROUP BY thread#, resetlogs_change#) b,
(SELECT MAX(sequence#) primax, thread#, resetlogs_change#
FROM v$archived_log
WHERE standby_dest='NO'
GROUP BY thread#, resetlogs_change#) c
WHERE a.thread# = b.thread#
AND b.thread# = c.thread#;
但是当我转换成如下 pl/sql 代码时,它失败了。
declare
l_shipgap NUMBER := 0;
l_applygap NUMBER := 0;
begin
SELECT
primax-stdmax into l_shipgap,
stdmax-stdmaxapp into l_applygap
FROM
(SELECT MAX(sequence#) stdmax, thread#, resetlogs_change#
FROM v$archived_log
WHERE standby_dest='YES'
GROUP BY thread#, resetlogs_change#) a,
(SELECT MAX(sequence#) stdmaxapp, thread#, resetlogs_change#
FROM v$archived_log
WHERE standby_dest='YES'
AND applied='YES'
GROUP BY thread#, resetlogs_change#) b,
(SELECT MAX(sequence#) primax, thread#, resetlogs_change#
FROM v$archived_log
WHERE standby_dest='NO'
GROUP BY thread#, resetlogs_change#) c
WHERE a.thread# = b.thread#
AND b.thread# = c.thread#;
end;
/
执行:
错误: SQL> @aa.sql stdmax-stdmaxapp 到 l_applygap * 第 7 行的错误: ORA-06550:第 7 行,第 20 列: PL/SQL: ORA-00923: 在预期的位置找不到 FROM 关键字 ORA-06550:第 5 行,第 1 列: PL/SQL:SQL 语句被忽略
语法错误。
由于一条语句包含一个 SELECT
、一个 FROM
、一个 WHERE
子句,因此 INTO
也是如此 - 只有一个:
SELECT
primax - stdmax,
stdmax - stdmaxapp
INTO l_shipgap, l_applygap
FROM ...
(对于“one”,我不是在谈论子查询 - 就像您一样,而是 general SELECT
语句语法)。