• 网络学院
  • 新手学堂
  • 操作系统
  • 网络技术
  • 软件应用
  • 办公软件
  • 编程技术
  • 网站架设
  • 数据库类
  • 平面设计
  • 多媒体类
  • 游戏资讯
  • 教学论文
  • 认证考试
开发技术:关于变量、移动以及含义
广告位
  站点:
  • 首 页
  • 最新软件
  • 最新文章
  • 国内软件
  • 国外软件
  • 汉化软件
  • 源码下载
  • 字体下载
开发技术:关于变量、移动以及含义
软件发布 开发技术:关于变量、移动以及含义
网络软件 系统工具 应用软件 联络聊天 图形图像 多媒体类 行业软件 游戏娱乐 编程开发 安全相关 教育教学 数码软件
热门软件: QQ 瑞星 pplive e话通 木马克星 千千静听 office2000 五笔字根 Photoshop 视频分割
返回首页 | 文章首页 | 认证考试 | Oracle认证 | Oracle指导 | 开发技术:关于变量、移动以及含义

开发技术:关于变量、移动以及含义

 

添加时间: 2008-4-23 22:52:28  作者: Oracle指导  阅读次数:25   来源: http://www.d9soft.com

 

 

       

Apply best practices to cursor variables, bidirectional cursor access, and error messages.

I have a stored procedure that uses a REF CURSOR parameter to return a result set as a cursor variable. How can I call that procedure and then insert the rows identified by the cursor variable into a table, using FORALL?

A cursor variable is a PL/SQL variable that points to a result set. You can fetch the rows of a cursor variable's result set just as you would fetch the rows identified by an explicitly declared cursor. You can in particular use BULK COLLECT against a cursor variable to deposit into a collection all the rows identified by the result set. You can then reference that collection in a FORALL INSERT statement.

Let's take a look at the kind of code you would write to achieve your goal. I will use the jokes and joke_archive tables as my example data structures:


CREATE TABLE jokes (
   joke_id INTEGER,
   title VARCHAR2(100),
   text VARCHAR2(4000)
)
/
CREATE TABLE joke_archive (
   archived_on DATE,
   old_stuff VARCHAR2(4000)
)
/

I will place two jokes in the jokes table, as shown in Listing 1.

Code Listing 1: Inserting jokes into the jokes table


BEGIN
   INSERT INTO jokes
        VALUES (100, 'Why does an elephant take a shower?'
               ,'Why does an elephant take a shower? ' ||
                'Because it can't fit into the bathtub!');

   INSERT INTO jokes
        VALUES (101
               ,'How can you prevent diseases caused by biting insects?'
               ,'How can you prevent diseases caused by biting insects?' || 'Don't bite any!');

   COMMIT;
END;

I now need to write a procedure that will identify joke text or titles that need to be moved to the joke_archive table. Here is the header of my procedure:


CREATE OR REPLACE
PROCEDURE get_title_or_text (
   title_like_in IN VARCHAR2
  ,return_title_in IN BOOLEAN
  ,joke_count_out OUT PLS_INTEGER
  ,jokes_out OUT SYS_REFCURSOR
)

I pass in a string (title_like_in) that acts as a filter to identify the rows in the jokes table to be moved to the archive. I specify whether I want to retrieve titles (return_title_in => TRUE) or text (return_title_in => FALSE). I then return the total number of rows identified by the result set (joke_count_out), as well as the result set itself (joke_out). I use the system-defined weak REF CURSOR type, SYS_REFCURSOR (available in Oracle9i Database Release 2 and later).

Listing 2 contains the implementation of the get_title_or_text procedure.


Code Listing 2: get_title_or_text procedure


1  CREATE OR REPLACE PROCEDURE get_title_or_text (
 2     title_like_in IN VARCHAR2
 3    ,return_title_in IN BOOLEAN
 4    ,joke_count_out OUT PLS_INTEGER
 5    ,jokes_out OUT SYS_REFCURSOR
 6  )
 7  IS
 8     c_from_where      VARCHAR2 (100) := ' FROM jokes WHERE title LIKE :your_title';
 9     l_colname           all_tab_columns.column_name%TYPE   := 'TEXT';
10    l_query              VARCHAR2 (32767);
11  BEGIN
12     IF return_title_in
13     THEN
14        l_colname := 'TITLE';
15     END IF;
16
17     l_query := 'SELECT ' || l_colname || c_from_where;
18
19     OPEN jokes_out FOR l_query USING title_like_in;
20
21     EXECUTE IMMEDIATE 'SELECT COUNT(*)' || c_from_where
22                  INTO joke_count_out
23                 USING title_like_in;
24  END get_title_or_text;

Here is an explanation of the interesting parts of the get_title_or_text procedure in Listing 2.

 

开发技术:关于变量、移动以及含义(1) 第 [1] [2] [3] [4] [5]  下一页

 

 

上下文章:

 

上一篇文章: 入门基础:连接常见错误及解决方法 下一篇文章: 开发技术:调查您的应用程序需求

相关文章:

  • Oracle中关于逻辑备份与恢复
  • Oracle开发人员JAVA存储过程
  • Oracle集成技术及创建工具
  • 关于Oracle的入门话题
  • 怎样应对ORACLE面试中的问题技术

相关软件:

  • C/S、B/S两用开发平台 V6.1.2
  • DVD/CD光盘刻录SDK开发包 V4.2
  • 中国移动手机桌面助理 V1.7.0.121
  • OK移动英语 V1.0 新概念英语第一册 for S60 v1 v2
  • 子墨开发平台 V1.0.0.0
  • 移动车子 绿色版

 

 

快速导航

  • 网络学院
  • 精品汇聚
  • 字体下载
  • 教程下载
  • ASP源码
  • PHP源码
  • Net源码
  • JSP 源码

Oracle认证分类导航

  • Oracle动态
  • Oracle指导
  • Oracle题库

本类经典文章推荐

  • Oracle中关于逻辑备份与恢复
  • Oracle开发人员JAVA存储过程
  • 为数据库的表自动生成行号
  • Oracle中的OOP概念
  • 用java从oracle取数
  • 冷备份移植到另一台Solaris机器上
  • 如何将excel数据导入oracle中
  • Oracle10.2g安装记录
  • 数据库监控工具ForOraclev1.2
  • oracle双机群集系统

Oracle指导阅读排行

  • Oracle系统表查询
  • 实例:Oracle导出EXCEL文件
  • Oracle企业管理器(OEM 2.1)使用...
  • 实例:Oracle导出EXCEL文件
  • Tomcat+SQLServer连接池配置
  • 服务器和客户机是怎样连接的
  • 入门基础:连接常见错误及解决方法
  • ORACLE数据库简介
  • 如何将excel数据导入oracle中
  • 如何取出某一用户的密码 再原样改...

Oracle认证阅读总排行

  • Oracle系统表查询
  • 实例:Oracle导出EXCEL文件
  • Oracle企业管理器(OEM 2.1)使用...
  • 在ORACLE的存储过程中如何做简单的...
  • 实例:Oracle导出EXCEL文件
  • AIX下自动启动Oracle数据库与监听...
  • Tomcat+SQLServer连接池配置
  • 服务器和客户机是怎样连接的
  • 入门基础:连接常见错误及解决方法
  • ORACLE数据库简介

广告位置

字母检索 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 回到顶部

关于我们 | 版权声明 | 免责条款 | 广告联系 | 软件发布 | 下载帮助 | 下载排行 | 网站地图 | 特别鸣谢 | 友情连接

copyright; 2005-2008 D9soft.com 第九软件网 版权所有