Oracle 此SELECT语句中应包含INTO子句

Oracle 此SELECT语句中应包含INTO子句,oracle,plsql,oracle11g,oracle10g,Oracle,Plsql,Oracle11g,Oracle10g,请问有什么帮助吗? 我想返回所有居住在法国的人,然后将他们与居住在BELguim的人进行比较,如果他们有相同的名字或名字,请显示结果 declare cursor c is select namer from poeple where city = 'France'; c_res c%rowtype; begin open c; loop fetch c into c_res; exit when c%notfound; select * from poe

请问有什么帮助吗? 我想返回所有居住在法国的人,然后将他们与居住在BELguim的人进行比较,如果他们有相同的名字或名字,请显示结果

declare
  cursor c is select namer from poeple where city = 'France';
  c_res c%rowtype;
begin
  open c;
  loop
    fetch c into c_res;
    exit when c%notfound;
    select * from poeple tw where city = 'BELguim' AND (c_res.namer = tw.namer OR c_res.namer = tw.namer || ' _done' );
  end loop;
  close c;
end;

为什么要使用光标?您可以使用单个查询编写此命令:

select pb.*
from poeple pf join
     poeple pb
     on pf.city = 'France' and pb.city = 'BELgium' and
        (pf.namer = pb.namer or pf.namer = pb.namer || ' _done');
代码的问题是PL/SQL不允许查询从代码块返回任何内容。您可以打印结果、将值插入变量或将它们放入另一个表中。但是,您不能只获得查询结果。

问题在于:

从Pople tw中选择*,其中city='BELguim'和(c_res.namer =tw.namer或c_res.namer=tw.namer | |‘‘u done’

不能直接在
PL/SQL
中写入
SQL
。PL/SQL引擎需要一个
INTO
子句

查看代码时,不需要
光标c
。它可以用一个SQL编写。这又回到了Gordon的问题:

select pb.*
from poeple pf join
     poeple pb
     on pf.city = 'France' and pb.city = 'BELgium' and
        (pf.namer = pb.namer or pf.namer = pb.namer || ' _done');
如果您确实需要PL/SQL来处理一些您没有解释过的内容,例如将结果集返回为REF CURSOR,那么将
OUT
参数设置为
REF CURSOR
。但是,您需要解释要求

如果您可以在SQL中执行某些操作,则不要使用PL/SQL。


编辑如果您的最终目标是更新,则在
MERGE
语句中使用上述查询作为
USING
子句。

您确定光标
c
确实必须具有
'France'
条件吗?它不应该是法国吗?我突然想到有一个
和一个比应该多的空格。@nop77svk yes edit donewell实际上是因为我必须更新每一行的rendred,所以我需要游标,不能使用用户加入更新。你应该使用
update
语句,而不是
select
。通过
更新
而不使用游标,您可能可以做您想做的事情。您当然可以使用
merge
执行所需操作。是的,我需要返回结果集,以便进一步更新每一行
merge