Oracle 第2節 過濾和排序資料,oracle第2節

來源:互聯網
上載者:User

Oracle 第2節過濾和排序資料,oracle第2節

LessonAim

While retrieving data from the database, you may need to restrict the rows of data that are displayed or specify the order in which the rows are displayed. 

This lesson explains the SQL statements that youuse to perform these actions.


•在查詢中過濾行。
•在查詢中對行進行排序。

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

FROM  table

[WHERE  condition(s)];

•WHERE 子句緊隨 FROM子句。


SELECT employee_id,last_name,job_id,department_id

FROM   employees

WHERE  department_id = 90 ;




•字元和日期要包含在單引號中。•字元大小寫敏感,日期格式敏感。

SELECTlast_name,job_id,department_id

FROM   employees

WHERE  last_name = 'Whalen';


SELECTlast_name,hire_date,department_id

FROM   employees

WHERE  hire_date ='7-6-1994'

日期以特定的格式書寫!



SELECT last_name, salary

FROM   employees

WHERE  salary <= 3000;






1.

SELECT last_name, salary

FROM  employees

WHERE salary BETWEEN 2500 AND 3500;


2.

SELECT employee_id,last_name, salary,manager_id

FROM   employees

WHERE  manager_id IN (100, 101, 201);


•使用 LIKE運算選擇類似的值•選擇條件可以包含字元或數字:–% 代表零個或多個字元(任意個字元)。_代表一個字元

3.

SELECT  first_name

FROM   employees

WHERE  first_name LIKE 'S%';



4.

SELECT last_name

FROM   employees

WHERE  last_name LIKE '_o%';



•可以使用 ESCAPE 標識符選擇‘%’和‘_’符號。

•迴避特殊符號的:使用轉義符。例如:將[%]轉為[\%]、[_]轉為[\_],然後再加上[ESCAPE ‘\’] 即可。

SELECT job_id

FROM   jobs

WHERE  job_id LIKE ‘IT\_%‘ escape ‘\;


5.

使用IS (NOT)NULL判斷空值。


SELECT last_name,manager_id

FROM   employees

WHERE  manager_id IS NULL;








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

相關文章

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.