-
Notifications
You must be signed in to change notification settings - Fork 849
/
Copy pathexample.sql
executable file
·156 lines (126 loc) · 3.11 KB
/
example.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
drop table doc
/
drop table doc_mirror
/
create table doc
(
rawid raw(20) primary key ,
doc_fmt varchar2(10),
doc_txt varchar2(255)
)
/
create table doc_mirror
(
doc_rowid rowid,
doc_fmt varchar2(10),
dummy varchar2(1)
)
/
drop trigger doc_mirror_update
/
create trigger doc_mirror_update
after insert or update on doc
for each row
begin
if inserting then
insert into doc_mirror values
(:new.rowid, :new.doc_fmt, 'X');
else /* updating */
update doc_mirror m set dummy = dummy
where m.doc_rowid = :new.rowid;
end if;
end;
/
insert into doc values (
hextoraw('FF01'), 'BINARY', 'hello world')
/
insert into doc values (
hextoraw('FF02'), 'TEXT', 'the quick brown fox')
/
select count(*) from doc_mirror
/
-- ctxsys must own the user datastore procedure
connect ctxsys/ctxsys
create or replace procedure sercoproc
(
rid in rowid,
tlob in out NOCOPY clob /* NOCOPY instructs Oracle to pass
this argument as fast as possible */
)
is
tmpbuff varchar2(4000);
begin
select d.doc_txt into tmpbuff
from roger.doc d, roger.doc_mirror m
where d.rowid = m.doc_rowid
and m.rowid = rid;
dbms_lob.write (tlob, length(tmpbuff), 1, tmpbuff);
end;
/
-- list if inserting then if inserting then
show errors
grant execute on sercoproc to public
/
connect roger/roger
exec ctx_ddl.drop_preference ('my_user_ds')
exec ctx_ddl.create_preference ('my_user_ds', 'user_datastore')
exec ctx_ddl.set_attribute ('my_user_ds', 'PROCEDURE', 'sercoproc')
create index doc_mirror_index on doc_mirror (dummy)
indextype is ctxsys.context
parameters ('datastore my_user_ds')
/
-- check what's in the index
select token_text from dr$doc_mirror_index$i
/
-- test updates
update doc set doc_txt = 'the quick brown rabbit'
where doc_txt = 'the quick brown fox'
/
exec ctx_ddl.sync_index('doc_mirror_index')
-- check what's in the index
select token_text from dr$doc_mirror_index$i
/
select rawtohex(rawid), doc_txt
from doc d, doc_mirror m
where contains (dummy, 'quick') > 0
and d.rowid = m.doc_rowid
/
-- this next section tests the user datastore procedure
-- by simulating the calls to it and printing the output
connect roger/roger
Set ServerOutput On
declare
tlob clob;
buff varchar2(4000);
amnt integer;
begin
for j in
(
select rowid from doc_mirror
)
loop
/* this is what the ctx calling env does */
Dbms_Lob.CreateTemporary
(
lob_loc => tlob,
cache => true,
dur => Dbms_Lob.Session
);
ctxsys.sercoproc ( j.rowid, tlob );
amnt := 4000;
Dbms_Lob.Read
(
lob_loc => tlob,
amount => amnt,
offset => 1,
buffer => buff
);
Dbms_Output.Put_Line ( buff );
/* this is again what the ctx calling env does */
Dbms_Lob.FreeTemporary
(
lob_loc => tlob
);
end loop;
end;
/