原创作品,出自 “深蓝的blog” 博客,深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/46908843
趣味SQL——创建指定的数据类型
在一篇文章上看到“提出过可以创建指定的数据类型”,于是想尝试着创建一下看看。
但是没有按预想的那样成功~~
create type MyName as object (first varchar2(20),second varchar2(20) );
create table newtype_test(
ID varchar2(32),
newname MyName
);
看一下创建的表结构:有两个列!
在查询数据看看效果:有三个列!
select * from newtype_test;
下面就是实验插入数据看看了,以命令行的方式插入,不成功,几次尝试如下:
SQL> insert into newtype_test(id,newname.first,newname.second) values(2,'shen','lan');
insert into newtype_test(id,newname.first,newname.second) values(2,'shen','lan')
ORA-00904: "NEWNAME"."SECOND":标识符无效
SQL> insert into newtype_test(id,newname.first,newname.second) values(2,shen,lan);
insert into newtype_test(id,newname.first,newname.second) values(2,shen,lan)
ORA-00984:列在此处不允许
SQL> insert into newtype_test(id,newname.first,newname.second) values(2,(shen),(lan));
insert into newtype_test(id,newname.first,newname.second) values(2,(shen),(lan))
ORA-00984:列在此处不允许
SQL> insert into newtype_test(id,newname) values(2,'shenlan');
insert into newtype_test(id,newname) values(2,'shenlan')
ORA-00932:数据类型不一致:应为 HYL.MYNAME,但却获得 CHAR
SQL> insert into newtype_test(id,newname) values(2,shenlan);
insert into newtype_test(id,newname) values(2,shenlan)
ORA-00984:列在此处不允许
SQL> insert into newtype_test(id,newname) values(2,(shen,lan));
insert into newtype_test(id,newname) values(2,(shen,lan))
ORA-00907:缺失右括号
SQL> insert into newtype_test(id,newname) values(2,(shen),(lan));
insert into newtype_test(id,newname) values(2,(shen),(lan))
ORA-00913: