創(chuàng)建了兩張表和一些問題 , 基本上把oracle的基礎(chǔ)語句都用上了, 適合新手練習(xí)與鞏固知識. 可以自己在oracle中創(chuàng)建表然后練習(xí).沒有可視化界面的可以用我下面準(zhǔn)備好的語句直接導(dǎo)入. EMP表 DEPT表 員工表建表語句: CREATE TABLE EMP ( 部門表建表語句: CREATE TABLE DEPT ( 員工表插入數(shù)據(jù): INSERT INTO EMP VALUES ('Zhou潤發(fā)', 10001, 10, '辦事員', TO_DATE('20161130131322', 'YYYYMMDDHH24MISS'), 2500, 2400); 部門表插入數(shù)據(jù): INSERT INTO DEPT VALUES ('市場部', 10, '北京'); 兩張表已全部建好,自己用查詢語句查看一下表結(jié)構(gòu)和數(shù)據(jù)是否沒問題. Select * From EMP Select * From DEPT 下面是題目:可以復(fù)制下來做, 做完再和我做答案對照一下, 當(dāng)然, 有的題目可以用多種方法去做, 看你自己選擇了. 還有一點需要注意的是:我是用的可視化界面輸入的語句,別名中文不需要加引號,一開始我加引號老是報錯,后來無意間去掉反而好了,不知道為什么.我開始學(xué)的時候,別名使用中文是需要加引號的,看你實際的情況吧!! 題目: --1.選擇30部門的職員 答案: 1-- select ename,deptno from emp where deptno=30; select e.ename,e.empno,d.dname,e.job from emp e,dept d where e.deptno=d.deptno and e.job='辦事員'; select * from emp where comm>sal order by comm desc; 4-- select * from emp where comm>sal*0.6; select * from emp e,dept d where e.deptno=10 and e.job='經(jīng)理' and e.deptno=d.deptno select * from emp e,dept d where (e.deptno=10 and e.job='經(jīng)理' and e.deptno=d.deptno) select * from emp e,dept d where e.sal>=2000 and e.job<>'辦事員' and e.job<>'經(jīng)理' and e.deptno=d.deptno; select distinct job from emp where comm>0; select ename,nvl(comm,0) comms from emp where nvl(comm,0)<2000; select * from emp where hiredate=last_day(hiredate); select * from emp where months_between(sysdate,hiredate)>12; select * from emp where hiredate<add_months(sysdate,-12); select * from emp where ename=initcap(ename); select * from emp where length(ename)=7; select * from emp where instr(ename,'Z')=0; select substr(ename,0,3) from emp select replace(ename,'Z','z') from emp select ename,add_months(hiredate,12) from emp select * from emp e,dept d where e.deptno=d.deptno order by e.ename select ename,trunc(months_between(sysdate,hiredate)/12,0) 服務(wù)年限 from emp order by 服務(wù)年限 desc select ename,hiredate from emp order by hiredate select ename,job,sal from emp order by job desc,sal asc select ename,extract(year from hiredate) 年份,extract(month from hiredate) 月份 from emp order by 年份,月份 select ename,to_char(hiredate,'yyyy') 年份,to_char(hiredate,'mm') 月份 from emp order by hiredate select ename,sal/30,trunc(sal/30,1),floor(sal/30),ceil(sal/30) from emp select * from emp where extract(month from hiredate)=1 select * from emp where to_char(hiredate,'mm')='01' select ename,floor(sysdate-hiredate) 入職天數(shù) from emp order by 入職天數(shù) desc select ename from emp where ename like '%i%'; select ename from emp where instr(ename,'i')>0 select ename,floor(months_between(sysdate,hiredate)/12) 服務(wù)總年數(shù), floor(months_between(sysdate,hiredate)) 服務(wù)總月數(shù), floor(sysdate-hiredate) 服務(wù)總天數(shù) from emp order by 服務(wù)總天數(shù); 最后送上一句勵志的話 ~~ |
|