Oracle系列:(6)where子句

來源:互聯網
上載者:User

標籤:oracle



查詢emp表中20號部門的員工資訊

select * from emp where deptno = 20;


查詢姓名是SMITH的員工,字串使用‘‘,內容大小寫敏感

select * from emp where ename = ‘SMITH‘;

總結:你所學過的技術中,哪些是大小寫敏感,哪些是大小寫不敏感

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/86/EF/wKiom1fPCe7RWSW3AAAYHml8RBY341.png" title="001.PNG" alt="wKiom1fPCe7RWSW3AAAYHml8RBY341.png" />


查詢1980年12月17日入職的員工,注意oracle預設日期格式(DD-MON-RR表示2位的年份)

select * from emp where hiredate = ‘17-12月-80‘;


查詢工資大於1500的員工

select * from emp where sal > 1500;


查詢工資不等於1500的員工【!=<>

select * from emp where sal <> 1500;


查詢薪水在1300到1600之間的員工,包括1300和1600 【between應用於數字

select * from emp where (sal>=1300) and (sal<=1600);

select * from emp where sal between 1300 and 1600;


查詢薪水不在1300到1600之間的員工,不包括1300和1600 【not between

select * from emp where sal NOT between 1300 and 1600;


查詢入職時間在"1981-2月-20"到"1982-1月-23"之間的員工【between應用於日期

select * from emp where hiredate between ‘20-2月-81‘ and ‘23-1月-82‘;

650) this.width=650;" src="http://s4.51cto.com/wyfs02/M02/86/EF/wKiom1fPDHPxM2F9AAA1PsY6e7c508.png" title="002.PNG" alt="wKiom1fPDHPxM2F9AAA1PsY6e7c508.png" />


注意:

1)對於數值型,小數值在前,大數值在後

2)對於日期型,年長值在前,年小值在後



查詢20號或30號部門的員工,例如:根據ID號,選中的員工,大量刪除【in

select * from emp where (deptno=20) or (deptno=30);

select * from emp where deptno in (30,20);


查詢不是20號或30號部門的員工【not in

select * from emp where deptno NOT in (30,20);


查詢姓名以大寫字母S開頭的員工,使用%表示0個,1個或多個字元【like模糊查詢

select * from emp where ename like ‘S‘;

等價

select * from emp where ename = ‘S‘;

select * from emp where ename like ‘S%‘;

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M00/86/EE/wKioL1fPDerQZlPIAAAPqHq8dcs256.png" title="003.PNG" alt="wKioL1fPDerQZlPIAAAPqHq8dcs256.png" />


注意:

凡是精確查詢用=符號

凡是不精確查詢用like符號,我們通常叫模糊查詢


 

查詢姓名以大寫字母N結束的員工

select * from emp where ename like ‘%N‘;


查詢姓名第一個字母是T,最後一個字母是R的員工

select * from emp where ename like ‘T%R‘;


查詢姓名是4個字元的員工,且第二個字元是I,使用_只能表示1個字元,不能表示0個或多個字元

select * from emp where ename like ‘_I__‘;

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/86/EF/wKiom1fPDuej1A_GAAAMLxxqu0k717.png" title="004.PNG" alt="wKiom1fPDuej1A_GAAAMLxxqu0k717.png" />


插入一條姓名為‘T_IM‘的員工,薪水1200

insert into emp(empno,ename) values(1111,‘T_IM‘);


查詢員工姓名中含有‘_‘的員工,使用\轉義符,讓其後的字元迴歸本來意思【like ‘%\_%‘ escape ‘\‘】

select * from emp where ename like ‘%\_%‘ escape ‘\‘;

650) this.width=650;" src="http://s5.51cto.com/wyfs02/M00/86/EF/wKiom1fPEQKCxFdvAAARRmROt5g708.png" title="005.PNG" alt="wKiom1fPEQKCxFdvAAARRmROt5g708.png" />


插入一個姓名叫‘的員工

insert into emp(empno,ename) values(2222,‘‘‘‘);


插入一個姓名叫‘‘的員工

insert into emp(empno,ename) values(2222,‘‘‘‘‘‘);

650) this.width=650;" src="http://s5.51cto.com/wyfs02/M00/86/EE/wKioL1fPEhGy1dceAAAMTGLGlds859.png" style="float:none;" title="006.PNG" alt="wKioL1fPEhGy1dceAAAMTGLGlds859.png" />

650) this.width=650;" src="http://s5.51cto.com/wyfs02/M00/86/EE/wKioL1fPEhHhAi0ZAABHgY-8y84483.png" style="float:none;" title="007.PNG" alt="wKioL1fPEhHhAi0ZAABHgY-8y84483.png" />


查詢所有員工資訊,使用%或%%

select * from emp;select * from emp where ename like ‘%‘;select * from emp where ename like ‘%_%‘;


查詢傭金為null的員工【is null

select * from emp where comm is null;

650) this.width=650;" src="http://s5.51cto.com/wyfs02/M01/86/EF/wKiom1fPEybRs8h8AAA6V_3wphw310.png" title="008.PNG" alt="wKiom1fPEybRs8h8AAA6V_3wphw310.png" />


注意:null不能參與=運算

      null能參與number/date/varchar2類型運算


查詢傭金為非null的員工【is not null

select * from emp where comm is not null;


查詢無傭金且工資大於1500的員工

select * from emp where (comm is null) and (sal>1500);


查詢工資是1500或3000或5000的員工 

select * from emp where sal in (4000,10000,1500,3,300,3000,5000);


查詢職位是"MANAGER"或職位不是"ANALYST"的員工(方式一,使用!=或<>)

select *from empwhere (job=‘MANAGER‘) or (job<>‘ANALYST‘);


查詢職位是"MANAGER"或職位不是"ANALYST"的員工(方式二,使用not)

select *from empwhere (job=‘MANAGER‘) or (not(job=‘ANALYST‘));









Oracle系列:(6)where子句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.