Oracle條件查詢

2021-09-24 04:22:46 字數 1210 閱讀 9913

條件查詢 

關係運算子: > < = <= >= != <>

邏輯運算子: and or not

其他運算子: like 模糊查詢

in(set) 在某個區間內

between .. and.. 在某個區間內

is not 判斷為空

is not null 判斷不為空

----查詢每月能得到獎金的員工資訊

select * from emp;

select * from emp where comm is not null;

----查詢工資在1500-3000之間的員工資訊

select * from emp where sal between 1500 and 3000;

select * from emp where sal >= 1500 and sal <= 3000;

----查詢名字在某個範圍內的員工資訊('jones','scott','ford')

select * emp where ename in ('jones','scott','ford');

模糊查詢:like

% 匹配多個字元

_匹配單個字元

如果有特殊字元需要使用escape轉義

-----查詢員工姓名第三個名字是o的員工資訊

select * from emp where ename like '__o%';

----查詢員工姓名中,包含%的員工資訊

update emp set ename = 'tur%ner' where ename = 'turner';

select * from emp where ename like '%\%%' escape '\';

排序:order by

公升序:asc ascend

降序:desc descend

排序注意null問題,nulls 預設是first 需要的話可以改為last

如果同時排列多列,,中間用,隔開

----查詢員工資訊,按照獎金由高到低排序

select * from emp order by comm desc nulls last;

----查詢部門編號和工資,按照部門公升序排序,工資降序排序

select deptno,sal from emp order by deptno asc, sal desc;

Oracle 條件查詢 模糊查詢

示例 1 查詢出工資高於3000的員工資訊 select froms emp e where e.salary 3000 2 查詢出名為carmen的員工所有資訊 select from s emp e wheree.first name carmen oracle sql 關鍵字,表名,列名等不區...

Oracle基礎條件查詢

當我們要組合三個或者三個以上條件的時候,就需要用到小括號 來表示應該如何進行條件運算。例如,編寫乙個複雜的條件 工資在5000以下或者10000以上,並且是job id為sa man 按多個條件查詢employees 如果不加括號,條件運算按照not and or的優先順序進行 not優先順序最高,...

Oracle連線查詢條件分析

oracle 對謂詞and t1.job clerk on 後面的 where t1.job clerk 的解析是不一樣的。一 使用where t1.job clerk 1 access t1 deptno t2 deptno 2 filter t1 job clerk oracle 先根據 t1 ...