oracle資料庫實訓(1)

2021-09-24 21:53:49 字數 3950 閱讀 8944

用的是11g版本

--解鎖

alter user scott account unlock

--設定密碼

alter user scott identified by tiger

--授權

grant dba to scott

用scott使用者登入,利用已有的表進行實驗

查詢語句:

1.員工的實發工資

--nvl(x,y) if x == null 則返回y

--nvl(null,0)

select e.ename,nvl(e.sal,0)+nvl(e.comm,0) as 實發工資 from emp e;

2.實發工資大於3000

select e.ename, e.job from emp e

where nvl(e.sal,0)+nvl(e.comm,0) > 3000;

tip:

--nvl(x,y) if x == null 則返回y

--nvl(null,0)

--round(x,n) x保留n位小數 四捨五入

--trunc(x,n) x保留n位小數 只舍

--ceil(x) 返回大於或等於x的最大整數

--floor(x) 返回等於或小於x的最大整數

3.工資大於等於1500小於等於3000的雇員全部資訊

--1

select * from emp e

where e.sal+nvl(e.comm,0) >= 1500 and e.sal+nvl(e.comm,0) <= 3000;

--2select * from emp e

where e.sal+nvl(e.comm,0) between 1500 and 3000;

4.查詢員工編號、員工姓名以及員工的日基本工資、月基本工資、年基本工資

select e.empno, e.ename, 

e.sal*12 as 年基本工資, e.sal as 月基本工資, round(e.sal/30,2) as 日基本工資, '¥' as 貨幣

from emp e;

5.把員工編號和員工姓名連線作為員工資訊

select '雇員編號:' || e.empno || '雇員姓名:' || e.ename as 雇員資訊 from emp e;
tip:oracle 資料庫用   ||  作為連線符

6.查詢所有領取佣金的員工的完整資訊

select * from emp e

where e.comm is not null;

7.查詢雇員編號是7369、7788、7566的員工的完整資訊

--1

select * from emp e

where e.empno = 7369 or e.empno = 7788 or e.empno = 7566;

--2select * from emp e

where e.empno in (7369,7788,7566);

8.--查詢雇員編號是7369、7788、7566之外的的員工的完整資訊

--1

select * from emp e

where e.empno not in (7369,7788,7566);

--2select * from emp e

where not (e.empno = 7369 or e.empno = 7788 or e.empno = 7566);

9.查詢出姓名以s開頭的所有員工資訊

select * from emp e

where e.ename like 's%';

tip:like 模糊查詢

%  匹配任意個任意字元

_   匹配乙個任意字元

10.查詢出姓名以s結尾的所有員工資訊

select * from emp e

where e.ename like '%s';

11.查詢出姓名中第二個字元是m的所有員工資訊

select * from emp e

where e.ename like '_m%';

12.查詢出姓名中有l的所有員工資訊

select * from emp e

where e.ename like '%l%';

13.查詢工資大於1200的員工姓名和基本工資

select e.ename, e.sal from emp e

where e.sal+nvl(e.comm,0) > 1200;

14.查詢員工號為7934的員工的姓名和部門號

select e.ename, e.deptno from emp e

where e.empno = 7934;

15.選擇工資不在5000到12000的員工的姓名和工資

select e.ename, e.sal from emp e 

where e.sa+nvl(e.comm,0)l < 5000 or

e.sal+nvl(e.comm,0) > 12000;

16. 選擇雇用時間在1981-02-01到1981-05-01之間的員工姓名,職位(job)和雇用時間,按從早到晚排序.

select e.ename, e.job, e.hiredate from emp e

where e.hiredate between

to_date('1981-02-01','yyyy-mm-dd')

and to_date('1981-05-01','yyyy-mm-dd')

order by e.hiredate asc;

select e.ename, e.job, e.hiredate from emp e

where to_char(e.hiredate,'yyyy-mm-dd') between '1981-02-01' and '1981-05-01'

order by e.hiredate asc;

tip:

to_date('x','b') x是要進行轉化的字串 b是要轉換的格式

to_char(x,'b') x是date型別的日期 b是要轉換的格式

b的格式: y表示年  y表示年的最後一位 yy表示年的最後兩位 以此類推

mm表示月

dd表示月的第幾天 ddd表示年的第幾天 dy表示周的第幾天

17.選擇在20或10號部門工作的員工姓名和部門號

select e.ename, e.deptno from emp e

where e.deptno in(10,20);

18.選擇公司中沒有管理者的員工姓名及job

select e.ename, e.job from emp e

where e.mgr is null;

19.選擇公司中有獎金 (comm不為空,且不為0) 的員工姓名,工資和獎金比例,按工資逆排序,獎金比例逆排序. 

select e.ename, e.sal, e.comm from emp e

where e.comm is not null and e.comm != 0

order by e.sal desc, e.comm desc;

tip:

多個排序用逗號分隔

排序中列名可用as指定的別名

排序預設公升序

Oracle實訓筆記1

1 desc 列出表定義,列出pl sql語句定義。2 disc 斷開連線。conn scott tiger orcl 連線 3 passw 更改密碼 4 nvl 函式的使用,處理null。sal nvl comm,0 即當comm為null時,將它看成0,當不是null時,將其忽略。5 如果列別名...

資料探勘實訓週報1

資料探勘實訓週報1 本階段工作內容 報名官網 二 配置本機環境。三 學習資料探勘涉及的主要python包。1.numpy 學習鏈結1 學習鏈結2 numpy提供了大量的庫函式和操作,主要用於對多維陣列執行計算,以及對影象的處理和其他數 算。基本操作 import numpy as np array ...

實訓筆記1

actioncontext com.opensymphony.xwork.actioncontext 是action執行時的上下文,上下文可以看作是乙個容器 其實我們這裡的容器就是乙個map而已 它存放放的是action在執行時需要用到的物件,比如 在使用webwork時,我們的上下文放有請求的引數...