【问题标题】:fast fetching data using table function oracle apex使用表函数 oracle apex 快速获取数据
【发布时间】:2018-12-14 12:05:41
【问题描述】:

有没有办法解决“ORA-01422 fetch return more than requested number of >rows”而不使用 for 循环来返回表函数的值?使用 for 循环获取数据以将该数据用于 oracle 应用程序使用 APEX 会变慢。

【问题讨论】:

    标签: oracle plsql oracle11g plsqldeveloper oracle-apex-5


    【解决方案1】:

    您可以针对 ORA-01422 使用 DISTINCTGROUP BY 并列出所有应为的行不使用 LOOP 而返回,但只有一个 INTO,如下例所示:

    SQL> create table tab( col1 int, col2 varchar2(50) );
    
     Table created
    SQL> insert all
    2         into tab values(1,'abc')
    3         into tab values(1,'abc')
    4         into tab values(2,'def')
    5  select * from dual;
    
    3 rows inserted
    SQL> set serveroutput on;
    SQL> 
    SQL> declare
      2    v_col1 tab.col1%type;
      3    v_col2 tab.col2%type;
      4  begin
      5    select t.col1, t.col2
      6      into v_col1, v_col2
      7      from tab t
      8     where t.col1 = 1;
      9  
     10     dbms_output.put_line(v_col1||'  '||v_col2);
     11  end;
     12  /     
    
    ORA-01422: exact fetch returns more than requested number of rows
    ORA-06512: at line 6
    
    SQL> 
    SQL> declare
      2    v_col1 tab.col1%type;
      3    v_col2 tab.col2%type;
      4  begin
      5    select t.col1, t.col2
      6      into v_col1, v_col2
      7      from tab t
      8     where t.col1 = 1
      9     group by t.col1, t.col2;
     10  
     11     dbms_output.put_line(v_col1||'  '||v_col2);
     12  end;
     13  /
    
    1  abc
    
    PL/SQL procedure successfully completed
    
    SQL> 
    SQL> declare
      2    v_col1 tab.col1%type;
      3    v_col2 tab.col2%type;
      4  begin
      5    select distinct t.col1, t.col2
      6      into v_col1, v_col2
      7      from tab t
      8     where t.col1 = 1;
      9  
     10     dbms_output.put_line(v_col1||'  '||v_col2);
     11  end;
     12  /
    
    1  abc
    
    PL/SQL procedure successfully completed
    

    【讨论】:

    • 嗯,是的 - 这适用于您创建的示例数据。但是,请尝试使用额外的insert into tab values (1, 'def');。我并不是说您写的内容错误,而是我们没有足够的信息来提供正确答案。我认为 OP 应该提供更多信息。
    • 这在我创建表类型以输出结果时有效。返回类型为 object 时如何进行 into 或批量 collect into。创建或替换可编辑类型“CS_OBJ”作为对象(CS1 VARCHAR2(6000),CS2 VARCHAR2(100))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 1970-01-01
    • 1970-01-01
    • 2011-06-19
    • 2013-10-24
    • 1970-01-01
    相关资源
    最近更新 更多