Oracle資料庫學習(三)

來源:互聯網
上載者:User

標籤: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資料庫學習(三)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.