--1创建一个存储过程,以员工号为参数,输出该员工的工资。
set serveroutput on
create or replace procedure show(p_no emp.empno%type)
as
v_sal emp.sal%type;
begin
select sal into v_sal from emp where empno=p_no;
dbms_output.put_line(v_sal);
exception
when no_data_found then
dbms_output.put_line('there is not such employee');
end;
/
--调用过程
begin
show(2010);
end;
/
--2 创建一个存储过程,以员工号为参数,
-- 修改该员工的工资。若该员工属于10号部门,
-- 则工资增加140元;若属于20号部门,则工资增加200元;
-- 若属于30号部门,则工资增加250元;若属于其他部门,则工资增长300元。
set serveroutput on
create or replace procedure show2(p_no emp.empno%type)
as
v_dno emp.deptno%type;
v_inc number;
begin
select deptno into v_dno from emp where empno=p_no;
case v_dno
when 10 then v_inc:=140;
when 20 then v_inc:=200;
when 30 then v_inc:=250;
else v_inc:=300;
end case;
update emp set sal=sal+v_inc where empno=p_no;
exception
when no_data_found then
dbms_output.put_line('there is not such an employees');
end;
/
--在调用前后查看一下
select sal,empno,deptno from emp where empno&
Oracle 11g数据库基础教程(第2版)-课后习题-第十章
最新推荐文章于 2022-04-10 18:31:51 发布