Oracle 检索数据
SELECT? * ?| ? ?{ ? [?DISTINCT ?] ? ?column ? | ? ?expression ? [ ? alias ? ] ?, ? ... ? ?}
FROM? table;
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
默認情況下。查詢會返回所有行,包含反復行。
列的別名:
?重命名一個列。 ?便于計算。 ?緊跟列名,也能夠在列名和別名之間增加keyword‘AS’,別名使用雙引號。以便在別名中包括空格或特殊的字符并區分大寫和小寫。 SQL中僅僅有這兒用雙引號(double quotation)SELECT last_name AS name,commission_pctcomm
FROM?? employees;
SELECT last_name "Name", salary*12 "AnnualSalary"
FROM??employees;
The first example displays the names and the commission percentages of all the employees. Notice that theoptionalASkeyword has been used before the columnalias?name. The result of the query is the same whether the AS keyword is used or not. Also notice that the SQL statement has the column aliases, name and comm, in lowercase, whereas the result of the querydisplays the column headings inuppercase. As mentioned in a previous slide, column headingsappear inuppercase by default.
默認的這樣的沒有引號的別名是大寫的
Thesecond example displays the last names and annual salaries of all the employees.Because Annual Salarycontain a space, it has been enclosed in double quotation marks. Notice thatthe column heading in the output is exactly the same as the column alias.用雙引號的這樣的方式。能夠將特殊的字符保留在引用的別名中。同一時候大寫和小寫和列的別名一致
在SELECT子句中使用keyword‘DISTINCT’刪除反復行。
select distinct department_id from employees;
DEPARTMENT_ID
-------------
? ? ? ? ? 100
? ? ? ? ? ?30
? ? ? ? ? ?20
? ? ? ? ? ?70
? ? ? ? ? ?90
? ? ? ? ? 110
? ? ? ? ? ?50
? ? ? ? ? ?40
? ? ? ? ? ?80
? ? ? ? ? ?10
? ? ? ? ? ?60
12 rows selected
定義空值
?空值是無效的,未指定的,未知的或不可預知的值 ?空值不是空格或者0。
包括空值的數學表達式的值都為空值
SQL 語句與?SQL*Plus命令
Structural query language
SQL
?一種語言 ?ANSI 標準 ?keyword不能縮寫 ?使用語句控制數據庫中的表的定義信息和表中的數據SQL*Plus
?一種環境?Oracle的特性之中的一個 ?keyword能夠縮寫 ?desc employees,desc是sql plus的keyword,全稱是describe; ed也是sql plus的keyword ,全稱是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 keyword, 下面語法錯誤
select last_name, distinct department_id
from employees
習題:
?SQL*PLUS命令能夠控制數據庫嗎?否!SQL*PLUS僅僅是一個執行環境,控制數據庫的是SQL語言。
總結
以上是生活随笔為你收集整理的Oracle 检索数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CentOS7 安装LNMP(Linux
- 下一篇: SQL语句添加删除修改字段