--编写一个存过,输入一个数字和一个部门编号,
--要求数字必须是0-9的整数
--(如果不是抛出异常,报错'请输入0-9的整数')
--如果输入的编号emp1表不存在,抛出异常,报错'部门错误'
--当部门人数小于该数字,则将部门的员工信息插入到emp_kk,
--并打印插入了多少行
--当部门人数大于该数字,则将部门的员工姓名、
--员工编号删除,并打印删除了几个人
--当部门人数等于该数字,则更新该部门的
--员工工资/100之后再3次方,并打印更新了几个人的工资
create or replace procedure p4(v1 number,v2 number) is
err1 exception;
err2 exception;
v_count number;
begin
if v1 not in (0,1,2,3,4,5,6,7,8,9) then
raise err1;
end if;
select count(1) into v_count from emp1 where deptno=v2;
if v_count=0 then
raise err2;
end if;
if v_count < v1 then
insert into emp_kk select * from emp1 where deptno=v2;
dbms_output.put_line('插入了'||sql%rowcount||'行');
elsif v_count > v1 then
update emp1 set ename=null,empno=null where deptno=v2;
dbms_output.put_line('删除了'||sql%rowcount||'人');
else
update emp1 set sal=power(sal/100,3);
dbms_output.put_line('更新了'||sql%rowcount||'人的工资');
end if;
exception
when err1 then
raise_application_error(-20001,'请输入0-9的整数');
when err2 then
raise_application_error(-20002,'部门错误');
end;
call p4(5,30)