0

嘿,任何人都可以帮助解决这个错误:

9/10 PLS-00428: an INTO clause is expected in this SELECT statement

尝试基于单个参数打印详细信息时会出现此问题。这是我一直在使用的代码

 CREATE OR REPLACE PROCEDURE PRINT_ACTOR_QUOTES (ID_actor CHAR)
 AS
 first_name CHAR(30);
 last_name CHAR(30);
 title CHAR(40);
 year NUMBER;
 role CHAR(40);
quote CHAR(255);
CURSOR print_cursor IS
SELECT a.actorID, a.firstname, a.lastname, m.title as title, m.year as year ,  
 r.rolename as role1 , q.quotechar as quote1 FROM movie m, role r, quote q, rolequote  
rq, actor a WHERE
a.actorID = r.actorID AND
m.movieID = r.movieID AND
rq.quoteID = q.quoteID AND
rq.roleID = r.roleID;
BEGIN  
FOR row IN print_cursor LOOP
SELECT AQ.QUOTES, A.FIRSTNAME, A.LASTNAME 
FROM ACTOR_QUOTES AQ, ACTOR A
Where row.actorID = ID_actor;
END LOOP; 
END PRINT_ACTOR_QUOTES ;
/
4

1 回答 1

1

我假设相关的错误是

PLS-00428:此 SELECT 语句中应有一个 INTO 子句

(而不是您在问题标题中提到的那个)。

问题是您的 FOR 循环中的 SELECT 语句。在 PL/SQL 中,您不能只选择数据而不对其进行任何操作。因此,您需要一条 INTO 语句将检索到的数据存储在 PL/SQL 变量中:

SELECT AQ.QUOTES, A.FIRSTNAME, A.LASTNAME
  INTO quote, first_name, last_name
FROM ACTOR_QUOTES AQ, ACTOR A
Where row.actorID = ID_actor;

然后我可以发现几个额外的问题:

  • SELECT 语句似乎是一个完全外部联接,这很少是您想要的。
  • 如果返回多行,带有 INTO 子句的 SELECT 语句将失败。
  • What's the purpose of the FOR loop if you overwrite the local variables on each iteration and don't do anything with them.
于 2012-05-03T13:35:58.523 回答