Oracle 模糊查詢與高階連線查詢

2021-07-24 07:35:17 字數 2332 閱讀 3166

//查詢薪水在2000-3000之間的員工資訊

select * from emp where sal>=2000

and sal<=3000l

orselect * from emp where sal 2000

and3000;

//查詢沒有上級的員工資訊

select * from emp where mgr is

null;

//查詢薪水高於2000或者崗位為clerk的員工資訊,同時還要滿足其姓名首字母為'j'的資訊

select * from emp where (sal>2000

or job='clerk') and ename like

'j%';

//內連線查詢(返回兩張表共同的資料)

select * from 表1

inner

join 表2

on 表1.公共列 = 表2.公共列;

select * from 表1

left

join 表2

on 表1.公共列 = 表2.公共列;

select * from 表1

right

join 表2

on 表1.公共列 = 表2.公共列;

select * from 表1

full

join 表2

on 表1.公共列 = 表2.公共列;

select * from 表1,表2

where 表1.公共列 = 表2.公共列;

//查詢員工『smith』的上級領導姓名

//方式一 子查詢

select * from emp where empno = (select mgr from emp where ename='smith');

//方式二 乙個查詢結果作為乙個新錶

select * from (select mgr from emp where ename='smith') 上級表 inner

join emp on 上級表.mgr = emp.empno;

//方式三

select * from emp,(select mgr from emp where ename='smith') 上級表 where emp.empno = 上級表.mgr;

//單行子查詢:返回乙個值的子查詢 = > < >= <=

//查詢與『smith』同部門的員工

select * from emp where deptno = (select deptno from emp where emp.ename='smith');

//查詢與部門10號員工同崗位的員工

select * from emp where job in (select job from emp where deptno=10)

//查詢與'smith'同部門崗位的員工

select * from emp where (deptno.job) = (select deptno,job from emp where ename='smith');

//內聯檢視子查詢:將子查詢的結果作為另乙個查詢的資料來源

//查詢薪水最低的5個員工的資訊

//注:因為rownum是先序列再排序,不能直接select * from 表名 order //by列 where rownum<5,所以先把排序的結果集在rownum序列一次

select rownum,t1.* from (select emp.* from emp order

by sal asc) t1 where rownum<=5;

//查詢員工資訊表1-5行的資料

select t1.* from (select rownum r,emp.* from emp where rownum <=10) t1 where r>5

and r<=10;

//每頁有多少行(pagecount),當前第幾頁(page)

select t1.* from (select rownum r,emp.* from

where rownum<=pagecount*page) t1 where r>pagecount*(page-1) and r<=pagecount*page;

Oracle 模糊查詢

在where子句中,可以對datetime char varchar欄位型別的列用like子句配合萬用字元選取那些 很像.的資料記錄,以下是可使用的萬用字元 零或者多個字元 單一任何字元 下劃線 特殊字元 在某一範圍內的字元,如 0 9 或者 aeth 不在某範圍內的字元,如 0 9 或者 aeth...

oracle 模糊查詢

oracle10g以上支援正規表示式的函式主要有下面四個 1,regexp like 與like的功能相似 2,regexp instr 與instr的功能相似 3,regexp substr 與substr的功能相似 4,regexp replace 與replace的功能相似 posix 正規表...

oracle模糊查詢

執行資料庫查詢時,有完整查詢和模糊查詢之分。一般模糊語句格式如下 select 字段 from 表 where 某欄位 like 條件 其中,關於條件,sql提供了四種匹配模式 1 表示零個或多個字元。可以匹配任意型別和任意長度的字元,有些情況下若是中文,請使用兩個百分號 表示。比如 select ...