PL/SQL How return all attributes in ROW

谁都会走 提交于 2019-12-20 02:42:33

问题


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  
     INSERT INTO User 
     VALUES (1,'Bill','QWERTY') 
     RETURNING * INTO v_user;  
END;

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


回答1:


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.



来源:https://stackoverflow.com/questions/2889250/pl-sql-how-return-all-attributes-in-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!