当前位置:Gxlcms > 数据库问题 > 趣味SQL——创建指定的数据类型

趣味SQL——创建指定的数据类型

时间:2021-07-01 10:21:17 帮助过:4人阅读

深蓝的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:值过多

SQL> insert into newtype_test(id,newname) values(2,(shen));

insert into newtype_test(id,newname) values(2,(shen))

ORA-00984:列在此处不允许

SQL> insert into newtype_test(id,newname(first,second)) values(2,(‘shen‘,‘lan‘));

insert into newtype_test(id,newname(first,second)) values(2,(‘shen‘,‘lan‘))

ORA-00917:缺失逗号

SQL> insert into newtype_test(id,newname,(first,second)) values(2,(‘shen‘,‘lan‘));

insert into newtype_test(id,newname,(first,second)) values(2,(‘shen‘,‘lan‘))

ORA-01747: user.table.column, table.column或列说明无效

SQL> insert into newtype_test(id,newname.(first,second)) values(2,(‘shen‘,‘lan‘));

insert into newtype_test(id,newname.(first,second)) values(2,(‘shen‘,‘lan‘))

ORA-01747: user.table.column, table.column或列说明无效

SQL> insert into newtype_test.newname.first values(‘shen‘);

insert into newtype_test.newname.first values(‘shen‘)

ORA-00926:缺失 VALUES关键字

SQL> insert into newtype_test.newname values (shen);

insert into newtype_test.newname values (shen)

ORA-00942:表或视图不存在

SQL> insert into newtype_test.newname values (shen,lan);

insert into newtype_test.newname values (shen,lan)

ORA-00942:表或视图不存在

SQL> insert into newtype_test.newname(first,second) values(shen,lan);

insert into newtype_test.newname(first,second) values(shen,lan)

ORA-00942:表或视图不存在

SQL> insert into newtype_test(hyl.tname.first,hyl.tname.second) values(1,2);

insert into newtype_test(hyl.tname.first,hyl.tname.second) values(1,2)

ORA-00904: "HYL"."TNAME"."SECOND":标识符无效

尝试了半天,也没弄明白,怎么插入,于是尝试了一下用工具插入数据:

select   *  from   newtype_test  for   update;

技术分享 

竟然成功插入了,查询有值,如下:

技术分享 

于是,尝试用工具逆向导出插入语句来看一看,如下:

技术分享 

粘贴后,如下所示:

prompt  Importing  table newtype_test...

set  feedback  off

set   define  off

insertinto  newtype_test (ID,  NEWNAME.FIRST,  NEWNAME.SECOND)

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

prompt  Done.

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

技术分享

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

技术分享

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

技术分享(吐血中。。。。。。)

这就是SQL的趣味~~~~

技术分享

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

技术分享

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

 

*******************************************蓝的成长记系列****************************************************

原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务必注明出处(http://blog.csdn.net/huangyanlong)。

蓝的成长记——追逐DBA(1):奔波于路上,挺进山东

蓝的成长记——追逐DBA(2):安装!安装!久违的记忆,引起我对DBA的重新认知

蓝的成长记——追逐DBA(3):古董上操作,数据导入导出成了问题

蓝的成长记——追逐DBA(4):追忆少年情愁,再探oracle安装(Linux下10g、11g)

蓝的成长记——追逐DBA(5):不谈技术谈业务,恼人的应用系统

蓝的成长记——追逐DBA(6): 做事与做人:小技术,大为人

蓝的成长记——追逐DBA(7):基础命令,地基之石

蓝的成长记——追逐DBA(8):重拾SP报告,回忆oracle的STATSPACK实验

蓝的成长记——追逐DBA(9):国庆渐去,追逐DBA,新规划,新启程

蓝的成长记——追逐DBA(10):飞刀防身,熟络而非专长:摆弄中间件Websphere

蓝的成长记——追逐DBA(11):回家后的安逸,晕晕乎乎醒了过来

蓝的成长记——追逐DBA(12):七天七收获的SQL

蓝的成长记——追逐DBA(13):协调硬件厂商,六个故事:所见所感的“服务器、存储、交换机......”

蓝的成长记——追逐DBA(14):难忘的“云”端,起步的hadoop部署

蓝的成长记——追逐DBA(15):以为FTP很“简单”,谁成想一波三折

蓝的成长记——追逐DBA(16):DBA也喝酒,被捭阖了

蓝的成长记——追逐DBA(17):是分享,还是消费,在后IOE时代学会成长

******************************************************************************************************************

 

********************************************足球与oracle系列*************************************************

原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务必注明出处(http://blog.csdn.net/huangyanlong)。

足球与oracle系列(1):32路诸侯点兵,oracle32进程联盟 之A组巴西SMON进程的大局观

足球与oracle系列(2):巴西揭幕战预演,oracle体系结构杂谈

足球与oracle系列(3):oracle进程排名,世界杯次回合即将战罢!

足球与oracle系列(4):从巴西惨败于德国,想到,差异的RAC拓扑对比! 

足球与oracle系列(5):fifa14游戏缺失的directX库类比于oracle的rpm包!

足球与oracle系列(6):伴随建库的亚洲杯——加油中国队

******************************************************************************************************************

版权声明:本文为博主原创文章,未经博主允许不得转载。

趣味SQL——创建指定的数据类型

标签:sql   趣味   

人气教程排行