Oracle 基本SQL SELECT語句,oracleselect

來源:互聯網
上載者:User

Oracle 基本SQL SELECT語句,oracleselect

SELECT  *  |    {   [ DISTINCT  ]    column   |    expression   [   alias   ]  ,   ...    }

FROM  table;


•SELECT  標識 選擇哪些列。•FROM    標識從哪個表中選擇。

column後面加上空格,同時跟上別名(alias),或者 as 別名,到下一行的內容時,要用逗號隔開,

預設的別名是小寫,如果想要讓它是大寫的,使用 "別名"

如果別名有多個單詞的時候,用雙引號別名的方式   比如 “annual  salary”

select employee_id id, first_name name from employees;
結果:

.....

    193 Britney
    194 Samuel
     id NAME
------- --------------------
    195 Vance
    196 Alana
    197 Kevin
107 rows selected



串連符:

•把列與列,列與字元串連在一起。•用 ‘||’表示。•可以用來‘合成’列。

select last_name||' `s eamil is '||email from employees;

類似於Java中的System.out.println(123+ “hello” + 123) ;//123hello123

預設情況下,查詢會返回全部行,包括重複行。


在SELECT子句中使用關鍵字‘DISTINCT’重複資料刪除行。

select distinct department_id from employees;
DEPARTMENT_ID
-------------
          100
           30
           20
           70
           90
          110
           50
           40
           80
           10
           60
12 rows selected



SQL 語句與   SQL*Plus 命令

Structural query language

SQL

•一種語言•ANSI 標準•關鍵字不能縮寫•使用語句控制資料庫中的表的定義資訊和表中的資料


SQL*Plus

•一種環境
•Oracle的特性之一•關鍵字可以縮寫   desc employees,desc是sql plus的關鍵字,全稱是describe;ed也是sql plus的關鍵字 ,全稱是edit•命令不能改變資料庫中的資料的值•集中運行
總結:
1. 對於日期型資料, 做 *, / 運算不合法


2. 包含空值的數學運算式的值都為空白值


3. 別名使用雙引號!


4. oracle 中連接字串使用 "||", 而不是 java 中的 "+"


5. 日期和字元只能在單引號中出現. 輸出 last_name`s email is email


select last_name || ' `s email is ' || email EMAIL
from employees


6. distinct 關鍵字, 以下語法錯誤


select last_name, distinct department_id
from employees

習題:

 SQL*PLUS命令可以控制資料庫嗎?否!SQL*PLUS只是一個運行環境,控制資料庫的是SQL語言。



著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.