PL/SQL 如何返回 ROW 中的所有属性

PL/SQL How return all attributes in ROW(PL/SQL 如何返回 ROW 中的所有属性)
本文介绍了PL/SQL 如何返回 ROW 中的所有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何使用 RETURNING 子句返回所有属性

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

我想要这样的东西:

DECLARE  
    v_user USER%ROWTYPE  
 BEGIN  
     INSERT INTO User 
     VALUES (1,'Bill','QWERTY') 
     RETURNING * INTO v_user;  
END;

RETURNING * INTO 出错,如何替换 * ?

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!

我怀疑其基本原理是,大多数表的派生列相对较少(分配给 ID 的序列,分配给 CREATED_DATE 的 sysdate 等),因此大多数值应该已经知道(或至少知道)插入过程.

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.

编辑

我很关心如何归还所有属性不啰嗦每列的规格;)也许这是不可能的.

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

我以为我已经说清楚了,但无论如何:是的,目前不可能在 RETURNING 子句中使用 * 或一些类似的非特定机制.

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.

这篇关于PL/SQL 如何返回 ROW 中的所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)