-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclob_cursor.pkb
More file actions
86 lines (72 loc) · 2.27 KB
/
clob_cursor.pkb
File metadata and controls
86 lines (72 loc) · 2.27 KB
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
77
78
79
80
81
82
83
84
85
86
CREATE OR REPLACE PACKAGE BODY "ORASVN"."CLOB_CURSOR"
IS
/*
This file is part of OraSVN: https://sourceforge.net/projects/orasvn/
OraSVN is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OraSVN is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
g_clob clob;
g_has_next boolean := false;
g_file_length BINARY_INTEGER;
g_start BINARY_INTEGER := 1;
procedure init(i_clob in clob)
is
begin
g_clob := i_clob;
g_file_length := dbms_lob.getlength(g_clob);
g_start := 1;
if g_file_length > 0 then g_has_next := true; end if;
end;
function fetch_line return varchar2
IS
r_record VARCHAR2 (240);
end_pos INTEGER;
BEGIN
-- check clob
if g_clob is null then
raise_application_error(-20100, 'can not fetch line, clob cursor is closed');
end if;
-- check length
if g_file_length is null then return null; end if;
end_pos :=
DBMS_LOB.INSTR (lob_loc => g_clob, pattern => CHR (10), offset => g_start);
IF end_pos > 0 THEN
r_record :=
RTRIM (
DBMS_LOB.SUBSTR(
lob_loc => g_clob
,amount => LEAST (end_pos - g_start, 240)
,offset => g_start
)
,CHR (13) || CHR (10)
);
g_start := end_pos + 1;
ELSE
r_record := DBMS_LOB.SUBSTR (
lob_loc => g_clob
,amount => g_file_length - g_start + 1
,offset => g_start
);
g_start := 0;
g_clob := null;
g_file_length := null;
g_has_next := false;
END IF;
RETURN r_record;
END fetch_line;
-- iterater for cursor
function has_next return boolean
is
begin
return g_has_next;
end;
END clob_cursor;
/