开发者

PL/SQL How return all attributes in ROW

开发者 https://www.devze.com 2022-12-31 12:58 出处:网络
I don\'t know how I can return all attributes with the RETURNING clause I want something like this: DECLARE

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  
     INSER开发者_StackOverflowT INTO User 
     VALUES (1,'Bill','QWERTY') 
     RETURNING * INTO v_user;  
END;

RETURNING * INTO gets an error , how can I replace * ?


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.


So far the best solution I believe could be:

DECLARE  
    v_user USER%ROWTYPE;
    rowid_v rowid;
 BEGIN  
     INSERT INTO User 
     VALUES (1,'Bill','QWERTY') 
     RETURNING ROWID INTO rowid_v; 

     SELECT * INTO v_user WHERE rowid = rowid_v ;
END;

https://oracle-base.com/articles/misc/dml-returning-into-clause

Unfortunately, still there is no such functionality as returning * or returning row :) but will be cool.

0

精彩评论

暂无评论...
验证码 换一张
取 消