/*********实例一*********/
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 游标及存储过程实例的更多相关文章

  1. oracle中print_table存储过程实例介绍

    oracle中pro_print_table存储过程实例介绍 存储过程(Stored Procedure),就是一组用于完成特定数据库功能的SQL语句集,该SQL语句集经过编译后存储在数据库系统中.这 ...

  2. oracle 游标/函数/存储过程/触发器 表空间

    --存储过程,循环create or replace procedure delTables(ename t_emp.ename%TYPE)AScon number;i NUMBER := 1;tab ...

  3. Oracle游标练手实例

    --声明游标:CURSOR cursor_name IS select_statement --For循环游标 --(1)定义游标 --(2)定义游标变量 --(3)使用for循环来使用这个游标 de ...

  4. oracle存储过程实例

    oracle存储过程实例 分类: 数据(仓)库及处理 2010-05-03 17:15 1055人阅读 评论(2)收藏 举报 认识存储过程和函数 存储过程和函数也是一种PL/SQL块,是存入数据库的P ...

  5. 利用navicat创建存储过程、触发器和使用游标的简单实例

    利用navicat创建存储过程.触发器和使用游标的简单实例 标签: navicat存储过程触发器mysql游标 2013-08-03 21:34 15516人阅读 评论(1) 收藏 举报  分类: 数 ...

  6. Oracle dbms_lock.sleep()存储过程使用技巧-场景-分析-实例

    <Oracle dbms_lock.sleep()存储过程使用技巧>-场景-分析-实例 摘要:今天是2014年3月10日,北京,雾霾,下午组织相关部门开会.会议的结尾一名开发工程师找到了我 ...

  7. Dapper完美兼容Oracle,执行存储过程,并返回结果集。

    Dapper完美兼容Oracle,执行存储过程,并返回结果集. 这个问题,困扰了我整整两天. 刚刚用到Dapper的时候,感觉非常牛掰.特别是配合.net 4.0新特性dynamic,让我生成泛型集合 ...

  8. PHP调用MYSQL存储过程实例

    PHP调用MYSQL存储过程实例 标签: mysql存储phpsqlquerycmd 2010-09-26 11:10 11552人阅读 评论(3) 收藏 举报 实例一:无参的存储过程$conn = ...

  9. 调用MYSQL存储过程实例

    PHP调用MYSQL存储过程实例 http://blog.csdn.net/ewing333/article/details/5906887 http://www.cnblogs.com/kkchen ...

随机推荐

  1. java线程condition

    子线程先执行一段代码,再主线程再执行一段代码,两个线程都循环执行50遍.用2个condition来实现,一个是子线程的condition,一个是主线程的condition,代码如下: package ...

  2. 转:Cocoa、Foundation、UIKit、Objective-c、XCode、Interface Builder的概念

    Cocoa 是在Mac OS X系统上原生的一个编译环境.他包含两个框架,其实就是一系列的类库,Foundation和AppKit. 在你的iPhone等掌上设备上,使用的则是他的一个子类 - Coc ...

  3. 永久修改python默认的字符编码为utf-8

    这个修改说来简单,其实不同的系统,修改起来还真不一样.下面来罗列下3中情况 首先所有修改的动作都是要创建一个叫 sitecustomize.py的文件,为什么要创建这个文件呢,是因为python在启动 ...

  4. ubuntu显卡驱动安装及设置

    转自: Ubuntu 14.04 Nvidia显卡驱动安装及设置   更换主板修复grub 引导后,无法从Nvidia进入系统(光标闪烁), 可能是显卡驱动出了问题. 1. 进入BIOS设置, 从集成 ...

  5. Python学习笔记_Chapter 7web开发

    1.web应用元素 a.成员: web浏览器 web服务器 b.行为: web请求: 请求内容: 静态内容:如html文件,图像. 动态内容:需服务器运行一个程序进而做出响应. 网关接口&CG ...

  6. Java IO 文件与流基础

    Java IO 文件与流基础 @author ixenos 摘要:创建文件.文件过滤.流分类.流结构.常见流.文件流.字节数组流(缓冲区) 如何创建一个文件 #当我们调用File类的构造器时,仅仅是在 ...

  7. 理解 Objective-C 的 ARC

    英文原文:Understanding Automatic Reference Counting in Objective-C 自动引用计数(Automatic Reference Counting, ...

  8. NOIP2010-普及组复赛-第四题-三国游戏

    题目描述 Description 小涵很喜欢电脑游戏,这些天他正在玩一个叫做<三国>的游戏.  在游戏中,小涵和计算机各执一方,组建各自的军队进行对战.游戏中共有 N 位武将(N为偶数且不 ...

  9. uilabel 复制

    //添加一个长按响应方法 - (void)addLongPressGestureRecognizer { UILongPressGestureRecognizer * longPress = [[UI ...

  10. HYSBZ 1053 反质数

    input n 1<=n<=2000000000 output 不大于n的最大反质数 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满足:g( ...