练手、练手

create or replace procedure p_employee_hire(resultinfo out testpackage.test_cursor)
is
d_department_name varchar2(20);
d_requirement_num number;
d_re number:=0;
sd_re number:=0;
u_user_id varchar2(20);
u_user_point number(3,1);
u_first_wish varchar2(20);
u_second_wish varchar2(20);
--r_department_name varchar2(20);
--r_hire_user_in varchar2(20);
cursor department is  select requirement_num,department_name from t_department_requirements for update;
cursor userinfo is select user_id,user_point,first_wish,second_wish  from t_user_apply_info order by user_point desc;
begin

open department;
open userinfo;
loop
fetch userinfo into u_user_id,u_user_point,u_first_wish,u_second_wish;
exit when userinfo%notfound;
--判断志愿并插入数据:
select requirement_num,department_name into d_requirement_num,d_department_name  from t_department_requirements  where department_name=u_first_wish;
if d_requirement_num>0 then
insert into t_result_info values(u_first_wish,u_user_id,u_user_point);
update  t_department_requirements set requirement_num=requirement_num-1 where department_name=u_first_wish;
end if;
if d_requirement_num<=0 then
select requirement_num,department_name into d_requirement_num,d_department_name  from t_department_requirements  where department_name=u_second_wish;
if d_requirement_num>0 then
insert into t_result_info values(u_second_wish,u_user_id,u_user_point);
update  t_department_requirements set requirement_num=requirement_num-1 where department_name=u_second_wish;
end if;
end if;
end loop;
Exception
   when No_data_found  then
     DBMS_OUTPUT.PUT_LINE('没有找到数据');
   when others then
     DBMS_OUTPUT.PUT_LINE('操作异常');
open resultinfo for select * from t_result_info;
close department;
close userinfo;
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值