转帖:Oracle包体用法及测试代码

 1 -- 建表
 2 create   table  userTabel( 
 3   userid  number ( 10 ), 
 4   username  varchar2 ( 100 ), 
 5    constraint  PK_USERID  PRIMARY   KEY (userid) 
 6 ); 
 7 commit
 8
 9 insert   into  userTabel  values ( 1 , ' Albert ' ); 
10 insert   into  userTabel  values ( 2 , ' reboot ' ) ;
11 insert   into  userTabel  values ( 3 , ' Jeff ' );
12
13 -- 建包
14 create   or   replace  package pkg_BB  is
15 --  Author  : ADMINISTRATOR
16    --  Created : 2008-07-17 8:35:52
17    --  Purpose : 
18   
19    --  Public type declarations
20   type mycur  is  ref  cursor ;  
21   type myrecord  is  record( 
22                           myid usertabel.userid % type,
23                           myname usertabel.username % type);
24    procedure  pro_GetCur(cur_return out mycur);
25   
26 end  pkg_BB;
27
28 -- 包体
29 create   or   replace  package body pkg_BB  is
30    --  Function and procedure implementations
31    procedure  pro_GetCur(cur_return out mycur)  
32    is     
33    begin
34     open  cur_return  for   select   *   from  Usertabel;    
35    end  pro_GetCur;
36 end  pkg_BB;
37
38 -- 测试代码
39 declare
40   rec pkg_bb.myrecord;
41   cur pkg_bb.mycur;
42 begin
43  pkg_bb.pro_GetCur(cur);
44  
45 ExpandedBlockStart.gifContractedBlock.gif  /**/ /*;
46  close cur;
47 dbms_output.put_line(rec.myid);
48 dbms_output.put_line(rec.myname);*/

49  loop 
50   fetch  cur  into  rec;
51   exit   when  cur % notfound;
52  dbms_output.put_line(rec.myid);
53  dbms_output.put_line(rec.myname);
54   end  loop;
55   close  cur;
56   end ;
57
58 输出结果:
59 1
60 Albert
61 2
62 reboot
63 3
64 Jeff
65
66

内容是从CSDN上一位好人的回帖中抠出来的,再次谢过了~

PS:若想通过PL/SQL工具来测试包里面的存储过程,可以发现包体文件夹中的存储过程的图标和真正存储过程文件夹中的是不一样的(前者是绿色圆圈,后者是蓝色立方体),需要在包体里面找到相应的存储过程,然后右键查看或者编辑,然后在打开的窗口中就可以发现左侧窗口上找到存储过称滚轮,这时右键就会有Test出现了;或者在包文件夹下找到指定包,然后在其下的存储过程文件夹中找到要测试的存储过程右键,就有了!估计会觉得写的很弱智,不过当时确实找了半天!

转载于:https://www.cnblogs.com/jinqiuqiu1120/archive/2009/02/13/1389943.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值