- 浏览: 101221 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
小小诺:
博主实例2中的代码博主难道没有测试吗?“工资总额不能超过6万元 ...
PLSQL -
emilyzhanghong:
我一般都用工具导入导出,语句记不住.
ORACLE 导入导出
--变量声明 declare -- 程序体 begin dbms_output.put_line('Hello World'); end;
/* if语句: 判断用户键盘输入的数字 */ set serveroutput on --接收键盘输入 accept num prompt '请输入一个数字:'; declare --通过&取输入的值 pnum number := # begin if pnum = 0 then dbms_output.put_line('您输入的是0'); end if; if pnum = 1 then dbms_output.put_line('您输入的是1'); end if; end; /
/* 带参数的光标: 查询并打印10号部门的员工的姓名和薪水 select ename,sal from emp where deptno=? */ set serveroutput on declare cursor cemp10(pdno number) is select ename,sal from emp where deptno=pdno; pename emp.ename%type; psal emp.sal%type; begin open cemp10(20); loop fetch cemp10 into pename,psal; exit when cemp10%notfound; dbms_output.put_line(pename||'的工资是'||psal); end loop; close cemp10; end; /
/* 被0除 catch(***Exception ex){ ... } */ set serveroutput on declare --定义数值变量,用于保存1/0结果 pnum number; begin --赋值 pnum := 1/0; exception when zero_divide then dbms_output.put_line('被0除'); end; /
/* 给员工涨工资,按照工种涨:总裁涨1000 经理800 其他人员400 可能的sql: select empjob,empno from emp; update emp set sal=sal+? where empno=? */ set serveroutput on declare --光标保存员工的编号和工作 cursor cemp is select empno,empjob from emp; --对应的变量 pempno emp.empno%type; pempjob emp.empjob%type; begin open cemp; LOOP --取出一个员工 fetch cemp into pempno,pempjob; --退出条件 exit when cemp%notfound; --判断 if pempjob = 'PRESIDENT' then update emp set sal=sal+1000 where empno=pempno; elsif pempjob= 'MANAGER' then update emp set sal=sal+800 where empno=pempno; else update emp set sal=sal+400 where empno=pempno; end if; END LOOP ; close cemp; --提交 commit; dbms_output.put_line('完成'); end; /
/* 使用游标查询员工姓名和工资,并打印 可能的sql: select ename,sal from emp */ set serveroutput on declare --定义光标 cursor cemp is select ename,sal from emp; --定义光标对应的变量 pename emp.ename%type; psal emp.sal%type; begin --打开光标 open cemp; --通过循环取出光标中的值 loop --取值 fetch cemp into pename,psal; --退出条件 exit when cemp%notfound; --取到值 dbms_output.put_line(pename||'的薪水是'||psal); end loop; --关闭光标 close cemp; end; /
/* 引用型变量和记录型变量 1. 引用型变量: 查询7839员工姓名和薪水 select ename, sal from emp where empno=7839; 2. 记录型变量: 查询7839员工所有信息 select * from emp where empno=7839; */ set serveroutput on declare --申明引用型变量 pename emp.ename%type; --记录姓名 psal emp.sal%type;--记录薪水 --记录型变量 emprec emp%rowtype; begin --执行查询 --select ename, sal into pename,psal from emp where empno=7839; select * into emprec from emp where empno=7839; --打印 --dbms_output.put_line(pename||'的薪水是'||psal); dbms_output.put_line(emprec.ename||'的薪水是'||emprec.sal); end; /
/* 自定义例外 */ set serveroutput on declare cursor cemp(pdno number) is select ename from emp where deptno=pdno; --变量 pename emp.ename%type; --例外 no_emp_data exception; begin open cemp(70); --取值 fetch cemp into pename; if cemp%notfound then raise no_emp_data; end if; close cemp; exception when no_emp_data then dbms_output.put_line('没有70号部门的员工'); end; /
/* 打印1~10 */ set serveroutput on declare pnum number :=1; begin loop --退出条件 exit when pnum > 10; --打印 dbms_output.put_line(pnum); pnum := pnum + 1; end loop; end; /
/* 实例1:统计每年入职的员工个数。 select count(*) "Total", sum(decode(to_char(hiredate,'yyyy'),'1980',1,0)) "1980" from emp; 可能的sql: select to_char(hiredate,'yyyy') from emp; */ set serveroutput on 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('总数' || (count80+count81+count82+count87)); dbms_output.put_line('80年'|| count80); dbms_output.put_line('81年'|| count81); dbms_output.put_line('82年'|| count82); dbms_output.put_line('87年'|| count87); end; /
/* 实例2: 为员工长工资。从最低工资调起每人长10%,但工资总额不能超过6万元, 请计算长工资的人数和长工资后的工资总额,并输出输出长工资人数及工资总额。 可能用到的sql: select empno from emp order by sal; 涨工资:update emp set sal=sal*1.1 where empno=? 工资总额: select sum(sal) from emp; */ set serveroutput on declare --查询员工,按照工资升序排列 cursor cemp is select empno from emp order by sal; pempno emp.empno%type;--记录员工的编号 --变量保存工资的总额 psalTotal number; --计数器保存涨工资的人数 empcount number :=0; begin --初始化工资的总额 select sum(sal) into psalTotal from emp; --涨工资 open cemp; loop --第一个退出条件 exit when psalTotal > 60000; --取出一个员工涨工资 fetch cemp into pempno; --第二个退出条件 exit when cemp%notfound; --涨工资 update emp set sal=sal*1.1 where empno=pempno; --人数加一 empcount := empcount + 1; --重新计算工资总额 select sum(sal) into psalTotal from emp; end loop; close cemp; --提交 commit; --输出结果 dbms_output.put_line('工资总额:' || psaltotal); dbms_output.put_line('涨工资的人数:' || empcount); dbms_output.put_line('-----------------------'); end; /
/* 实例3: 用PL/SQL语言编写一程序,实现按部门分段(6000以上、(6000,3000)、3000元以下) 统计各工资段的职工人数、以及各部门的工资总额(工资总额中不包括奖金) 可能的sql: 查询部门: select distinct deptno from dept; 取出该部门的员工: select sal from emp where deptno=? 计算该部门的工资总额: select sum(sal) from emp where deptno=? */ set serveroutput on declare --查询部门 cursor cdept is select distinct deptno from dept; pdeptno dept.deptno%type; --查询该部门中的员工 cursor cemp(pdno number) is select sal from emp where deptno=pdno; psal emp.sal%type; --计数器 count1 number;-->6000 count2 number;--3000~6000 count3 number;--<3000 --工资总额 psalTotal number; begin --获取部门 open cdept; loop --取一个部门 fetch cdept into pdeptno; --退出 exit when cdept%notfound; --初始化计数器 count1 := 0;count2 := 0;count3 := 0; --得到该部门的工资总额 select sum(sal) into psalTotal from emp where deptno=pdeptno; --得到该部门的员工的工资 open cemp(pdeptno); loop --取一个员工的工资 fetch cemp into psal; exit when cemp%notfound; --判断 if psal >= 6000 then count1 := count1 +1; elsif psal < 6000 and psal >=3000 then count2:=count2+1; else count3:=count3+1; end if; end loop; close cemp; --保存结果 insert into msg1 values(pdeptno,count3,count2,count1,psalTotal); commit; end loop; close cdept; dbms_output.put_line('完成'); end; /
发表评论
-
实现数据的列转入到行中的过程语言
2013-05-07 14:16 633drop PROCEDURE RSPDB.GET_C ... -
db2工作笔记
2012-02-15 11:03 919// 生成32位随机数 CREATE OR REPLAC ... -
oracle_SQL 优化
2012-01-14 04:53 761ORACL ... -
db2 基本命令整理
2012-01-13 13:34 892安装好数据库 进行系统环境变量的设置 可以在doc命令行上面 ... -
db2 数据备份和还原
2012-01-12 17:53 1068connect to odsdb user reportdb ... -
db2命令
2011-12-27 10:57 8481.关闭db2 db2stop 或db2 ... -
cognos 连不上业务库
2011-12-10 17:39 1829Cognos Error 'QE-DEF-0285 The l ... -
编目远程数据库到本地
2011-11-22 20:52 851db2 catalog tcpip node reportdb ... -
快速生成测试数据
2011-09-21 11:34 527select rownum as id, to_char(sy ... -
window下 ORACL卸载
2011-07-28 21:23 964用Oracle自带的卸载程序不能从根本上卸载Oracle,从而 ... -
SQL优化
2011-07-17 00:24 641SQL优化的一些资料 -
ORACLE 问题
2011-07-04 23:55 723表 张三 英语 张三 语文 张三 英语 李四 英语 李四 语文 ... -
ORACLE 导入导出
2011-07-04 23:54 843Oracle数据导入导出imp/exp就相当于oracle数据 ... -
SQl游标的使用
2011-05-27 14:13 739use testtest-- 定义游标MyTestCursor ... -
序列自增长的问题
2011-05-25 11:16 730用存储过程为多表生成序列: 为每张表生成对应的序列 --创建 ... -
Oracle(SQL查询测试题)
2011-05-20 14:13 1252--客户表a(id name address) 登 ... -
Oracle(SQL 之视图)
2011-05-20 11:55 813-- 查询部门号为10所有的员工,所有得到提成的员工,以及20 ... -
Oracle(SQL之查询)
2011-05-20 11:47 864--查询语句 select * from emp; -- 查询 ... -
Oracle(SQL)
2011-05-20 11:31 702--插入一条数据 select * from emp; --修 ... -
Oracle(procedure)
2011-05-20 11:07 2114--存储过程 -- 列1: 如果员工工资小于2000的涨百分之 ...
相关推荐
PL/SQL Developer是一个集成开发环境,专门面向Oracle数据库存储程序单元的开发。... 该安装包包含了解决PLSQL过期的文件,将PLSQL安装后将解决过期的文件放到安装包中,即可解决PLSQL过期的问题。即可永久使用。
plsql developer9 0破解版 PLSQL Developer 9 0 0 1601破解版本使用了8 0的汉化包 可以正常使用 无需注册 默认为英文 点击菜单tools preferences appearance language 选择简体中文即可切换到简体中文界面 如果...
PLSQL Developer 11.0.2.1766 中文绿色注册版(免Oracle客户端) PLSQL Developer 11.0.2.1766 中文绿色注册版(免Oracle客户端) 免安装Oracle客户端,绿色无...CN.GBK start PLSQLDev.exe 作用:设置临时变量,启动plsql
1、点击 "启动PLSQL.exe" 即可免装oracle使用PLSQL 或者 使用qidong.bat启动 (启动PLSQL.exe是qidong.bat编译的exe,隐藏调用qidong.bat启动PLSQL,比qidong.bat好处没有黑框界面,有图标); 2、Oracle64为oracle ...
下面简单介绍下PLSQL developer工具的SVN版本控制 1, 下载pl/sql-svn插件。 2, 关闭你打开的所有pl/sql窗口。 3,将插件里的SVN_Plugin.dll文件复制到PLSQL DeveloperPlugIns目录下。 4,重新打开pl/sql,...
PLSQL Developer9-GGS 0402版 (更新至Oracle11g2内核) 完美绿色中文破解版,真正地免安装Oralce,已集成最新的instantclient(Oracle11g2),兼容Oracle11g2以下所有版本。 如果需要运行原版,请直接进入bin文件夹...
plsql developer 64位是专门针对windows 64位操作系统开发的Oracle数据库管理工具,它拥有强大的数据库编辑器和智能化的语法特性,在使用sql语句创建和编辑数据库的基础上提供更加简捷实用的图形化界面进行数据库表...
plsql11安装包文件
PLSQL Developer 11.0.2.1766 中文绿色注册版(免Oracle客户端) PLSQL Developer 11.0.2.1766 中文绿色注册版(免Oracle客户端) 免安装Oracle客户端,绿色无公害。...作用:设置临时变量,启动plsql
PLSQL Developer7(oracle数据库) PLSQL Developer7(oracle数据库) PLSQL Developer7(oracle数据库) PLSQL Developer7(oracle数据库) PLSQL Developer7(oracle数据库) PLSQL Developer7(oracle数据库) ...
plsql developer plsql developer plsql developer plsql developer plsql developer
64位版本的 PLSQL 正式版,只能运行在64位系统中,需要你安装 64 位的 Oracle11g 或 Oracle12c 客户端。 安装中文包时请注意安装路径是否为PLSQL程序的路径。 Enhancements in PL/SQL Developer 11.0.6 ===========...
plsql安装程序plsql.rar......................................
plsql精解plsql精解plsql精解plsql精解
plsql删除重复记录
plsql11汉化包 一键汉化plsql 告别英文plsql 亲测可用
32位版本的 PLSQL 正式版。 安装请查看说明。 APRIL 8, 2022 - VERSION 15.0 RELEASED Dark Mode styles and Light Mode styles Read-Only Connections Editor enhancements A macro can now be repeated by ...
使plsql 中的日常操作更加便捷,可以自定义快捷键
PLSQL Developer14用户指南英文版
plsql批量导入数据