標籤:nbsp 知識 長度 having 預設 基於 學習資料庫 from 運算
Oracle資料庫由甲骨文公司開發,是基於對象的關係型資料庫;下面是簡單的學習資料庫操作等知識。
1.SQL單表查詢(設一個表名為tab)
(1)查詢所有記錄
select * from tab(一般格式:使用者名稱.表名;如果不輸入使用者名稱,則預設為目前使用者)。
(2)查詢某些欄位
select f_z from tab (f_z為查詢欄位,可以查詢多個欄位,以‘,’隔開)。
(3)distinct(返回不同值)
select distinct f_z from tab (distinct必須放在前面,可以查詢多個欄位,以‘,’隔開)。
(4)單條件查詢
select * from tab where f_z like ‘47%’(1.in(not in)、like(not like)、between(not between)、is null(is not null)運算子;2.like和not like適合字元型欄位查詢;3.%表示任意長度字串,_表示一個長度的字串。4.f_z是欄位)。
(5)組合條件查詢(and、or、not)
select * from tab where f_z = 2 and f_y > 100
select * from tab where f_d not like ‘%47%’
select * from tab where not f_m like ‘47%‘
(6)排序查詢
select * from tab order by f_z(Asc(預設)為升序排列,Desc降序排列;order by 要放在where語句後面)。
(7)分組查詢
select f_z,f_a from tab group by f_z,f_a having f_z is not null(where檢查每條記錄是否符合條件;having檢查分組後的各組是否滿足條件,having只能與group by配合使用)。
(8)欄位運算查詢(+、-、*、/)
select ‘汽車名稱--’|| f_z from tab(||字串合并)。
(9)變換查詢顯示
select f_z as f_a from tab(as命名欄位的別名,可以不用;group by不能用別名,order by可以用。)。
表別名不用as,例如:select t.f_z from tab t。
for update用於鎖定行,例如:select for update
Oracle資料庫學習(一)