一道经典plsql编程练习题

本文提供了一段PLSQL代码示例,用于练习薪资调整逻辑。根据职位和薪资水平,自动调整员工薪资,并将符合条件的数据插入到新表中,同时输出调整人数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在学plsql,苦于找不到练习题,所以自己写了一个用于练习.要求如下:

查找scott用户的emp表中的所有数据,如果jobMANAGER 工资大于2500,则下调百分之10;如果小于2500 则增加百分之10,如果jobSALESMAN 工资小于1500 则上调百分之10;

最后符合条件的人.插入到test表中.并且打印符合条件的人数的个数.

Test表结构如下:

Ename varchar

Sal number

大家可以做来练习一下.以下是我的答案:

create or replace procedure test_update_all as type emplist is table of emp%rowtype; empl emplist; coun number(3):=0; state number(1); procedure one_record(name_emp in emp.ename%type,job_name in emp.job%type,sal_emp in out emp.sal%type,coun in out number,sal_state in out number) as up_reails number(2,2):=0; low_reails number(2,2):=0; begin case when job_name='MANAGER' then if sal_emp>=2500 then low_reails:=.1; dbms_output.put_line(name_emp||' 工资大于2500 过高 ,下调百分之'||low_reails*100); sal_state:=1; coun:=coun+1; elsif sal_emp<2500 then low_reails:=.1; dbms_output.put_line(name_emp||' 工资大于2500 过低 ,上调百分之'||up_reails*100); sal_state:=1; coun:=coun+1; end if; when job_name='SALESMAN' then if sal_emp<1500 then begin low_reails:=.1; dbms_output.put_line(name_emp||' 工资大于1500 过低 ,上调百分之'||low_reails*100); sal_state:=1; coun:=coun+1; end; end if; else dbms_output.put_line(name_emp||'不符合条件,不进行更改'); end case; sal_emp:=sal_emp*(1+up_reails-low_reails); end one_record; begin select * bulk collect into empl from emp; for i in empl.first..empl.last loop state:=0; one_record(empl(i).ename,empl(i).job,empl(i).sal,coun,state); if state =1 then dbms_output.put_line(empl(i).ename||'的薪金更改为'||empl(i).sal); insert into test values(empl(i).ename,empl(i).sal); end if; end loop; dbms_output.put_line('更改的人数为:'||coun); end;

接触plsql时间尚浅,只是用最简单的方法实现.大牛们有更好的思路请跟帖告知.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值