/
ref_cursor_db_objects.sql
77 lines (59 loc) · 2.13 KB
/
ref_cursor_db_objects.sql
1
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
67
68
69
70
71
72
73
74
75
76
create table refcursor_test_tbl (
site_id number(2) not null,
location varchar2(12)
);
insert into refcursor_test_tbl values (1, 'Paris' );
insert into refcursor_test_tbl values (2, 'Boston' );
insert into refcursor_test_tbl values (3, 'London' );
insert into refcursor_test_tbl values (4, 'Stockholm' );
insert into refcursor_test_tbl values (5, 'Ottawa' );
insert into refcursor_test_tbl values (6, 'Washington');
insert into refcursor_test_tbl values (7, 'La' );
insert into refcursor_test_tbl values (8, 'Toronto' );
insert into refcursor_test_tbl values (3, 'Zuerich' );
create or replace package tq84_refcursor_test_pck as -- {
procedure proc_1 (
Pmyid in number,
Pmycursor out sys_refcursor, -- use cursor
x out sys_refcursor,
Perrorcode out number);
procedure proc_2 (
Pmyquery in varchar2,
Pmycursor out sys_refcursor,
Perrorcode out number);
end tq84_refcursor_test_pck; -- }
/
create or replace package body tq84_refcursor_test_pck as -- {
procedure proc_1 (
Pmyid in number,
Pmycursor out sys_refcursor, -- use cursor
x out sys_refcursor, -- use cursor
Perrorcode out number) is
begin
Perrorcode := 0;
-- Open the ref cursor
-- Use Input Variable "PmyID" as part of the query.
open pmycursor for
select 'foo' foo, location
from refcursor_test_tbl
where site_id = pmyid;
open x for select * from refcursor_test_tbl where site_id < 5;
exception when others then
Perrorcode := SQLCODE;
end proc_1;
procedure proc_2 (
Pmyquery in varchar2,
Pmycursor out sys_refcursor,
Perrorcode out number)
is
begin
Perrorcode := 0;
-- Open the REF CURSOR
-- This procedure uses a query
-- which is passed in as a parameter.
open pmycursor for pmyquery;
exception when others then
Perrorcode := sqlcode;
end proc_2;
end tq84_refcursor_test_pck; -- }
/