oracle涨工资问题
2018-01-20 20:33
141 查看
--综合案例之瀑布模型 --统计每年入职员工人数 /*select to_char(hiredate,'yyyy')from emp; -->光标-->循环-->退出条件:notfound 变量:1:初始值 2:如何得到 每年入职员工人数: count80 number:=0; count81 number:=0; count82 number:=0; count87 number:=0; */ declare cursor cemp is select to_char(hiredate,'yyyy') from emp; phiredate varchar2(4); --每年入职员工人数 count80 number:=0; count81 number:=0; count82 number:=0; count87 number:=0; begin --打开光标 open cemp; --循环 loop fetch cemp into phiredate; exit when cemp%notfound; --判断年份 if phiredate='1980' then count80:=count80+1; elsif phiredate='1981' then count81:=count81+1; elsif phiredate='1982' then count82:=count82+1; else count87:=count87+1; end if; end loop; close cemp; --输出 DBMS_OUTPUT.PUT_LINE('1980:'||count80); DBMS_OUTPUT.PUT_LINE('1981:'||count81); DBMS_OUTPUT.PUT_LINE('1982:'||count82); DBMS_OUTPUT.PUT_LINE('1987:'||count87); end; -- set SERVEROUTPUT ON; --案例2:从最低工资涨起每人张10%,但工资总额不能超过5万 -------计算涨工资的人数和涨工资后的工作总额 /*selectempno,sal,from emp order bysal -->光标-->循环-->退出条件:1.工资总额>5w 2.%notfound 2.变量 涨工资的人数: countemp number:=0; 涨后工作总额: saltotal number: 1 select sum(sal) into saltal from emp; 2.涨后工资总额=涨钱工资总额+sal*0.1 */ declare cursor cemp is select empno,sal from emp order by sal; pempno EMP.ENAME%type; psal EMP.SAL%type; countemp number:=0; saltal number; begin --得到工资初始值 select sum(sal) into saltal from emp; open cemp; loop exit when saltal>500000; --取每一个员工涨工资 fetch cemp into pempno,psal; -- exit when cemp%notfound; --涨工资 update emp set sal=sal*1.1 where empno=pempno; --人数+1 countemp:=countemp+1; --涨后工资 saltal:=saltal+sal*0.1; end loop; close cemp; commit; dbms_output.put_line('人数:'||countemp||'涨后工资'||saltal); end; --
相关文章推荐
- 初折腾Oracle问题小记四
- 解决txt文件中数据带有日期类型导入oracle中到不进去的问题
- oracle的license和正版使用问题
- oracle insert中文数据,查询出现乱码问题解决
- Oracle 乱码或则中文无法正确查询问题
- ORACLE导出时的query问题
- Oracle当"sqlplus / as sysdba"登录不了数据库问题场景1
- Oracle 客户端连接服务器端常见问题排除方法
- maven 无法下载 Oracle jar包问题
- oracle 10g 字符集不同的库之间的数据导入导出问题
- oracle客户端连接数据库的小问题
- Ubuntu 12.04(32位)安装Oracle 11g(32位)全过程以及几乎所有问题的解决办法
- Oracle分页查询中排序与效率问题
- iis无法访问oracle的问题
- ORACLE问题,每天10问(十)
- oracle一些问题集中!
- Oracle客户端工具连接数据库服务器问题汇总
- 解决vs2010无法找到System.Data.OracleClient的引用问题
- Oracle 安装问题一则
- oracle多语言环境下to_date时间转换问题