- 浏览: 176163 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (321)
- eclipse (4)
- idea (2)
- Html (8)
- Css (14)
- Javascript (8)
- Jquery (6)
- Ajax Json (4)
- Bootstrap (0)
- EasyUI (0)
- Layui (0)
- 数据结构 (0)
- Java (46)
- DesPattern (24)
- Algorithm (2)
- Jdbc (8)
- Jsp servlet (13)
- Struts2 (17)
- Hibernate (11)
- Spring (5)
- S2SH (1)
- SpringMVC (4)
- SpringBoot (11)
- WebService CXF (4)
- Poi (2)
- JFreeChart (0)
- Shiro (6)
- Lucene (5)
- ElasticSearch (0)
- JMS ActiveMQ (3)
- HttpClient (5)
- Activiti (0)
- SpringCloud (11)
- Dubbo (6)
- Docker (0)
- MySQL (27)
- Oracle (18)
- Redis (5)
- Mybatis (11)
- SSM (1)
- CentOS (10)
- Ant (2)
- Maven (4)
- Log4j (7)
- XML (5)
最新评论
1. oracle游标
1) 游标简介 使用游标,我们可以对具体操作数据,比如查询的结果,对行,列数据进行更加细致的处理。以及对其他DML操作进行判断等操作。 2) 显示游标 SQL> set serverout on; declare cursor cu_emp is select empno,ename,sal from emp; e_no number; e_name varchar2(10); e_sal number; begin open cu_emp; fetch cu_emp into e_no,e_name,e_sal; while cu_emp%found loop dbms_output.put_line('编号:'||e_no||',姓名:'||e_name||',基本薪资:'||e_sal); fetch cu_emp into e_no,e_name,e_sal; end loop; close cu_emp; end; 使用%type匹配类型 SQL> set serverout on; declare cursor cu_emp is select empno,ename,sal from emp; e_no emp.empno%type; e_name emp.ename%type; e_sal emp.sal%type; begin open cu_emp; fetch cu_emp into e_no,e_name,e_sal; while cu_emp%found loop dbms_output.put_line('编号:'||e_no||',姓名:'||e_name||',基本薪资:'||e_sal); fetch cu_emp into e_no,e_name,e_sal; end loop; close cu_emp; end; 使用行,查询要使用*查询要使用*查询 SQL> set serverout on; declare cursor cu_emp is select * from emp; e emp%rowtype; begin open cu_emp; fetch cu_emp into e; while cu_emp%found loop dbms_output.put_line('编号:'||e.empno||',姓名:'||e.ename||',基本薪资:'||e.sal); fetch cu_emp into e; end loop; close cu_emp; end; 带条件查询 SQL> set serverout on; declare cursor cu_emp is select * from emp where sal>2000 and sal<3000; e emp%rowtype; begin open cu_emp; fetch cu_emp into e; while cu_emp%found loop dbms_output.put_line('编号:'||e.empno||',姓名:'||e.ename||',基本薪资:'||e.sal); fetch cu_emp into e; end loop; close cu_emp; end; 3) 隐式游标 隐式游标的属性 返回值类型 意义 SQL%ROWCOUNT 整型 代表DML语句成功执行的数据行数 SQL%FOUND 布尔型 值为true代表插入、删除、更新或单行查询操作成功 SQL%NOTFOUND 布尔型 与SQL%FOUND 属性返回值相反 SQL%ISOPEN 布尔型 DML执行过程中为真,结束后为假 SQL> begin if sql%isopen then dbms_output.put_line('sql游标已打开'); else dbms_output.put_line('sql游标未打开'); end if; end; 运行结果: sql游标未打开 隐式游标rowcount属性 SQL> declare e_count number; begin select count(*) into e_count from emp; dbms_output.put_line('游标捕获的记录数:'||sql%rowcount); end; 运行结果: 1 使用rowcount判断是否更新 SQL> begin update emp set ename='newname' where empno=111; if sql%rowcount=1 then dbms_output.put_line('已更新'); else dbms_output.put_line('未更新'); end if; end; 使用found判断是否更新 SQL> begin update emp set ename='newname' where empno=111; if sql%found then dbms_output.put_line('已更新'); else dbms_output.put_line('未更新'); end if; end; 4) 动态游标 强类型动态游标 job='PRESIDENT'或者job='PRESIDENT1' SQL> declare type emptype is ref cursor return emp%rowtype; cu_emp emptype; e_count number; e emp%rowtype; begin select count(*) into e_count from emp where job='PRESIDENT1'; if e_count=0 then open cu_emp for select * from emp; else open cu_emp for select * from emp where job='PRESIDENT'; end if; fetch cu_emp into e; while cu_emp%found loop dbms_output.put_line('编号:'||e.empno||',姓名:'||e.ename||',基本薪资:'||e.sal); fetch cu_emp into e; end loop; close cu_emp; end; 弱类型动态游标 job='PRESIDENT'或者job='PRESIDENT1' SQL> declare type customType is ref cursor; e_count number; e emp%rowtype; s salgrade%rowType; cType customType; begin select count(*) into e_count from emp where job='PRESIDENT1'; if e_count=0 then open cType for select * from salgrade; fetch cType into s; while cType%found loop dbms_output.put_line('等级:'||s.grade||',最低薪资:'||s.losal||',最高工资:'||s.hisal); fetch cType into s; end loop; close cType; else open cType for select * from emp where job='PRESIDENT'; fetch cType into e; while cType%found loop dbms_output.put_line('编号:'||e.empno||',姓名:'||e.ename||',基本薪资:'||e.sal); fetch cType into e; end loop; close cType; end if; end;
发表评论
-
账户锁定:ORA-28000: the account is locked
2019-02-28 09:16 2091Caused by: java.sql.SQLExcept ... -
oracle中角色
2018-12-21 10:58 5661. oracle角色 角色是权限的集合,可以给用户直接分 ... -
oracle中权限
2018-12-21 10:12 5241. oracle权限 oracle权限分为系统权限和对象 ... -
oracle中用户
2018-12-21 09:53 5521. oracle用户 oracle用户分两种,一种是系统 ... -
oracle中程序包?
2018-12-21 09:40 6711. oracle程序包 引入的目的,是为了有效的管理函数 ... -
oracle中函数与存储过程
2018-12-21 09:37 7301. oracle函数 create function 函 ... -
oracle中触发器
2018-12-20 15:29 5621. oracle触发器 ---------------- ... -
oracle中控制语句
2018-12-20 09:15 5721. oracle控制语句 set serverout o ... -
oracle中约束!
2018-12-19 16:26 5331. oracle约束 1.1 主键约束 primary ... -
oracle中视图
2018-12-19 09:25 5971. 用户授权 查看当前用户的角色 SQL> se ... -
oracle中数据类型及函数
2018-12-19 09:22 6261. 字符串类型及函数 ----------------- ... -
oracle中table表操作
2018-12-18 11:47 7321. scott用户示例表 1) 部门表:dept 1D ... -
oracle中sequence序列
2018-12-18 11:47 5781. oracle序列 ----------------- ... -
oracle中tablespace表空间
2018-12-18 11:47 6251. oracle表空间 一个数据库可以有多个表空间,一个 ... -
oracle软件sqldeveloper的安装
2018-12-18 11:46 6301. PLSQL Developer 10安装 1) PLS ... -
oracle软件oracle11g的安装
2018-12-18 11:46 6381. oracle的下载 oracle官 ... -
密码过期:ORA-28001: the password has expired
2018-12-24 15:48 11621. 密码过期:ORA-28001: the password ...
相关推荐
很详细很基础的讲了oracle中游标的使用,每一种有游标具体的用法,包含有案例的pl/sql的代码。
主要介绍了Oracle中游标Cursor基本用法详解,还是比较全面的,具有一定参考价值,需要的朋友可以了解下。
学习游标的用法!包含一些资料和代码!!对于学习者很有帮助的!!
ORACLE中游标的使用.pdf
标准的ORACLE数据库巡检报告文档,需要的童鞋赶快抢啦
关于Oracle9i中游标的应用.pdf
在Oracle PL/SQL中游标声明中表名动态变化的方法
oracle资料oracle资料oracle资料oracle资料oracle资料oracle资料oracle资料oracle资料oracle资料oracle资料oracle资料oracle资料
ORACLE中的游标汇总,记录了oracle中游标的使用
本书共分为15章,介绍关系数据库的基本理论,Oracle数据库的应用结构、体系结构,管理Oracle数据库,SQL*Plus命令、基本的SQL语句和Oracle对事务的管理,在Oracle数据库中使用PL/SQL进行编程,Oracle数据库的模式...
Oracle详解Oracle详解Oracle详解Oracle详解
Oracle 9i Client (Oracle 9i 客户端) 简化版 (不安装Oracle客户端,也可以使用PLSQL Developer 不用安装Oracle客户端也可以使用PLSQL Developer 绿色! 安全! 轻便! 可靠! 1、本软件可作为简单的Oracle9i客户端...
主要描述oracle中游标的学习隐式游标和显示游标
oracle游标使用! 值得下载看看!资源免费,大家分享!!
Dbmover for Mysql to Oracle 是高效的将Mysql导入到Oracle数据库的工具。 使用DBMover可以灵活定义Mysql和Oracle之间表和字段的对照关系,也可以在DBMover创建一个查询,把查询结果当作源表转入到Oracle中。 ...
oracle 数据库oracle 数据库oracle 数据库oracle 数据库oracle 数据库oracle 数据库oracle 数据库
oracle_课件oracle_课件oracle_课件oracle_课件oracle_课件oracle_课件oracle_课件oracle_课件oracle_课件oracle_课件oracle_课件