趣味SQL——创建指定的数据类型
原創作品,出自 “深藍的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:值過多
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:缺失 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":標識符無效
嘗試了半天,也沒弄明確,怎么插入,于是嘗試了一下用工具插入數據:
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這個字段時,顯示出的的確是兩個拆分的列。
?
補充時間: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. 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的對象表。
假設上面的實驗我們又一次來做一下,例如以下就能夠實現了。
create?table? myname_test? ?OF?MyName;
SELECT?* ?FROM? myname_test;
insert?into? ?myname_test??VALUES? ?('huang', ?'yanlong');
--這次插入是能夠的
commit;
SELECT??*? ?FROM??myname_test;
小結:
??????? Oracle對象類型是具有名稱、屬性、和方法的用戶定義類型。對象類型使得對現實世界中的實體(比如產品經理和項目名稱等),作為對象在數據庫中進行建模成為可能。對象表是一種特殊的表,當中每一行表示一個對象。
?
補充時間: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對象類型是具有名稱、屬性、和方法的用戶定義類型。對象類型使得對現實世界中的實體(比如產品經理和項目名稱等),作為對象在數據庫中進行建模成為可能。對象表是一種特殊的表,當中每一行表示一個對象。
?
*******************************************藍的成長記系列****************************************************
原創作品。出自 “深藍的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):協調硬件廠商,六個故事:所見所感的“server、存儲、交換機......”
藍的成長記——追逐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):伴隨建庫的亞洲杯——加油中國隊
******************************************************************************************************************
轉載于:https://www.cnblogs.com/lytwajue/p/6755251.html
總結
以上是生活随笔為你收集整理的趣味SQL——创建指定的数据类型的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python蜕变-2017-4-23
- 下一篇: ESB--转