Oracle數(shù)據(jù)庫(kù)的數(shù)據(jù)類型有:1、字符char,固定長(zhǎng)度1-2000字節(jié);2、字符VARCHAR2,可變長(zhǎng)度1-4000字節(jié);3、長(zhǎng)字符LONG,可變長(zhǎng)度,最大2GB;4、數(shù)字NUMBER[(精度,[小數(shù)點(diǎn)位數(shù)])];5、日期DATE,存儲(chǔ)日期和時(shí)間部分,精確到秒;6、日期TIMESTAMP 存儲(chǔ)日期、時(shí)間和時(shí)區(qū),秒值精確到小數(shù)點(diǎn)后面6位;7、二進(jìn)制BLOB字段,存放較大的二進(jìn)制數(shù)據(jù)。等等注意:數(shù)值類型的值不需要加單引號(hào),時(shí)間和字符串類型需要加單引號(hào)。
主鍵:一個(gè)表中能唯一區(qū)分每一條記錄的字段,可以一個(gè)也可以多個(gè),可以作為其它表的外鍵;字段:數(shù)據(jù)庫(kù)表網(wǎng)格中的列,記作column;記錄:數(shù)據(jù)庫(kù)表網(wǎng)格中的行,記作row;外鍵:一個(gè)表中的某個(gè)字段的取值是另一表中的主鍵;唯一鍵:一個(gè)表中能唯一區(qū)分每一條記錄的字段,不能做外鍵。
增加一列:alter table wtemp add key_num int;設(shè)置列的值:update wtemp set key_num = 1;刪除一列:alter table wtemp drop column key_num;
表中有十條一樣的記錄,刪除其中九條,保留一條:1、create table temp as select * from wtemp where rownum = 1//創(chuàng)建一個(gè)臨時(shí)表,保存第一條記錄2、delete from wtemp where 1=1;//刪除原表中所有的記錄3、insert into wtemp select * from temp;//然后將臨時(shí)表中的記錄插入到原表中4、drop table temp;//刪除臨時(shí)表。
對(duì)于向oracle中同時(shí)插入多條數(shù)據(jù)的時(shí)候,只能同時(shí)寫對(duì)個(gè)Insert into語(yǔ)句,例如:insert into data values(1,to_date('2007-5-1','yyyy-mm-dd'),2,46);insert into data values(1,to_date('2007-5-1','yyyy-mm-dd'),2,46);
select stuidfrom Personwhere Sex='女' //where用于限定所有數(shù)據(jù)的條件group by stuidhaving count(*)>=1//having是用來限定分組內(nèi)的條件,一般都只是聚合函數(shù)
--內(nèi)連接查詢-----多表查詢時(shí)建議使用inner join(只查詢出兩個(gè)表stuID相等的記錄)select * from Personinner join Student on Person.StuID=Student.StuIDwhere Sex='女'
--左連接查詢(沒有關(guān)聯(lián)的部分為null)select * from Personleft join Student on Person.StuID=Student.StuID --右連接查詢(沒有與右表關(guān)聯(lián)的部分為null)select * from Personright join Student on Student.StuID=Person.StuID --全連接查詢(沒有關(guān)聯(lián)的部分為null)select * from Personfull join Student on Student.StuID=Person.StuID
--查詢結(jié)果用作查詢條件進(jìn)行比較運(yùn)算的時(shí)候,結(jié)果必須是一行一列的,可以0行一列(一一對(duì)應(yīng))select * from Person where Salary=(select MAX(salary) from person)select * from Person where Salary=(select salary from person where ID=1)
--查詢結(jié)果用作查詢條件進(jìn)行in查詢的時(shí)候,結(jié)果只能是多行一列的,可以是0行一列(一對(duì)多)select * from Person where StuID in (select StuID from Student)
select * from Personinner join(select StuID,AVG(salary) avgsalaryfrom Person group by StuID) PersonAvg on Person.StuID=PersonAvg.StuIDwhere Person.Salary<PersonAvg.avgsalary --工資小于平均值的人的信息
--any表示取其中的任意一條記錄select * from Personwhere StuID=2 and Salary>any(select Salary from Person where StuID=1)--大于其中最小的 --all表示取其中的所有的記錄select * from Personwhere StuID=2 and Salary>all(select Salary from Person where StuID=1)--大于其中最大的值
--exists表示數(shù)據(jù)存在select * from Personwhere exists(select * from Student)--exists判斷表中是否有數(shù)據(jù)存在 一般用 exists關(guān)聯(lián)查詢時(shí)比其它關(guān)聯(lián)查詢效率要高select * from Person pwhere exists(select * from Student s where p.StuID=s.StuID)
--union是將兩個(gè)查詢結(jié)果進(jìn)行合并,并且消除了重復(fù)行--上下兩個(gè)數(shù)據(jù)集的字段必須一致,而且數(shù)據(jù)類型也必須一致select * from Person where StuID=1unionselect * from Person where StuID=2
--條件語(yǔ)句,利用case when可以進(jìn)行條件匹配select id,revtime,max(case channel when 1 then val end) as channel1Val,max(case channel when 2 then val end) as channel1Val,max(case channel when 3 then val end) as channel1Valfrom data group by id, revtime
case channel when 1 then ....; when 2 then ....; else ....;end case;
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注