国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Oracle > 正文

Oracle基礎學習之簡單查詢和限定查詢

2024-08-29 13:59:27
字體:
來源:轉載
供稿:網友

本文主要介紹的是關于Oracle中的簡單查詢和限定查詢,下面話不多說,來一起看看吧。

SQL:

     1,DML(數據操作語言):主要指的是數據庫的查詢與更新的操作,查詢操作是整個sql語法 中最麻煩也是筆試中最常用的部分。

     2,DDL(數據定義語言):主要指的是數據對象的創建(表、用戶、)例如:creat.需要相關的設計范式。

     3,DCL(數據控制語言):主要進行權限的操作(需要結合用戶來觀察),此部分由DBA負責。

簡單查詢:

1,利用select 子句控制要顯示的數據列:

 select empno,ename,ename,job,sal from emp;

2,可以使用distinct來消除重復的數據行顯示:

 select distinct job from emp;

3,select子句可以進行四則運算,可以直接輸出常量內容,但是對于字符串使用單引號數字直接編寫,日期格式按照字符格式:

select empno,ename,(sal*15+(200+100)) income from emp;

4,||負責輸出內容連接此類的操作很少直接在查詢中出現:

 select empno||ename from emp;

5,where子句一般都寫在from子句之后,但是是緊跟著from子句之后執行的,where子句控制顯示數據行的操作,而select控制數據列,select子句要落后于where子句執行,所以在select子句之中定義的別名無法在where中使用。

限定查詢:

1,關系運算符:

 select * from emp where sal>1500; select * from emp where ename ='SMITH' select empno,ename,job from emp where job<>'SALESMAN';

2,邏輯運算符:

 select * from emp where sal>1500 and sal<3000; select * from emp where sal>2000 or job='CLERK'; select * from emp where not sal >=2000;

3,范圍查詢:

 select * from emp where sal between 1500 and 2000; select * from emp where hiredate between '01-1月-1981'and'31-12月-1981';

4,空判斷(空在數據庫上表示不確定,如果在數據列使用null不表示0)

select * from emp where comm is not null;

5,IN操作符(類似于between and 而in給出的是指定的范圍):

 select * from emp where empno in (7369,7566,7788,9999);

關于not innull的問題:

在使用not in 進行范圍判斷的時候,如果范圍有null,那么不會有任何結果返回。

6,模糊查詢:

“-”:匹配任意一位字符;

“%”:匹配任意的0,1,,或者多位字符;

查詢姓名是以字母A開頭的雇員信息:

 select * from emp where ename like 'A%'

查詢姓名第二個字母是A的雇員信息:

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

查詢姓名任意位置是A的雇員信息:

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

查詢排序:

ASC(默認):按照升序排列;

DESC: 按照降序排列;

查詢所有的雇員信息,要求按照工資的由高到低:

 select * from emp order by sal desc;

查詢每個雇員的編號,姓名,年薪,按照年薪由低到高排序:

  select empno ,ename,sal*12 income from emp order by income;

語句的執行順序:from - where -select - order by

基礎練習:

1,選擇部門30中的所有員工:

 select * from emp where deptno=30;

2,列出所有辦事員(clerk)的姓名,編號,和部門編號:

select ename,empno,deptno from emp where job='CLERK';

3,找出傭金高于薪金的60%的員工:

 select * from emp where comm>sal*0.6 ;

4,找出部門10中所有的經理(manager)和部門20中所有的辦事員(clerk):

 select *  from emp  where (deptno=10 and job='MANAGER' )or(deptno=20 and job='CLERK'   );

5,找出部門10中所有的經理(manager),部門20中的所有辦事員(clerk),以及既不是經理又不是辦事員但是工資高于等于2000的所有員工資料:

 select * from emp where (deptno=10 and job='MANAGER')or(deptno=20 and job='CLERK')or(job! ='MANAGER'and job!='CLERK' and sal>=2000);
  select *  from emp  where (deptno=10 and job='MANAGER')or(deptno=20 and job='CLERK')or(job  not in ('CLERK','MANAGER') and sal>=2000);

6,找出收取傭金的員工的不同工作:

select distinct job from emp where comm is not null;

7,找出收取傭金或者收取的傭金低于100的員工:

  select distinct job  from emp where comm is null or comm<100;

8,顯示不帶有“R”的員工姓名:

 select * from emp where ename not like '%R%';

9,顯示姓名字段含有A的所有員工姓名,顯示的結果按照基本的工資由高到低,如果工資相同,則按照雇傭年限由早到晚,如果雇傭日期相同,則按職位排序:

 select * from emp where ename like '%A%' order by sal desc,hiredate asc,job;

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。


注:相關教程知識閱讀請移步到oracle教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 绥芬河市| 青海省| 平果县| 福鼎市| 临桂县| 沾化县| 大埔区| 西林县| 龙南县| 南宫市| 建平县| 南澳县| 马关县| 平顶山市| 富川| 玉溪市| 舞阳县| 章丘市| 河东区| 鄢陵县| 昭通市| 塔城市| 临清市| 罗平县| 九台市| 曲沃县| 红安县| 宜川县| 杭锦旗| 莱阳市| 潜江市| 建阳市| 昌乐县| 太谷县| 奇台县| 新安县| 湘潭市| 云浮市| 曲水县| 汾阳市| 阿图什市|