Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1786390
  • 博文数量: 1647
  • 博客积分: 80000
  • 博客等级: 元帅
  • 技术积分: 9980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 15:15
文章分类

全部博文(1647)

文章存档

2011年(1)

2008年(1646)

我的朋友

分类:

2008-10-28 18:04:53

CREATE OR REPLACE package pkg_test as 
    
/* 定义ref cursor类型 
    不加return类型,为弱类型,允许动态sql查询, 
    否则为强类型,无法使用动态sql查询; 
    
*/
 
    type myrctype 
is ref cursor

    
--函数申明 
    function get(intID numberreturn myrctype; 
end pkg_test; 
/ 

CREATE OR REPLACE package body pkg_test as 
--函数体 
    function get(intID numberreturn myrctype is 
        rc myrctype; 
--定义ref cursor变量 
        sqlstr varchar2(500); 
    
begin 
        
if intID=0 then 
            
--静态测试,直接用select语句直接返回结果 
            open rc for select id,name,sex,address,postcode,birthday from student; 
        
else 
            
--动态sql赋值,用:w_id来申明该变量从外部获得 
            sqlstr := 'select id,name,sex,address,postcode,birthday from student where id=:w_id'
            
--动态测试,用sqlstr字符串返回结果,用using关键词传递参数 
            open rc for sqlstr using intid; 
        
end if

        
return rc; 
    
end get; 

end pkg_test; 
/
--------------------next---------------------

阅读(108) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~