Home  >  Article  >  Database  >  oracle 基本语句练习(一) where, between ,null, like,转义字符,

oracle 基本语句练习(一) where, between ,null, like,转义字符,

WBOY
WBOYOriginal
2016-06-07 15:31:091033browse

1 where 筛选关键字; select * from emp where job 'CLERK' 从emp表中列出 job大于'CLERK'的项 (由于比较的是字符串,所以加单引号) 2 between and select ename,sal from emp where sal between 800 and 1500 从emp表中找到 sal在800和1500之间的项(包括800

1   where  筛选关键字;


    select * from emp where job >'CLERK'

    从emp表中列出 job值大于'CLERK'的项 (由于比较的是字符串,所以加单引号)


2  between  and


   select ename,sal from emp where sal between 800 and 1500 


    从emp表中找到 sal值在800和1500之间的项(包括800和1500) 列出他们的ename 和sal


3 空值

   select ename,sal from emp where comm is null  ;

   

  列出非空值

  select ename,sal from emp where comm is  not  null  ;


4 模糊查询

   查询ename中包含ALL的项

  select  ename from emp where ename like '%ALL%' ;

   %代表0个或多个字符,  次查询目的为了找到ename 值为 ALL 左边和右边具有0个或多个字符的项


   查询ename第二个字母为A 的项

 select  ename from emp where ename like '_A%' ;


5  转义字符 

    查找ename中带有 % 的项

select  ename from emp where ename like '%$%%'  escape '$' ;

  指定'$'为转义字符查找% .


  转义字符默认为'/'  使用/ 为转义字符时不用写后面的escape ..


6 排序order by

  

     select * from dept  order by deptno ; (默认升序)

    select * from dept  order by deptno desc ;(按deptno的降序排序)


  组合使用:

 select  empno,ename from emp where empno 10 order by empno;   (先过滤 再排序)


 select  empno,ename from emp order by empno asc,ename desc; 按(empno升序排序)  empno相同时按ename 降序排序

 

   


  

  

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn