Skip to content

Commit 19cfaf1

Browse files
authored
Add files via upload
1 parent 44d5b0c commit 19cfaf1

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
drop table sample_data_temp;
2+
3+
CREATE GLOBAL TEMPORARY TABLE sample_data_temp (
4+
id NUMBER,
5+
created_on date,
6+
random_number number
7+
)
8+
on commit preserve rows;
9+
10+
create or replace package sample_pkg as
11+
TYPE sample_data_tbl is table of sample_data%ROWTYPE;
12+
TYPE refcur_t IS REF CURSOR RETURN sample_data%ROWTYPE;
13+
14+
function get_sample_data(p_min_id IN NUMBER) return sample_data_tbl
15+
pipelined;
16+
17+
function get_sample_data_dml(p_min_id IN NUMBER) return sample_data_tbl
18+
pipelined;
19+
20+
function get_sample_data_ref_cur(p IN refcur_t) return sample_data_tbl
21+
pipelined;
22+
end;
23+
/
24+
25+
create or replace package body sample_pkg as
26+
function get_sample_data(p_min_id IN NUMBER) return sample_data_tbl
27+
PIPELINED as
28+
cursor sample_data_cur is
29+
SELECT * FROM sample_data where id > p_min_id order by id asc;
30+
begin
31+
for current_row in sample_data_cur loop
32+
pipe row(current_row);
33+
end loop;
34+
end get_sample_data;
35+
36+
function get_sample_data_dml(p_min_id IN NUMBER) return sample_data_tbl
37+
PIPELINED as
38+
PRAGMA AUTONOMOUS_TRANSACTION;
39+
cursor sample_data_cur is
40+
SELECT * FROM sample_data_temp where id > p_min_id order by id asc;
41+
begin
42+
execute immediate 'delete from sample_data_temp';
43+
insert into sample_data_temp select * from sample_data where id > p_min_id;
44+
-- other DML here
45+
commit;
46+
47+
for current_row in sample_data_cur loop
48+
pipe row(current_row);
49+
end loop;
50+
51+
return;
52+
end get_sample_data_dml;
53+
54+
55+
function get_sample_data_ref_cur(p IN refcur_t) return sample_data_tbl
56+
PIPELINED is
57+
in_rec p%rowtype;
58+
59+
begin
60+
loop
61+
FETCH p INTO in_rec; -- input row
62+
EXIT WHEN p%NOTFOUND;
63+
pipe row(in_rec);
64+
end loop;
65+
close p;
66+
return;
67+
end get_sample_data_ref_cur;
68+
69+
end sample_pkg;
70+
/
71+
72+
-- SELECT * from TABLE( sample_pkg.get_sample_data(100));
73+
74+
-- SELECT * from TABLE( sample_pkg.get_sample_data_dml(100));
75+
76+
-- SELECT * from TABLE( sample_pkg.get_sample_data_ref_cur(
77+
-- cursor(select * from sample_data where id > 100))
78+
-- );
79+
80+
81+
-- | dbxquery connection="splunk_test_db12" query="SELECT * from TABLE( sample_pkg.get_sample_data(100))"
82+
-- | dbxquery connection="splunk_test_db12" query="SELECT * from TABLE( sample_pkg.get_sample_data_dml(100))"
83+
-- | dbxquery connection="splunk_test_db12" query="SELECT * from TABLE( sample_pkg.get_sample_data_ref_cur(cursor(select * from sample_data where id > 100)))"

0 commit comments

Comments
 (0)