Oracle PL/SQL匿名块(三)
转载: http://blog.163.com/lyq_163_2009/blog/static/134082696201071210464738/
//错误处理
declare
v_temp number(4);
begin
select empno into v_temp from emp where deptno=10;
exception
when too_many_rows then
dbms_output.put_line('太多记录了...');
when others then
dbms_output.put_line('error...');
end;
/
//错误处理
declare
v_temp number(4);
begin
select empno into v_temp from emp where empno=2222;
exception
when no_data_found then
dbms_output.put_line('没有数据...');
when others then
dbms_output.put_line('error...');
end;
/
//游标
declare
cursor c is select * from emp;
v_emp c%rowtype;
begin
open c;
fetch c into v_emp;
dbms_output.put_line(v_emp.ename);
close c;
end;
/
//游标
declare
cursor c is select * from emp;
v_emp c%rowtype;
begin
open c;
loop
fetch c into v_emp;
exit when(c%notfound);
dbms_output.put_line(v_emp.ename);
end loop;
close c;
end;
/
//游标
declare
cursor c is select * from emp;
v_emp c%rowtype;
begin
open c;
fetch c into v_emp;
while(c%found)loop
dbms_output.put_line(v_emp.ename);
fetch c into v_emp;
end loop;
close c;
end;
/
//游标
declare
cursor c is select * from emp;
begin
for v_emp in c loop
dbms_output.put_line(v_emp.ename);
end loop;
end;
/
//带参数的游标
declare
cursor c(v_deptno emp.deptno%type, v_job emp.job%type) is
select ename,sal from emp where deptno=v_deptno and job=v_job;
--v_temp c%rowtype;
begin
--open c(30,'clerk');
for v_temp in c(30,'CLERK') loop
dbms_output.put_line(v_temp.ename || ' ' || v_temp.sal);
end loop;
end;
/
//可以更新的游标
declare
cursor c is select * from emp2 for update;
--v_temp c%rowtype;
begin
for v_temp in c loop
if(v_temp.sal < 2000)then
update emp2 set sal=sal*2 where current of c;
elsif(v_temp.sal =5000)then
delete from emp2 where current of c;
end if;
end loop;
commit;
end;
/
//创建表
create table emp2 as(
select * from emp
);
//删除表
drop table emp2;
转载于:https://blog.51cto.com/baidu2013/1118699
Oracle PL/SQL匿名块(三)相关推荐
- Oracle PL/SQL匿名块
转载: http://blog.163.com/lyq_163_2009/blog/static/1340826962010712103822138/ PL/SQL单行注释使用--,多行注释使用/* ...
- 什么是oracle 匿名块,Oracle PL/SQL匿名块
PL/SQL单行注释使用--,多行注释使用/**/. PL/SQL中的变量类型主要有一下几种: binary_integer: 整数,主要用来技数而不是用来表示字段类型 number: 数字类型 ch ...
- Oracle PL/SQL匿名块(二)
转载: http://blog.163.com/lyq_163_2009/blog/static/1340826962010712104242953/ //table变量类型 declare typ ...
- Oracle课堂笔记之事务集合查询与PL/SQL匿名块(3)(实验习题)
(一)sql语句 1.将您自己的姓名.当前系统时间作为雇员信息插入到雇员表emp中(雇员编号统一为3010.部门编号为40).插入后查看emp表以确认是否插入成功!请将运行结果截图. 2. 将部门名为 ...
- oracle游标语法举例,PL/SQL语句块基本语法(ORACLE存储过程,函数,包,游标)
1.PL/SQL语句块 PL/SQL语句块只适用于Oracle数据库,使用时临时保存在客户端,而不是保存在数据库. 基本语法: declare 变量声明.初始化 begin 业务处理.逻辑代码 exc ...
- Oracle PL/SQL 第三章--运算符与表达式
Oracle PL/SQL 第三章--运算符与表达式 目录 Oracle PL/SQL 第三章--运算符与表达式 1.运算符分类 1.1.算术运算符 1.2.关系运算符 1.3.比较运算符 1.4.逻 ...
- oracle 的遍历语法,oracle pl/sql之pl/sql语法
一.pl/sql基础 pl/sql分匿名块和命名块. 命名块:存储过程,函数,触发器,包等. pl/sql语句块分3部分: (1)声明部分 (2)可执行部分 (3)异常处理部分 其中可执行部分是语句块 ...
- [顶]ORACLE PL/SQL编程详解之二:PL/SQL块结构和组成元素(为山九仞,岂一日之功)...
[顶]ORACLE PL/SQL编程详解之二:PL/SQL块结构和组成元素(为山九仞,岂一日之功) 原文:[顶]ORACLE PL/SQL编程详解之二:PL/SQL块结构和组成元素(为山九仞,岂一日之 ...
- 《Oracle PL/SQL程序设计(第5版)》一一2.4 执行必要的PL/SQL任务
本节书摘来自异步社区出版社<Oracle PL/SQL程序设计(第5版)>一书中的第2章,第2.4节,作者:[美]Steven Feuerstein , Bill Pribyl,更多章节内 ...
最新文章
- 【Mongodb】 Replica set的主从切换测试
- SQL Prompt 5.1使用
- 4.5/4.6 磁盘格式化 4.7/4.8 磁盘挂载 4.9 手动增加swap空间
- VS2017文件操作之使用fopen函数总结
- php 502.88,Nginx+PHP-FPM 访问出现 502错误
- Vite+Vue3页面空白、图标不显示问题解决
- 动态规划 —— 树形 DP
- selenium与python自动化测试模拟登录百度
- 毕业三年,攒了多少钱?
- v-show在elementui中表格组件失效问题
- vector容器——插入和删除
- 谷歌浏览器如何截取长屏幕(全屏截图)
- WinRAR v5.40 官网无广告弹窗正式版
- 百度翻译API使用简介
- Microsoft Office Home and Student Edition 2013 All-in-One For Dummies 免积分下载
- 该信谁?跳槽究竟是涨工资还是毁一生
- 不需要再手写 onSaveInstanceState 了,因为你的时间非常值钱
- docker配置redis
- 知物由学 | “群控软件”助长黑灰产套利的零和游戏,硬核技术打击隐秘的不公
- ‘When we dream, we have the perfect chemical canvas for intense visions’ “入梦时,我们就拥有了能够呈现强烈幻象的完美化学画布”
热门文章
- mpiBlast安装详解以及使用说明
- 机器学习知识总结系列-机器学习中的优化算法总结(1-4)
- Linux加密框架crypto crypto_alg|cipher_alg数据结构|AES例子
- C++ std::iota递增
- 与Linus Torvalds“并列”,虚拟化天才程序员法布里斯贝拉
- 公司管理项目管理中的技巧
- Dubbo + RestEasy 实现文件上传与下载
- JAVA 构造 MAP 并初始化 MAP、定义时就初始化
- IP: 169.254.0.0/16 地址用途
- Quartz 之入门示例