【问题标题】:PLSQL: ORA-00933 why is INTO not working? [closed]PLSQL: ORA-00933 为什么 INTO 不工作? [关闭]
【发布时间】:2017-05-13 19:38:15
【问题描述】:

我正在编写一个 PLSQL 脚本,但有一个错误 - 我不知道出了什么问题 ;(

我很抱歉这个愚蠢的问题,但我真的不知道解决方案。 有人可以帮帮我吗?

这是我的代码:

DECLARE
  tagnow  webtags_20161221.editionid%TYPE;
BEGIN
  select editionid from webtags w, edition e
  into tagnow *the word into is red underlined*
  where editionid in (
  select editionid from (
  select editionid, tag, count(*) from webtags
  group by editionid, tag
  having count(*) > 1))
  and editionid = editionid
  order by createdat desc;

  DBMS_OUTPUT.put_line (
     tagnow);
END; 

为什么它不起作用?错误是:

ORA-06550: Line 5, Column 3:
PL/SQL: ORA-00933
ORA-06550: Line 4, Column 3:
PL/SQL: SQL Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

请帮帮我,我是初学者。

【问题讨论】:

标签: oracle plsql


【解决方案1】:

INTO 紧随 SELECT 部分之后,FROM 之前。

select e.editionid
into tagnow
from webtags w, edition e

另外,尝试学习标准的 ANSI JOIN,而不是使用这种旧的 Oracle 方式,并注意在 joiur 连接条件中使用别名。 您的查询将变为:

SELECT e.editionid
  INTO tagnow
  FROM webtags w
  INNER JOIN edition e
  ON (w.editionid = e.editionid)
 WHERE e.editionid IN (... );

另一种方式,别名可能不是绝对必要的(但使用它们是一个好习惯):

SELECT editionid
  INTO tagnow
  FROM webtags w
  INNER JOIN edition e
  USING (editionid)
 WHERE editionid IN (... );

另外,您不需要双重嵌套查询;你可以使用:

SELECT editionid
FROM webtags
GROUP BY editionid, tag
HAVING COUNT(*) > 1

【讨论】:

  • 第二个好像也错了,使用别名不应该注意吗?
  • 还有一个没有别名的 editionid
  • 太不专心了!谢谢
猜你喜欢
  • 2014-10-23
  • 1970-01-01
  • 2012-11-09
  • 2021-09-04
  • 2018-12-14
  • 1970-01-01
  • 2021-08-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多