a test_type := test_type(); //初始化
create or replace procedure test_UNION(outelements in out test_type) is
....

解决方案 »

  1.   

    象cenlmmx(学海无涯苦作舟) 那样初始化不对啊.
      

  2.   

    看这样可不可以: a test_type := test_type(null,null);
      

  3.   

    a test_type := test_type(null,null); 也不行啊.
      

  4.   

    declare
    a test_type;
    begin
    a := test_type(null,null);
    test_union(a);
    dbms_output.put_line(a.aaa);
    end;create or replace procedure test_UNION(outelements out test_type) is
    begin
    begin
    select aaa,bbb
    into
    outelements.aaa, outelements.bbb
    from test01 where test01.id = 0;
    exception 
    when no_data_found then
    dbms_output.put_line('no data found');
    when too_many rows then
    dbms_output.put_line('too many data found');
    end;
    end test_UNION;
      

  5.   

    create or replace procedure test_UNION(outelements in out test_type)
      

  6.   

    执行
    declare
    a test_type;
    begin
    a := test_type(null,null);
    test_union(a);
    dbms_output.put_line(a.aaa);
    end;
    还是报这个错:
    ORA-06530: Reference to uninitialized composite
    ORA-06512: at "GE80.TEST_UNION", line 3
    ORA-06512: at line 5
      

  7.   

    SQL> create or replace type test_type as object
      2  (
      3         aaa   varchar2(20),
      4         bbb   varchar2(20)
      5  )
      6  /Type created.SQL> create table test01(
      2  id number(8),
      3  aaa varchar2(30),
      4  bbb varchar2(30)
      5  )
      6  /Table created.SQL> insert into test01 values(0,'1','2');1 row created.SQL> commit;Commit complete.SQL> set serveroutput on
    SQL> create or replace procedure test_UNION(outelements in out test_type) is
      2  begin
      3       select aaa,bbb into outelements.aaa, outelements.bbb
      4           from test01
      5            where test01.id = 0;
      6  end test_UNION;
      7  /Procedure created.SQL> declare
      2   a test_type:=test_type(null,null);
      3  begin
      4    test_union(a);
      5    dbms_output.put_line(a.aaa);
      6  end;
      7  /
    1PL/SQL procedure successfully completed.