PL/SQL How return all attributes in ROW

前端 未结 1 949
半阙折子戏
半阙折子戏 2021-01-21 08:45

I don\'t know how I can return all attributes with the RETURNING clause

I want something like this:

DECLARE  
    v_user USER%ROWTYPE  
 BEGIN  
     IN         


        
相关标签:
1条回答
  • 2021-01-21 09:20

    It would be neat if we could do something like that but alas:

    SQL> declare
      2      v_row t23%rowtype;
      3  begin
      4      insert into t23
      5          values (my_seq.nextval, 'Daisy Head Maisy')
      6          returning * into v_row;
      7  end;
      8  /
            returning * into v_row;
                      *
    ERROR at line 6:
    ORA-06550: line 6, column 19:
    PL/SQL: ORA-00936: missing expression
    ORA-06550: line 4, column 5:
    PL/SQL: SQL Statement ignored
    
    
    SQL>
    

    I believe there may be a logged change request for this feature, because I know lots of people want it. But for the moment all we can do is the long-winded specification of every column:

    SQL> declare
      2      v_row t23%rowtype;
      3  begin
      4      insert into t23
      5          values (my_seq.nextval, 'Daisy Head Maisy')
      6          returning id, person_name into v_row;
      7  end;
      8  /
    
    PL/SQL procedure successfully completed.
    
    SQL>
    

    Bad news if you have a lot of columns!

    I suspect the rationale is, most tables have relatively few derived columns (sequence assigned to an ID, sysdate assigned to a CREATED_DATE, etc) so most values should already be known (or at least knowable) to the inserting process.

    edit

    I was care how returning all attributes without long-winded specification of every column ;) Maybe it's impossible.

    I thought I had made it clear, but anyway: yes currently it is impossible to use * or some similar unspecific mechanism in a RETURNING clause.

    0 讨论(0)
提交回复
热议问题