【Oracle】存储过程和函数的使用

--1:创建一个存储过程,根据提供的雇员编号(作为过程的参数),将该雇员的佣金改为500;

--1:创建一个存储过程,根据提供的雇员编号(作为过程的参数),将该雇员的佣金改为500;
create or replace procedure update_sal(eno emp.empno%type)
is
begin
  update emp set sal=500 where empno=eno;
end;
exec update_sal(7788);
select * from emp;

 --2:创建一个存储过程,根据提供的雇员编号,查询该雇员的上级领导人的姓名,并返回。

--2:创建一个存储过程,根据提供的雇员编号,查询该雇员的上级领导人的姓名,并返回。
create or replace procedure getmname(eno emp.empno%type)
is 
vname emp.ename%type;
begin
  select ename into vname from emp where empno=(select mgr from emp where empno=eno);
  dbms_output.put_line(vname);
end;
exec getmname(7788);

 --3:创建一个存储过程,输入一个工资数,返回emp表中员工工资高于该工资的员工姓名、部门编号、工资和佣金。 

--3:创建一个存储过程,输入一个工资数,返回emp表中员工工资高于该工资的员工姓名、部门编号、工资和佣金。 
create or replace procedure getm(esal emp.sal%type)
is 
cursor my is select ename,deptno,sal,comm from emp where sal>esal;
begin
  for info in my loop
  dbms_output.put_line(info.ename||'  '||info.deptno||'   '||info.sal||'   '||info.comm);
  end loop;
end;
exec getm(1200);

 --4:写一个函数,传入员工编号,返回所在部门名称 

--4:写一个函数,传入员工编号,返回所在部门名称 
create or replace function getnum(eno emp.empno%type) return varchar
is
vname dept.dname%type;
dno dept.deptno%type;
begin
  select deptno into dno from emp where empno=eno;
  select dname into vname from dept where deptno=dno;
  return vname;
end;
select getnum(7788) from dual;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值