Oracle 游标及存储过程实例
/*********实例一*********/
create or replace procedure users_procedure is
cursor users_cursor is select * from users;--声明动态游标
v_id users.id%type;--定义变量,与表中变量类型同步
v_username users.username%type;
v_password users.password%type;
begin
open users_cursor;--打开游标
fetch users_cursor into v_id, v_username, v_password;
while users_cursor%found
loop
dbms_output.put_line('v_id = ' || v_id || 'v_username = ' || v_username || 'v_password = ' || v_password);
fetch users_cursor into v_id, v_username, v_password;
end loop;
close users_cursor;
end;
/ /*********实例二*********/
create or replace procedure users_batch_insert_procedure is
v_id users.id%type;
v_username users.username%type;
v_password users.password%type;
begin
for i in 0..1000
loop
v_id := i;
v_username := 'abc' || i;
v_password := 'efg' || i;
insert into users values(v_id, v_username, v_password);
commit;
end loop;
end;
/ /**********实例三 弱类型游标**************/
create or replace procedure users_a is
type users_cursor_type is ref cursor; --return users%rowtype;
type users_record_type is record (v_id users.id%type, v_username users.username%type, v_password users.password%type);
v_sql varchar2(2000);
users_cursor_a users_cursor_type;
users_record users_record_type;
begin
v_sql := 'select * from users';
open users_cursor_a for v_sql;
fetch users_cursor_a into users_record;
while users_cursor_a%found
loop
dbms_output.put_line('v_id = ' || users_record.v_id || 'v_username = ' || users_record.v_username || 'v_password = ' || users_record.v_password);
fetch users_cursor_a into users_record;
end loop;
close users_cursor_a;
end;
/ /**********实例四 强类型游标**************/
create or replace procedure users_a2 is
type users_cursor_type is ref cursor return users%rowtype;
v_row users%rowtype;
v_sql varchar2(2000);
users_cursor_a users_cursor_type;
begin open users_cursor_a for select * from users;
fetch users_cursor_a into v_row;
while users_cursor_a%found
loop
dbms_output.put_line('v_id = ' || v_row.id || 'v_username = ' || v_row.username || 'v_password = ' || v_row.password);
fetch users_cursor_a into v_row;
end loop;
close users_cursor_a;
end;
/ set serveroutput on size 1000000; /**********实例五 for语句 procedure**************/
create or replace procedure update_procedure is
v_province_name varchar2(100);
v_city_name varchar2(100);
v_county_name varchar2(100);
v_town_name varchar2(100);
begin
for i in (select t.id from area t where t.parent_id = 0)
loop
select t.shortname into v_province_name from area t where t.id = i.id;
v_province_name := v_province_name;
update area t set t.fullname = v_province_name where t.id = i.id;
for j in (select t.id from area t where t.parent_id = i.id)
loop
select t.shortname into v_city_name from area t where t.id = j.id;
v_city_name := v_province_name || v_city_name;
update area t set t.fullname = v_city_name where t.id = j.id;
for k in (select t.id from area t where t.parent_id = j.id)
loop
select t.shortname into v_county_name from area t where t.id = k.id;
v_county_name := v_city_name || v_county_name;
update area t set t.fullname = v_county_name where t.id = k.id;
for l in (select t.id from area t where t.parent_id = k.id)
loop
select t.shortname into v_town_name from area t where t.id = l.id;
v_town_name := v_county_name || v_town_name;
update area t set t.fullname = v_town_name where t.id = l.id;
end loop;
end loop;
end loop;
end loop;
end;
/
Oracle 游标及存储过程实例的更多相关文章
- oracle中print_table存储过程实例介绍
oracle中pro_print_table存储过程实例介绍 存储过程(Stored Procedure),就是一组用于完成特定数据库功能的SQL语句集,该SQL语句集经过编译后存储在数据库系统中.这 ...
- oracle 游标/函数/存储过程/触发器 表空间
--存储过程,循环create or replace procedure delTables(ename t_emp.ename%TYPE)AScon number;i NUMBER := 1;tab ...
- Oracle游标练手实例
--声明游标:CURSOR cursor_name IS select_statement --For循环游标 --(1)定义游标 --(2)定义游标变量 --(3)使用for循环来使用这个游标 de ...
- oracle存储过程实例
oracle存储过程实例 分类: 数据(仓)库及处理 2010-05-03 17:15 1055人阅读 评论(2)收藏 举报 认识存储过程和函数 存储过程和函数也是一种PL/SQL块,是存入数据库的P ...
- 利用navicat创建存储过程、触发器和使用游标的简单实例
利用navicat创建存储过程.触发器和使用游标的简单实例 标签: navicat存储过程触发器mysql游标 2013-08-03 21:34 15516人阅读 评论(1) 收藏 举报 分类: 数 ...
- Oracle dbms_lock.sleep()存储过程使用技巧-场景-分析-实例
<Oracle dbms_lock.sleep()存储过程使用技巧>-场景-分析-实例 摘要:今天是2014年3月10日,北京,雾霾,下午组织相关部门开会.会议的结尾一名开发工程师找到了我 ...
- Dapper完美兼容Oracle,执行存储过程,并返回结果集。
Dapper完美兼容Oracle,执行存储过程,并返回结果集. 这个问题,困扰了我整整两天. 刚刚用到Dapper的时候,感觉非常牛掰.特别是配合.net 4.0新特性dynamic,让我生成泛型集合 ...
- PHP调用MYSQL存储过程实例
PHP调用MYSQL存储过程实例 标签: mysql存储phpsqlquerycmd 2010-09-26 11:10 11552人阅读 评论(3) 收藏 举报 实例一:无参的存储过程$conn = ...
- 调用MYSQL存储过程实例
PHP调用MYSQL存储过程实例 http://blog.csdn.net/ewing333/article/details/5906887 http://www.cnblogs.com/kkchen ...
随机推荐
- android 进程和线程管理
进程和线程的概念: 进程:程序的运行实例. 线程:cpu调度基本单位. Activity启动的时候,启动一个主线程,两个binder线程. 主线程实如何产生的?ZygoteInit启动,经由一系列调用 ...
- js-数组算法收集版(转)
不管是在面试中还是在笔试中,我们都会被经常问到关于javascript数组的一些算法,比方说数组去重.数组求交集.数组扰乱等等.今天抽点时间把javascript中的一些常用的数组算法做一下总结,以方 ...
- JavaScript的计时器对象
1.JavaScript计时器,我们可以在设定的时间间隔之后来执行代码,而不是在函数被调用后立即执行. 计时器类型: 1)一次性计时器:仅在指定的延迟时间之后触发一次. 2)间隔性触发计时 ...
- QQ头像一键添加校徽
简书链接地址:http://www.jianshu.com/p/dcb2cbd07e4d 项目展示链接地址:www.zhaozhengyu.cn/SchoolImage/index.html
- Quicksum
Quicksum Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Subm ...
- 【Machine Learning in Action --5】逻辑回归(LogisticRegression)从疝气病预测病马的死亡率
背景:使用Logistic回归来预测患有疝气病的马的存活问题,这里的数据包括368个样本和28个特征,疝气病是描述马胃肠痛的术语,然而,这种病并不一定源自马的胃肠问题,其他问题也可能引发疝气病,该数据 ...
- G - Zombie’s Treasure Chest(动态规划专项)
G - Zombie’s Treasure Chest Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &am ...
- 2.3 DHC REST
DHC REST也是Chrome浏览器的插件,可以在Chrome应用商店安装下载,主要用来模拟HTTP客户端发送测试数据到服务器.HTTP Get请求在开发中比较常用.
- px和em,rem的区别
任意浏览器的默认字体高都是16px. px: 像素(Pixel) , 计算机屏幕上的一个点.固定大小:不方便维护: em:相对于当前对象内 (父元素) 文本的字体尺寸.如当前对行内文本的字体尺寸未被人 ...
- margin的auto的理解
auto 总是试图充满父元素 margin有四个值: All the margin properties can have the following values: auto - the brows ...