1

我写了以下程序

create or replace procedure sp_abc_profile 
(
  f_symbol_in abc.colname%TYPE
)
is profile abc%rowtype;
is profile2 abc2%rowtype;
begin
  SELECT fname, lname,mname,age
    INTO profile
  FROM abc
  WHERE f_symbol = f_symbol_in;

  SELECT initiaiinvestment AS minInitialInvestment, pr as qt, class1 as clss
    into profile2
  FROM 
      abc2 
  WHERE f_symbol = f_symbol_in;
end;

执行上述操作后,我收到如下错误消息:

错误 (7,3): PL/SQL: SQL 语句被忽略

错误 (21,5): PL/SQL:ORA-00913: 值太多

我不想选择两个表中的所有行。

如何在一个过程中编写多个 select 语句,以便过程中的每个 select 语句都返回一个结果集。

4

5 回答 5

2

尝试以下操作:

is
profile abc.fname%type;
profile2 abc2.initiaiinvestment%type;

在过程中有多个 select 语句没有问题。它与所选列和 PL/SQL 类型不匹配有关。

除此之外,您的代码中似乎有太多内容is

有关使用的更多信息select into,请查看此链接:Oracle PL/SQL "select into" 子句

于 2013-01-31T14:26:45.730 回答
0

试试这个,我们可以在过程中有多个 select 语句:

您的代码中存在太多价值的问题。

create or replace procedure sp_abc_profile 
(
  f_symbol_in abc.colname%TYPE
)
is profile abc.fname%type;
is profile2 abc2.initiaiinvestment%type;
begin
  SELECT fname
    INTO profile
  FROM abc
  WHERE f_symbol = f_symbol_in;

  SELECT initiaiinvestment into profile2
  FROM 
      abc2 
  WHERE f_symbol = f_symbol_in;
end;
于 2013-02-01T05:22:34.740 回答
0

正如其他人指出的那样,您有太多的“是”陈述。

在对行变量执行选择时,您需要选择所有内容:

select *
into profile
from abc
where f_symbol = f_symbol_in;

select *
into profile2
from abc2
where f_symbol = f_symbol_in;

当您在 f_symbol_in 上有多个匹配项时,您还会面临引发异常的风险。您的代码可以捕获此异常,或者您可以限制行数(即 rownum<=1),或者查看集合以加载与参数匹配的所有行。

于 2013-02-01T14:39:15.407 回答
0

解决方案是在 oracle 中使用 CURSORS,以便过程中的每个 select 语句都返回一个结果集。

然后可以使用您首选的脚本语言遍历该结果集以获得所需的输出。

create or replace 
procedure sp_abc_profile
(
  symbol_in in tablename.fieldname%type,
  cursor1 out SYS_REFCURSOR,
  cursor2 out SYS_REFCURSOR,
)
as
begin


    open cursor1 for
         {your select statement here}


    open cursor2 for
        {your second select statement here}


end sp_abc_profile;
于 2013-06-14T07:46:16.640 回答
0
  1. 删除多余的“IS”
  2. 添加:ROWNUM = 1
create or replace procedure sp_abc_profile 
(
  f_symbol_in abc.colname%TYPE
)
is profile abc%rowtype;
/*is*/ profile2 abc2%rowtype;
begin
  SELECT fname, lname,mname,age
    INTO profile
  FROM abc
  WHERE f_symbol = f_symbol_in
  AND ROWNUM = 1;

  SELECT initiaiinvestment AS minInitialInvestment, pr as qt, class1 as clss
    into profile2
  FROM 
      abc2 
  WHERE f_symbol = f_symbol_in
  AND ROWNUM = 1;
end;
于 2013-06-14T10:12:05.707 回答