欢迎投稿

今日深度:

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;


 

 

\\

 

 

www.htsjk.Com true http://www.htsjk.com/oracle/23608.html NewsArticle 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 perfo...
评论暂时关闭