Transwiki:SELECT:搜尋資料

  • Select 語句 Select 欄位 From 資料表
  1. Select * From loan – 選擇 loan 資料表內的所有欄位的內容– 在 Oracle 裡開啟資料表瀏覽,就相當於此行指令
  2. Select branch_name From loan – 從一個資料表選擇單一個欄位來看
  3. Select branch_name, loan_number From loan – 選擇多個欄位,欄位間用逗號分隔
  4. Select distinct branch_name From loan  – branch_name 欄位內若有重複的資料,也只會列出 一次,上頁第 2 語句會列出所有的資料
  5. Select loan_number, branch_name, amount*100 From loan  – 選擇出的欄位若為「數字」、「貨幣」型態,可做數 學運算後再列出– 選擇出的欄位若為「字串」型態,可串接其他字串再 列出
  • Where 子句句

Select 欄位 From 資料表 Where 判斷式

  1.   Select loan_number From loan Where branch_name=‘Perryridge’ –  列出分部(branch_name)為 Perryridge 的貸款代碼(loan_number)  –  判斷式的關係運算符號可為 =, >, <, >=, <=, <> 
  2.   Select loan_number From loan Where branch_name=‘Perryridge’ And amount>1200  –  Where 子句中有超過一個判斷式,可使用 And, Or, 或 Not 做邏輯運算
  3.   Select loan_number From loan Where amount Between 900 And

1000  –  可使用 Between .. And .. 的範圍運算 –  相當於 amount>=900 And amount<=1000 –  也可使用 Not Between .. And .. 運算