標籤:to_date nvl values HERE upd oracl 結構 sysdate user
6.關於null
資料庫中null是一個未知數,沒有任何值;進行運算時使用nvl,但是結果仍為空白;在聚集合函式中只有全部記錄為空白才會返回null。
7.insert插入
(1)單行記錄插入
insert into tab (f_z,f_a) values (1,to_date(‘2017-10-11’,’yyyy-mm-dd’)).
文法:文法insert into 資料表(欄位名1,欄位名2,……) values(欄位名1的值, 欄位名2的值,……)。
欄位名和值要一一對應,時間日期要用單引號,非空列必須要有值對應。
(2)多行記錄插入
insert into table1 (f_id, f_m, f_r) select table2.nextval as f_id, ‘new user‘, sysdate from table1 where f_r <= to_date(‘2017-10-01‘, ‘yyyy-mm-dd‘).
文法:insert into 資料表(欄位名1,欄位名2,……) (select(欄位名1或運算, 欄位名2或運算,……) from 資料表 where 條件)。
子查詢和insert中的資料表既可以相同,也可以不同,但要求查詢結果的欄位和insert插入的資料表中欄位屬性完全一致。
8.delete
delete from tab where f_a >= 5;truncate table table1;truncate是刪除整個表,並且刪除後不能恢複資料,但是保留資料表結構;delete刪除資料可以恢複。
9.update
直接賦值更新:1)文法:update tab set f_a = new1,f_b = new2... where 條件;
2)update tab set f_a = ‘新名稱’where f_id = 2。
嵌套更新:1)文法:set 欄位名1=(select 欄位列表 from 資料表 where 條件),欄位名2=(select 欄位列表 from 資料表 where 條件),……。
2)update table1 set table1.f_a=(select table2.f_b from table2 where table1.f_id=table2.f_id) where table1.f_id=5。
10.merge into
Merge into table1 using table2 on(table1.f_id=table2.f_id) when matched then update set table1.f_a = ‘new’ when not matched then insert(table1.f_id) values(table2.f_id)
Oracle資料庫學習(三)