ORA-01422:精确提取返回超过请求的行数错误

时间:2015-07-07 10:59:34

标签: oracle plsql oracle11g oracle10g

我想将exch_name传递给where子句中的主查询 但是它给出了错误

ORA-01403: no data found

问题2:

我已经通过了硬编码值而不是exch_name用于测试目的 MV_sum.exch = 'ASX'但是给出了错误

ORA-01422: exact fetch returns more than requested number of rows

请指导我......

DECLARE
  exch_name     VARCHAR2(200);
  v_exch        VARCHAR2(1000);
  output        VARCHAR2(4000);
  abc           VARCHAR2(4000);
  v_str         VARCHAR2(4000);
  err_code      VARCHAR2 (4000);
  err_msg       VARCHAR2 (4000);

  CURSOR tbl IS
    SELECT DISTINCT MV_sum.exch
      into exch_name
      FROM LLDMA.MERCAUDIT_VOLUME_AGG_SUMMARY MV_sum,
           EXCHANGE_MAPPING ex_map
      WHERE MV_SUM.EXCH = ex_map.agora_exchange
      ORDER BY 1;
BEGIN
  DBMS_OUTPUT.PUT_LINE (exch_name);

  for x in tbl loop
    EXIT WHEN tbl%NOTFOUND;

   select 'ICTO-10510' ||','|| MV_sum.exch ||','|| 
          to_char(to_date(MV_sum.TRADEDATE, 'yymmdd'), 'dd-Mon-yyyy')  ||
          ','|| '' ||','|| 'TDV' ||','|| MV_sum.new ||','|| "NEW"  ||
          ','|| '' || ','|| ''
     into abc  
     from LLDMA.MERCAUDIT_VOLUME_AGG_SUMMARY MV_sum ,
          EXCHANGE_MAPPING ex_map
     where (TRADEDATE between TO_CHAR  (sysdate-545, 'YYMMDD')
                          and TO_CHAR  (sysdate, 'YYMMDD') ) and
           MV_SUM.EXCH = ex_map.agora_exchange and
           MV_sum.exch = 'ASX' ---Passing hardcoded value for testing
           --and MV_sum.exch = exch_name --If I uncomment this "ORA-01403: no data found"error is coming
     group by MV_sum.exch,
              to_char(to_date(MV_sum.TRADEDATE, 'yymmdd'), 'dd-Mon-yyyy' ),
              MV_sum.new;

    EXECUTE IMMEDIATE abc into output;

    DBMS_OUTPUT.PUT_LINE (output);
  end loop;
EXCEPTION
  WHEN OTHERS THEN
    err_code := SQLCODE;
    err_msg := SUBSTR(SQLERRM, 1, 200);

    DBMS_OUTPUT.PUT_LINE  (err_code || err_msg);
END;

1 个答案:

答案 0 :(得分:0)

以下是工作示例:example。注意我如何使用光标:c而不仅仅是create table t (a int) ; insert into t values(1) ; insert into t values(2) ; create table dbmsoutput ( pos int, mes varchar2(4000) );

上例中的代码:

declare
  b NUMBER(4);
  procedure put_line(p_mes in varchar2) is
     v_pos int; 
  begin  
     select count(0) into v_pos from dbmsoutput;  
     insert into dbmsoutput (pos, mes) values (v_pos, p_mes);
  end;

begin
  for c in (select a from t) loop
    put_line  (c.a);
  end loop;
end;
/

SELECT mes FROM dbmsoutput order by pos

<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
 <Triggers>
     <asp:Asyncpostbacktrigger controlid="ddlcategory" eventname="SelectedIndexChanged" />
   </Triggers>
       <ContentTemplate>
             <asp:DropDownList ID="ddlcategory" class="form-control txtboxmargin validate[required]" runat="server" 
               AutoPostBack="True" onselectedindexchanged="ddlcategory_SelectedIndexChanged" AppendDataBoundItems="True">
             <asp:ListItem Value="">--select category--</asp:ListItem>
           </asp:DropDownList>
       </ContentTemplate>

   </asp:UpdatePanel>

<asp:DropDownList ID="ddlpurity" 
               class="form-control txtboxmargin" AutoPostBack="True" runat="server"
               onselectedindexchanged="ddlpurity_SelectedIndexChanged">
           </asp:DropDownList>