/*********实例一*********/
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. redis 5 种数据结构

    常用命令 就DB来说,Redis成绩已经很惊人了,且不说memcachedb和tokyocabinet之流,就说原版的memcached,速度似乎也只能达到这个级别.Redis根本是使用内存存储,持久 ...

  2. MySQL备份参数详解

    mysqldump 是采用SQL级别的备份机制,它将数据表导成 SQL 脚本文件,在不同的 MySQL 版本之间升级时相对比较合适,这也是最常用的备份方法. 1. --compatible = nam ...

  3. ASP.NET Page执行顺序

    using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...

  4. Spring Security(02)——关于登录

    目录 1.1     form-login元素介绍 1.1.1    使用自定义登录页面 1.1.2    指定登录后的页面 1.1.3    指定登录失败后的页面 1.2     http-basi ...

  5. Django中的Form表单

    Django中已经定义好了form类,可以很容易的使用Django生成一个表单. 一.利用Django生成一个表单: 1.在应用下创建一个forms文件,用于存放form表单.然后在forms中实例华 ...

  6. 关于socket客户端接收不定长数据的解决方案

    #!/usr/bin/env python3.5 # -*-coding:utf8-*- """ 本实例客户端用于不断接收不定长数据,存储到变量res "&qu ...

  7. 请教下关于CKEditor富文本编辑框设置字体颜色的问题

    CKEDITOR.editorConfig = function( config ){ config.plugins = 'about,a11yhelp,basicstyles,bidi,blockq ...

  8. 全排列dfs算法

    如下 #include <iostream> using namespace std; #define MAX 10 #define _CRT_SECURE_NO_WARNINGS int ...

  9. .net 2.0 后台多线程

    System.Threading.Thread thread1 = new System.Threading.Thread(delegate() { Web.BLL.banpaiconfig.Vide ...

  10. PHP通过url下载远程图片到本地

    function GrabImage($url,$filename) { if($url==""):return false;endif; ob_start(); readfile ...