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
/**//*;
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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45


46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

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