趣味SQL――创建指定的数据类型(二)

2015-07-21 16:27:32 · 作者: · 浏览: 23
ECOND)

values ('1','huang','yanlong');

prompt Done.

验证,按上面的书写方式插入数据(这个方式之前其实是试过的啊!),果然,依旧是不成功。

\

这是怎么回事呢?于是封建迷信的把这个变成脚本,执行一下看看,如下:还是报错!

\

至此,反复尝试几次,通过PL/SQL Developer工具手工插入数据是可行的。但为什么用指令执行就出问题了?是语法不对嘛~~

\(吐血中。。。。。。)

这就是SQL的趣味~~~~

\

最后,看一下,查询结果:

\

可以看到,在查询newname这个字段时,显示出的的确是两个拆分的列。

?

补充时间:2015年7月16日星期四

过来纠个错,上面的实验有点臆想了,我们查看一下官方文档,看看正统的解释是怎样的:

Object Tables

An Oracle object type is a user-defined type with a name, attributes, and methods. Object types make it possible to model real-world entities such as customers and purchase orders as objects in the database.

An object type defines a logical structure, but does not create storage. Example 2-5 creates an object type named department_typ.

Example 2-5 Object Type

CREATE TYPE department_typ AS OBJECT

( d_name VARCHAR2(100),

d_address VARCHAR2(200) );

/

An object table is a special kind of table in which each row represents an object. The CREATE TABLE statement in Example 2-6 creates an object table named departments_obj_t of the object type department_typ. The attributes (columns) of this table are derived from the definition of the object type. The INSERT statement inserts a row into this table.

Example 2-6 Object Table

CREATE TABLE departments_obj_t OF department_typ;

INSERT INTO departments_obj_t

VALUES ('hr', '10 Main St, Sometown, CA');

Like a relational column, an object table can contain rows of just one kind of thing, namely, object instances of the same declared type as the table. By default, every row object in an object table has an associated logical object identifier (OID) that uniquely identifies it in an object table. The OID column of an object table is a hidden column.

oracle的对象表。如果上面的实验我们重新来做一下,如下就可以实现了。

create table myname_test OF MyName;

SELECT * FROM myname_test;

\

insert into myname_test VALUES ('huang', 'yanlong');

--这次插入是可以的

commit;

SELECT * FROM myname_test;

\

小结:

Oracle对象类型是具有名称、属性、和方法的用户定义类型。对象类型使得对现实世界中的实体(例如产品经理和项目名称等),作为对象在数据库中进行建模成为可能。对象表是一种特殊的表,其中每一行表示一个对象。