oracle where order by,ORACLE SQL WHERE和ORDER BY
第二章:限制(where子句)和排列數據(order by子句)
限制數據訪問:
使用數字做條件
select ename,sal,deptno from emp where DEPTNO=10;
使用字符做條件,字符串要單引,大小寫敏感!
select ename,sal,deptno from emp where ename='king';
select ename,sal,deptno from emp where ename='KING';
使用日期做條件,格式敏感!
select ename,hiredate from emp where hiredate='23-JAN-82';
借助系統函數查看系統日期格式:
select sysdate from dual;
select * from nls_database_parameters;
在where條件中使用單行比較符號
> , < , = ,>= ,<= ,<> !=
在where條件中使用邏輯運算
and , or , not
檢索符合下列條件的數據:
工資大于2000的雇員
工資大于2000并且小于3000的雇員
工資大于2000或者小于1000的雇員
特殊比較符:
between and 相當于 ( >= and <= )
select ename,sal from emp where sal between 2000 and 3000;
in (set list): 枚舉方式取數據,in后面跟隨一個集合列表!
select ename,sal from emp where sal in (1000,2000,3000);
like : 能夠做模糊匹配
select ename from emp where ename like 'M%';
select ename,hiredate from emp where hiredate like '';
select ename from emp where ename like '_L%';
select ename from emp where ename like '_ _%' escape ' ';
is null (is not null) : 過濾空值
select ename,comm from emp where comm is null;
select ename,comm from emp where comm is not null;
補充:在查詢中使用rownum偽列,rownum是結果集的編號!
select rownum,ename from emp;
select * from emp where rownum<6;
排列結果集:
升序排列結果集
select ename,sal from emp order by sal;
降序排列結果集
select ename,sal from emp order by sal desc;
對別名排序
select ename,sal*12 ann_sal from emp order by ann_sal;
多列排序
select ename,deptno,sal from emp order by deptno desc,sal desc;
select ename,deptno,sal from emp order by 2,3 desc;
select * from emp order by 5;
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的oracle where order by,ORACLE SQL WHERE和ORDER BY的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 异常php有必要吗,关于php异常的问题
- 下一篇: oracle11g ora 29927,