Oracle record 和 object type 区别 及 选用

版权声明:本文为博主原创文章,转载请申明原文出处。 https://blog.csdn.net/xuheng8600/article/details/85456606

https://stackoverflow.com/questions/10848277/difference-between-object-and-record-type

Difference between object and record type

Ask Question 22 5

I am just curious whats the difference between object and record type in oracle, More specifically between the below declarations

create type emp2_oty is object 
(
 empno  number,
 ename  varchar2(20),
 deptno number
);

create type emp2_nt is table of emp2_oty;

and

type emp2_oty is record
(
 empno  number,
 ename  varchar2(20),
 deptno number
);

create type emp2_nt is table of emp2_oty;

Please elaborate.

oracle

shareimprove this question

edited Jul 3 '13 at 21:23

Doug Porter

6,75843253

asked Jun 1 '12 at 10:06

redsoxlost

60331123

  • 1

    basically, record is a pl/sql type, and object types are UDTs that can exist outside pl/sql. Which one you choose depends on your needs really. – tbone Jun 1 '12 at 11:30

  • Objects also have methods, while records only have fields; but the SQL vs. PL/SQL is more relevant here. – Alex Poole Jun 1 '12 at 11:44

add a comment

2 Answers

activeoldestvotes

10

The OBJECT type can be stored in the database and can be used in both SQL and PL/SQL

shareimprove this answer

answered Jun 1 '12 at 10:11

Jeffrey Vandenborne

275417

add a comment

29

  • record:

       Cannot be stored in the database.
       Cannot be recursively referenced.
       Cannot have logic defined as part of their definition.
  • object:

       Can be stored as a database table column or as an entire row.
       Can be recursively referenced using the SELF parameter.
       Can have logic defined as part of their definition using member methods.

记录:

无法存储在数据库中。

不能递归引用。

不能将逻辑定义为其定义的一部分。

对象:

可以存储为数据库表列或整行。

可以使用self参数递归引用。

可以使用成员方法将逻辑定义为其定义的一部分。

shareimprove this answer

answered Nov 6 '12 at 17:57

venu

32134

https://stackoverflow.com/questions/10848277/difference-between-object-and-record-type

http://www.itpub.net/thread-1882302-1-1.html

关于oracle中record与object的疑惑 

[复制链接]

weijunbo83

论坛徽章:

1

ITPUB 11周年纪念徽章 日期:2012-10-10 13:11:14

电梯直达跳转到指定楼层

1#

 发表于 2014-8-7 10:58 | 只看该作者 回帖奖励

本帖最后由 weijunbo83 于 2014-8-7 10:59 编辑

我的数据库版本是Oracle Database 10g Enterprise Edition Release 10.2.0.1.0, 在scott用户下执行如下语句,用于将删除的记录数据保存在nasted table中,使用record可以成功,没问题
DECLARE  
   TYPE emp_rec_type IS RECORD  
   (  
      empno      emp.empno%TYPE  
     ,ename      emp.ename%TYPE  
     ,hiredate   emp.hiredate%TYPE  
   );  
   TYPE nested_emp_type IS TABLE OF emp_rec_type;  
   emp_tab   nested_emp_type;  
BEGIN  
   DELETE FROM emp  
   WHERE  deptno = 20  
   RETURNING empno, ename, hiredate     -->使用returning 返回这几个列   
   BULK   COLLECT INTO emp_tab;         -->将前面返回的列的数据批量插入到集合变量     
end;


但是,如果我这里将record改为使用object就会出现问题,提示: 
ora-00947:not enough values;代码如下:
create or replace type emp_rec_type IS object
   (
      empno      NUMBER(4)
     ,ename      VARCHAR2(10)
     ,hiredate   DATE
   ); 

-------------------------------------------------------
DECLARE  
   TYPE nested_emp_type IS TABLE OF emp_rec_type;  
   emp_tab   nested_emp_type;  
BEGIN  
   DELETE FROM emp  
   WHERE  deptno = 20  
   RETURNING empno, ename, hiredate     -->使用returning 返回这几个列   
   BULK   COLLECT INTO emp_tab;         -->将前面返回的列的数据批量插入到集合变量     
end;


一时搞不清楚原因,通过搜索资料未果,请大牛帮我解惑;这个和数据库版本有关系吗?

Oraclerecordobject数据库版本

 

使用道具 举报

回复
   

Naldonado

论坛徽章:

168

SQL数据库编程大师 日期:2016-01-13 10:30:43SQL极客 日期:2013-12-09 14:13:35SQL大赛参与纪念 日期:2013-12-06 14:03:45最佳人气徽章 日期:2015-03-19 09:44:03现任管理团队成员 日期:2015-08-26 02:10:00秀才 日期:2015-07-28 09:12:12举人 日期:2015-07-13 15:30:15进士 日期:2015-07-28 09:12:58探花 日期:2015-07-28 09:12:58榜眼 日期:2015-08-18 09:48:03

