新手向 Oracle常用查詢例項(一)

2021-09-30 13:39:45 字數 3954 閱讀 3534

以下查詢均只涉及scott使用者下的emp表

1.查詢scott使用者下的所有表

> select * from tabs;
2.查詢雇員表中的全部資訊

> select * from emp;
3.查詢雇員編號,姓名,工作,工資。

> select empno,ename,job,sal from emp;
4.查詢雇員編號,姓名,工作,工資,列表標題需中文顯示。

> select empno 編號, ename 姓名, job 工作, sal 工資 from emp;
5.查詢雇員工作種類。

> select distinct job from emp;
6.查詢所有雇員編號,姓名,工作.按以下格式顯示:編號:7369-姓名:smith-工作:clerk (返回乙個列)

> select  '編號:' || empno || '-姓名:' || ename || '-工作:' || job as 詳情 from emp;
7.查詢雇員編號,姓名,工作,年薪

> select empno,ename,job,(sal + nvl(comm,0))*12 yearlysalary from emp;
8.查詢工資大於1500的雇員所有資訊

> select * from emp where sal >1500;
9.查詢可以得到獎金的雇員的名字與獎金

> select ename,comm from emp where nvl(comm,0)>0;

> select ename,comm from emp where decode(comm,null,0,comm) > 0;

10.查詢工資大於1500或可以得到獎金的雇員

> select ename from emp where sal > 1500 or nvl(comm,0) > 0;

> select ename from emp where sal > 1500 or decode(comm,null,0,comm) > 0;

11.查詢工資大於1500並且可以領取獎金的雇員

> select ename from emp where sal > 1500 and nvl(comm,0) > 0;

> select ename from emp where sal > 1500 and decode(comm,null,0,comm) > 0;

12.查詢工資不大於1500或者不可以領取獎金的雇員

> select ename from emp where sal <= 1500 or nvl(comm,0) = 0;
13.查詢工資在1500到3000的所有雇員資訊

> select * from emp where sal >=1500 and sal <= 3000;
14.查詢系統當前時間

> select sysdate from dual;
15.查詢在2023年雇用的員工資訊

> select * from emp where hiredate like '%81%';

> select * from emp where to_char(hiredate,'yyyy') = '1981';

> select * from emp where hiredate <= to_date('1981-12-31','yyyy-mm-dd') and hiredate >= to_date('1981-01-01','yyyy-mm-dd');

> select * from emp where hiredate between to_date('1981-01-01','yyyy-mm-dd') and to_date('1981-12-31','yyyy-mm-dd');

16.查詢雇員姓名中第三個字母為」a」的雇員資訊

> select * from emp where ename like '__a%';
17.查詢雇員編號為7369的雇員資訊

> select  * from emp where empno = '7369';
18.查詢雇員編號不為7369的雇員資訊

> select  * from emp where empno != '7369';

> select * from emp where empno <> '7369';

19.查詢編號是7369,7900的雇員資訊

> select * from emp where empno in (7369,7900);
20.查詢編號不是7369,7900的雇員資訊

> select * from emp where empno not in (7369,7900);
21.查詢雇員資訊,按工資由低到高排序

> select * from emp order by sal;

> select * from emp order by sal asc;

22.查詢雇員資訊,按工資由高到低排序

> select * from emp order by sal desc;
23.請查詢沒有領導的員工名和職位

> select ename,job from emp where mgr is null;
24.查詢有領導的員工名和職位

> select ename,job from emp where mgr is not null;
25.查詢所有員工名、職位以及領導名

> select e1.ename,e1.job,e2.ename from emp e1,emp e2 where e1.mgr = e2.empno(+);
26.查詢部門30中的所有員工資訊

> select * from emp where deptno = 30;
27.列出所有辦事員(clerk)的姓名,編號和部門編號(按部門編號公升序排列)

> select ename,empno,deptno from emp where job = 'clerk' order by deptno;
28.找出佣金高於薪金的員工

> select * from emp where nvl(comm,0) > sal;
29.找出佣金低於薪金的40%的員工資訊

> select * from emp where nvl(comm,0) < sal*0.4;
30.找出部門10中所有經理(manager)和部門20中所有辦事員(clerk)的詳細資料

> select *  from emp  where deptno = '10' and job = 'manager'  union   select *  from emp where job = 'clerk' and deptno = '20';

> select * from emp where (deptno = '10' and job = 'manager') or (job = 'clerk' and deptno = '20');

新手向 stl常用容器介紹

1 容器的基本概念 stl庫為許多常用的資料結構提供了通用的模板,我們叫它容器。顧名思義,容器可以用來儲存資料,其中的資料可以是預定義型別,如int double,也可以是自定義型別。容器類中的元素自動申請記憶體,不需要new和delete。新增了相應的標頭檔案後容器就可以直接使用了。宣告乙個容器的...

oracle常用查詢

查詢庫表中大資料量的表 select owner,segment name,sum bytes 1024 1024 m from dba segments where segment type in table index and owner bomc2 group by segment name,...

oracle常用查詢

select from dba users 檢視所有使用者 select from user all tables 查詢當前使用者表空間 select from user source 查詢所有函式和儲存過程 select from v session 檢視當前使用者連線 select from s...