--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;