oracle11g函数,Oracle11g学习-sql/函数练习

Oracle--1、查询工作地点在纽约或波士顿的员工信息 地点在dept

select * from emp e where e.deptno in(select deptno from dept where loc='NEW YORK' or loc='BOSTON');

--3、查询工资比scott用户高的用户

select * from emp e where e.sal>(select e.sal from emp e where e.ename='SCOTT');

--4、查询部门名称为SALES或ACCOUNTING的员工信息

select * from emp e where e.deptno in(select d.deptno from dept d where d.dname='SALES' or d.dname='ACCOUNTING');

--5、查询每一个部门中工资最低的员工信息

select * from emp e,(select deptno ,min(sal) minSal from emp group by deptno) s where e.deptno=s.deptno and e.sal=s.minSal;

--6、查询员工中工资前三的员工信息(利用rownum)

select * from (select * from emp order by sal desc) s where rownum<=3

--7、查询工资大于本岗位平均工资的员工信息

select * from emp e ,(select job,avg(sal) avgSal from emp group by job) s where e.job=s.job and e.sal>s.avgSal;

--8、查询工资大于最小工资且小于最大工资的员工信息

select * from emp e,(select min(e.sal) minSal,max(e.sal) maxSal from emp e) s where e.sal>s.minSal and e.sal

declare

begin

for i in 1..9

loop

for j in i..9

loop

dbms_output.put(i||'*'||j||' ');

end loop;

dbms_output.put_line('');

end loop;

end;

--2、使用存储过程给scott所在的部门的员工全体涨300工资

create or replace procedure pro_scottDept_addSal

as

p_scottDeptno emp.deptno%type;

begin

select deptno into p_scottDeptno from emp where ename='SCOTT';

update (select sal,empno from emp e where e.deptno= p_scottDeptno) s set s.sal=s.sal+300;

end;

exec pro_scottDept_addSal();

select * from emp where deptno=20;

select * from dept;

--4、使用存储函数,在给定员工编号的情况下,返回该员工的工作地点

create or replace function fun_getAddress_byEmpno(

p_empno in emp.empno%type

)

return varchar2

as

p_deptno dept.deptno%type;

p_empAddress dept.loc%type;

begin

select deptno into p_deptno from emp where empno=p_empno;

select loc into p_empAddress from dept where deptno=p_deptno;

return p_empAddress;

end;

select fun_getAddress_byEmpno(7499) from dual;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值