Oracle 检索数据
SELECT? * ?| ? ?{ ? [?DISTINCT ?] ? ?column ? | ? ?expression ? [ ? alias ? ] ?, ? ... ? ?}
FROM? table;
column后面加上空格,同一時(shí)候跟上別名(alias),或者 as 別名。到下一行的內(nèi)容時(shí),要用逗號(hào)隔開(kāi)。
默認(rèn)的別名是小寫的。假設(shè)想要讓它是大寫的。使用 "別名"
假設(shè)別名有多個(gè)單詞的時(shí)候,用雙引號(hào)別名的方式 ? 比方 “annual ?salary”
select employee_id id, first_name name from employees; 結(jié)果:.....
? ? 193 Britney
? ? 194 Samuel
? ? ?id NAME
------- --------------------
? ? 195 Vance
? ? 196 Alana
? ? 197 Kevin
107 rows selected
連接符:
?把列與列,列與字符連接在一起。 ?用 ‘||’表示。 ?能夠用來(lái)‘合成’列。select last_name||' `s eamil is '||email from employees;
類似于Java中的System.out.println(123+ “hello” + 123) ;//123hello123
默認(rèn)情況下。查詢會(huì)返回所有行,包含反復(fù)行。
列的別名:
?重命名一個(gè)列。 ?便于計(jì)算。 ?緊跟列名,也能夠在列名和別名之間增加keyword‘AS’,別名使用雙引號(hào)。以便在別名中包括空格或特殊的字符并區(qū)分大寫和小寫。 SQL中僅僅有這兒用雙引號(hào)(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.
默認(rèn)的這樣的沒(méi)有引號(hào)的別名是大寫的
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.用雙引號(hào)的這樣的方式。能夠?qū)⑻厥獾淖址A粼谝玫膭e名中。同一時(shí)候大寫和小寫和列的別名一致
在SELECT子句中使用keyword‘DISTINCT’刪除反復(fù)行。
select distinct department_id from employees;
DEPARTMENT_ID
-------------
? ? ? ? ? 100
? ? ? ? ? ?30
? ? ? ? ? ?20
? ? ? ? ? ?70
? ? ? ? ? ?90
? ? ? ? ? 110
? ? ? ? ? ?50
? ? ? ? ? ?40
? ? ? ? ? ?80
? ? ? ? ? ?10
? ? ? ? ? ?60
12 rows selected
定義空值
?空值是無(wú)效的,未指定的,未知的或不可預(yù)知的值 ?空值不是空格或者0。
包括空值的數(shù)學(xué)表達(dá)式的值都為空值
SQL 語(yǔ)句與?SQL*Plus命令
Structural query language
SQL
?一種語(yǔ)言 ?ANSI 標(biāo)準(zhǔn) ?keyword不能縮寫 ?使用語(yǔ)句控制數(shù)據(jù)庫(kù)中的表的定義信息和表中的數(shù)據(jù)SQL*Plus
?一種環(huán)境?Oracle的特性之中的一個(gè) ?keyword能夠縮寫 ?desc employees,desc是sql plus的keyword,全稱是describe; ed也是sql plus的keyword ,全稱是edit ?命令不能改變數(shù)據(jù)庫(kù)中的數(shù)據(jù)的值 ?集中執(zhí)行
總結(jié):
1. 對(duì)于日期型數(shù)據(jù), 做 *, / 運(yùn)算不合法
2. 包括空值的數(shù)學(xué)表達(dá)式的值都為空值
3. 別名使用雙引號(hào)!
4. oracle 中連接字符串使用 "||", 而不是 java 中的 "+"
5. 日期和字符僅僅能在單引號(hào)中出現(xiàn). 輸出 last_name`s email is email
select last_name || ' `s email is ' || email EMAIL
from employees
6. distinct keyword, 下面語(yǔ)法錯(cuò)誤
select last_name, distinct department_id
from employees
習(xí)題:
?SQL*PLUS命令能夠控制數(shù)據(jù)庫(kù)嗎?否!SQL*PLUS僅僅是一個(gè)執(zhí)行環(huán)境,控制數(shù)據(jù)庫(kù)的是SQL語(yǔ)言。
總結(jié)
以上是生活随笔為你收集整理的Oracle 检索数据的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: CentOS7 安装LNMP(Linux
- 下一篇: SQL语句添加删除修改字段