OCP之黄伟 2

Restricting and Sorting Data 

Objectives

After completing this lesson,you should be able to do the following:

  • Limit the rows that are retrieved by a query
  • Sort the rows that are retrieved by a query

Character Strings and Dates

列别名应当使用双引号

字符串拼接或者日期信息,以及where子句中的数据,需要使用单引号

  • Character strings and date values are enclosed by single quotation marks
  • Character values are case-sensitive,and date values are format-sensitive.
  • The default date format is DD-MON-RR.
SQL> SELECT last_name,job_id,department_id
  2  FROM employees
  3  WHERE last_name = 'Grant';

LAST_NAME                 JOB_ID     DEPARTMENT_ID
------------------------- ---------- -------------
Grant                     SH_CLERK              50
Grant                     SA_REP

SQL> SELECT last_name,job_id,department_id
  2  FROM employees
  3  WHERE last_name = 'grant';

no rows selected
View Code

Using the LIKE Condition

  • Use the LIKE condition to perform wildcard searches of valid search string values.
  • Search conditions can contain either literal character or numbers:
    • % denotes zero or many characrters.
    • _ denotes one character
  • You can combine pattern-matching characters
SELECT last_name FROM employees WHERE last_name LIKE '_o%';

 

  •  You can use the ESCAPE identifier to search for the actual % and _ symbols. 
SELECT employee_id,last_name,job_id
FROM employees
WHERE job_id LIKE '%SA\_%' ESCAPE '\';

 

 

Using the NULL Conditions

null value的比较只能使用IS NULL或者IS NOT NULL而不能使用=,<>符号进行比较.  

posted @ 2013-06-26 18:29  ArcerZhang  阅读(186)  评论(0编辑  收藏  举报