趣味SQL——创建指定的数据类型
原創(chuàng)作品,出自 “深藍(lán)的blog” 博客,深藍(lán)的blog:http://blog.csdn.net/huangyanlong/article/details/46908843?
?
趣味SQL——創(chuàng)建指定的數(shù)據(jù)類型
?
在一篇文章上看到“提出過能夠創(chuàng)建指定的數(shù)據(jù)類型”。于是想嘗試著創(chuàng)建一下看看。
可是沒有按預(yù)想的那樣成功~~
?
?create?type??MyName?as?object?(first?varchar2(20),second?varchar2(20) );
?
create?table? newtype_test(
ID?varchar2(32),
newname? MyName
);
?
看一下創(chuàng)建的表結(jié)構(gòu):有兩個(gè)列。
在查詢數(shù)據(jù)看看效果:有三個(gè)列!
select? *?from?? newtype_test;
?
?
以下就是實(shí)驗(yàn)插入數(shù)據(jù)看看了,以命令行的方式插入,不成功,幾次嘗試?yán)缫韵?#xff1a;
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":標(biāo)識(shí)符無效
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:數(shù)據(jù)類型不一致:應(yīng)為 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:缺失右括號(hào)
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:缺失逗號(hào)
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:缺失 VALUESkeyword
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":標(biāo)識(shí)符無效
嘗試了半天,也沒弄明確,怎么插入,于是嘗試了一下用工具插入數(shù)據(jù):
select?? *?from?? newtype_test?for??update;
?
居然成功插入了,查詢有值。例如以下:
?
于是,嘗試用工具逆向?qū)С霾迦胝Z句來看一看。例如以下:
?
粘貼后。例如以下所看到的:
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.
驗(yàn)證,按上面的書寫方式插入數(shù)據(jù)(這個(gè)方式之前事實(shí)上是試過的啊!
),果然。依然是不成功。
這是怎么回事呢?于是封建迷信的把這個(gè)變成腳本,運(yùn)行一下看看。例如以下:還是報(bào)錯(cuò)!
至此。重復(fù)嘗試幾次,通過PL/SQL Developer工具手工插入數(shù)據(jù)是可行的。但為什么用指令運(yùn)行就出問題了?是語法不正確嘛~~
(吐血中。
。
。
。
。。)
這就是SQL的趣味~~~~
最后,看一下,查詢結(jié)果:
能夠看到,在查詢newname這個(gè)字段時(shí),顯示出的的確是兩個(gè)拆分的列。
?
補(bǔ)充時(shí)間:2015年7月16日星期四
過來糾個(gè)錯(cuò)。上面的實(shí)驗(yàn)有點(diǎn)臆想了。我們查看一下官方文檔,看看正統(tǒng)的解釋是如何的:
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. TheCREATE TABLE statement inExample 2-6 creates an object table named departments_obj_t of the object typedepartment_typ. The attributes (columns) of this table are derived from the definition of the object type. TheINSERT 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的對(duì)象表。
假設(shè)上面的實(shí)驗(yàn)我們又一次來做一下,例如以下就能夠?qū)崿F(xiàn)了。
create?table? myname_test? ?OF?MyName;
SELECT?* ?FROM? myname_test;
insert?into? ?myname_test??VALUES? ?('huang', ?'yanlong');
--這次插入是能夠的
commit;
SELECT??*? ?FROM??myname_test;
小結(jié):
??????? Oracle對(duì)象類型是具有名稱、屬性、和方法的用戶定義類型。對(duì)象類型使得對(duì)現(xiàn)實(shí)世界中的實(shí)體(比如產(chǎn)品經(jīng)理和項(xiàng)目名稱等),作為對(duì)象在數(shù)據(jù)庫中進(jìn)行建模成為可能。對(duì)象表是一種特殊的表,當(dāng)中每一行表示一個(gè)對(duì)象。
?
補(bǔ)充時(shí)間:2015年7月16日星期四
過來糾個(gè)錯(cuò),上面的實(shí)驗(yàn)有點(diǎn)臆想了,我們查看一下官方文檔,看看正統(tǒng)的解釋是如何的:
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的對(duì)象表。假設(shè)上面的實(shí)驗(yàn)我們又一次來做一下。例如以下就能夠?qū)崿F(xiàn)了。
create??? table??? myname_test??? OF? ?MyName;
SELECT?? *??? FROM? ?myname_test;
insert?? into?? myname_test?? ?VALUES? ?('huang', 'yanlong');
--這次插入是能夠的
commit;
SELECT?? *?? FROM?? myname_test;
?
小結(jié):
?????? Oracle對(duì)象類型是具有名稱、屬性、和方法的用戶定義類型。對(duì)象類型使得對(duì)現(xiàn)實(shí)世界中的實(shí)體(比如產(chǎn)品經(jīng)理和項(xiàng)目名稱等),作為對(duì)象在數(shù)據(jù)庫中進(jìn)行建模成為可能。對(duì)象表是一種特殊的表,當(dāng)中每一行表示一個(gè)對(duì)象。
?
*******************************************藍(lán)的成長記系列****************************************************
原創(chuàng)作品。出自 “深藍(lán)的blog” 博客,歡迎轉(zhuǎn)載,轉(zhuǎn)載時(shí)請(qǐng)務(wù)必注明出處(http://blog.csdn.net/huangyanlong)。
藍(lán)的成長記——追逐DBA(1):奔波于路上,挺進(jìn)山東
藍(lán)的成長記——追逐DBA(2):安裝!安裝!久違的記憶。引起我對(duì)DBA的又一次認(rèn)知
藍(lán)的成長記——追逐DBA(3):古董上操作。數(shù)據(jù)導(dǎo)入導(dǎo)出成了問題
藍(lán)的成長記——追逐DBA(4):追憶少年情愁,再探oracle安裝(Linux下10g、11g)
藍(lán)的成長記——追逐DBA(5):不談技術(shù)談業(yè)務(wù),惱人的應(yīng)用系統(tǒng)
藍(lán)的成長記——追逐DBA(6): 做事與做人:小技術(shù),大為人
藍(lán)的成長記——追逐DBA(7):基礎(chǔ)命令,地基之石
藍(lán)的成長記——追逐DBA(8):重拾SP報(bào)告,回顧oracle的STATSPACK實(shí)驗(yàn)
藍(lán)的成長記——追逐DBA(9):國慶漸去。追逐DBA,新規(guī)劃。新啟程
藍(lán)的成長記——追逐DBA(10):飛刀防身。熟絡(luò)而非專長:擺弄中間件Websphere
藍(lán)的成長記——追逐DBA(11):回家后的安逸,暈暈乎乎醒了過來
藍(lán)的成長記——追逐DBA(12):七天七收獲的SQL
藍(lán)的成長記——追逐DBA(13):協(xié)調(diào)硬件廠商,六個(gè)故事:所見所感的“server、存儲(chǔ)、交換機(jī)......”
藍(lán)的成長記——追逐DBA(14):難忘的“云”端,起步的hadoop部署
藍(lán)的成長記——追逐DBA(15):以為FTP非常“簡(jiǎn)單”。誰成想一波三折
藍(lán)的成長記——追逐DBA(16):DBA也喝酒。被捭闔了
藍(lán)的成長記——追逐DBA(17):是分享。還是消費(fèi),在后IOE時(shí)代學(xué)會(huì)成長
******************************************************************************************************************
?
********************************************足球與oracle系列*************************************************
原創(chuàng)作品,出自 “深藍(lán)的blog” 博客。歡迎轉(zhuǎn)載,轉(zhuǎn)載時(shí)請(qǐng)務(wù)必注明出處(http://blog.csdn.net/huangyanlong)。
足球與oracle系列(1):32路諸侯點(diǎn)兵。oracle32進(jìn)程聯(lián)盟 之A組巴西SMON進(jìn)程的大局觀
足球與oracle系列(2):巴西揭幕戰(zhàn)預(yù)演。oracle體系結(jié)構(gòu)雜談
足球與oracle系列(3):oracle進(jìn)程排名,世界杯次回合即將戰(zhàn)罷!
足球與oracle系列(4):從巴西慘敗于德國,想到,差異的RAC拓?fù)鋵?duì)照!?
足球與oracle系列(5):fifa14游戲缺失的directX庫類比于oracle的rpm包!
足球與oracle系列(6):伴隨建庫的亞洲杯——加油中國隊(duì)
******************************************************************************************************************
轉(zhuǎn)載于:https://www.cnblogs.com/lytwajue/p/6755251.html
總結(jié)
以上是生活随笔為你收集整理的趣味SQL——创建指定的数据类型的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python蜕变-2017-4-23
- 下一篇: 由于昨天没发博客,在此向广大粉丝们道歉。