2#

 发表于 2014-8-7 12:14 | 只看该作者

这样当然不行,object的类型,你要RETURNING emp_rec_type(empno, ename, hiredate)
 
 

使用道具 举报

回复
   

 

 

weijunbo83

论坛徽章:

1

ITPUB 11周年纪念徽章 日期:2012-10-10 13:11:14

3#

  楼主| 发表于 2014-8-8 09:33 | 只看该作者

Naldonado 发表于 2014-8-7 12:14 
这样当然不行,object的类型,你要RETURNING emp_rec_type(empno, ename, hiredate)

原来是这样,谢谢了。
 

http://www.itpub.net/thread-1882302-1-1.html

http://www.itpub.net/thread-1265785-1-1.html

请教create object 和type XXX is record有什么区别呢 

[复制链接]

autumn_leaf

论坛徽章:

5

ITPUB新首页上线纪念徽章 日期:2007-10-20 08:38:44数据库板块每日发贴之星 日期:2007-12-10 01:03:50ITPUB8周年纪念徽章 日期:2009-09-27 10:21:21鲜花蛋 日期:2012-03-24 10:51:55灰彻蛋 日期:2012-03-24 19:58:31

电梯直达跳转到指定楼层

1#

 发表于 2010-1-29 20:22 | 只看该作者 回帖奖励

请教create object 和type XXX is record有什么区别呢

createobjecttyperecord

 

使用道具 举报

回复
   

newkid

论坛徽章:

530

奥运会纪念徽章:垒球 日期:2008-09-15 01:28:12生肖徽章2007版:鸡 日期:2008-11-17 23:40:58生肖徽章2007版:马 日期:2008-11-18 05:09:48数据库板块每日发贴之星 日期:2008-11-29 01:01:02数据库板块每日发贴之星 日期:2008-12-05 01:01:03生肖徽章2007版:虎 日期:2008-12-10 07:47:462009新春纪念徽章 日期:2009-01-04 14:52:28数据库板块每日发贴之星 日期:2009-02-08 01:01:03生肖徽章2007版:蛇 日期:2009-03-09 22:18:532009日食纪念 日期:2009-07-22 09:30:00

2#

 发表于 2010-1-29 22:23 | 只看该作者

record 只能够用在PL/SQL中,OBJECT 可以用于SQL, 还可带成员函数;
record变量声明后可以直接使用,OBJECT还要执行初始化函数。
 
 

使用道具 举报

回复
   

guostong

论坛徽章:

38

授权会员 日期:2005-10-30 17:05:332012新春纪念徽章 日期:2012-02-13 15:12:09现任管理团队成员 日期:2011-11-07 09:46:59ITPUB十周年纪念徽章 日期:2011-11-01 16:19:41ITPUB9周年纪念徽章 日期:2010-10-08 09:31:21版主3段 日期:2012-05-15 15:24:112009新春纪念徽章 日期:2009-01-04 14:52:282010新春纪念徽章 日期:2010-03-01 11:06:202009日食纪念 日期:2009-07-22 09:30:00祖国60周年纪念徽章 日期:2009-10-09 08:28:00

3#

 发表于 2010-1-29 22:24 | 只看该作者

http://www.itpub.net/thread-1157164-1-1.html
 

http://www.itpub.net/thread-1265785-1-1.html

http://www.itpub.net/thread-1157164-1-1.html

bject和records 

[复制链接]

zjj1002

论坛徽章:

1

2011新春纪念徽章 日期:2011-02-18 11:42:49

电梯直达跳转到指定楼层

1#

 发表于 2009-4-27 11:46 | 只看该作者 回帖奖励

如题,create type zjj as object (n number);
type zjj is record(.....);
这2句有什么区别啊?
另外有create table zjj1 of zjj;这种用法吗?
书上看来的,不懂
希望各位大大能给我解个疑,谢谢!~

objectrecordscreatetypenumber

 

使用道具 举报

回复
   

lee_defei

论坛徽章:

6

数据库板块每日发贴之星 日期:2009-04-29 01:01:02数据库板块每日发贴之星 日期:2009-05-03 01:01:02数据库板块每日发贴之星 日期:2009-05-04 01:01:02数据库板块每日发贴之星 日期:2009-05-11 01:01:02数据库板块每日发贴之星 日期:2009-05-17 01:01:03ITPUB9周年纪念徽章 日期:2010-10-08 09:31:21

2#

 发表于 2009-4-28 23:57 | 只看该作者

最直接的区别是,create type zjj as object (n number);
这个可以建立一个数据的类型对象,以后可以在其他地方引用,而type zjj is record仅仅是声明一种类型,只能在存储过程里面使用  create table zjj1 of zjj 这个用法是有的

http://www.itpub.net/thread-1157164-1-1.html

猜你喜欢

转载自blog.csdn.net/xuheng8600/article/details/85456606
今日推荐