-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathoracle.out
421 lines (366 loc) · 10.4 KB
/
oracle.out
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
CREATE FOREIGN DATA WRAPPER oracle VALIDATOR dblink.oracle;
CREATE SERVER server_oracle FOREIGN DATA WRAPPER oracle OPTIONS (dbname 'dbt');
CREATE USER MAPPING FOR CURRENT_USER SERVER server_oracle OPTIONS (user 'scott', password 'tiger');
CREATE SERVER server_oracle2 FOREIGN DATA WRAPPER oracle OPTIONS (dbname 'dbt', max_value_len '4');
CREATE USER MAPPING FOR CURRENT_USER SERVER server_oracle2 OPTIONS (user 'scott', password 'tiger');
CREATE SERVER server_oracle3 FOREIGN DATA WRAPPER oracle OPTIONS (dbname 'dbt', max_value_len '3');
CREATE USER MAPPING FOR CURRENT_USER SERVER server_oracle3 OPTIONS (user 'scott', password 'tiger');
SELECT dblink.connect('conn_ora', 'server_oracle', false);
connect
---------
t
(1 row)
SELECT dblink.exec('conn_ora', 'CREATE TABLE dblink_tbl (id NUMBER(4), value VARCHAR2(100))');
exec
------
0
(1 row)
SELECT dblink.exec('conn_ora', 'CREATE TABLE lob_test (id NUMBER(5), value CLOB, value2 CLOB)');
exec
------
0
(1 row)
SELECT dblink.disconnect('conn_ora');
disconnect
------------
t
(1 row)
SELECT dblink.exec('server_oracle', 'INSERT INTO dblink_tbl VALUES(1, ''X'')');
exec
------
1
(1 row)
SELECT dblink.exec('server_oracle', 'INSERT INTO dblink_tbl VALUES(2, ''BB'')');
exec
------
1
(1 row)
SELECT dblink.exec('server_oracle', 'INSERT INTO dblink_tbl VALUES(3, ''CCC'')');
exec
------
1
(1 row)
SELECT dblink.exec('server_oracle', 'INSERT INTO dblink_tbl VALUES(4, ''DDDD'')');
exec
------
1
(1 row)
SELECT dblink.exec('server_oracle', 'INSERT INTO dblink_tbl VALUES(5, NULL)');
exec
------
1
(1 row)
CREATE TABLE dblink.dblink_tmp_ora (LIKE dblink.dblink_tbl);
CREATE FUNCTION dblink.cursor_test_ora(cursor integer, howmany integer)
RETURNS SETOF dblink.dblink_tmp_ora AS
$$
TRUNCATE dblink.dblink_tmp_ora;
INSERT INTO dblink.dblink_tmp_ora SELECT * FROM dblink.fetch($1, $2) AS t(id integer, value text);
INSERT INTO dblink.dblink_tmp_ora SELECT * FROM dblink.fetch($1, $2) AS t(id integer, value text);
INSERT INTO dblink.dblink_tmp_ora SELECT * FROM dblink.fetch($1, $2) AS t(id integer, value text);
SELECT * FROM dblink.dblink_tmp_ora;
$$
LANGUAGE sql;
-- dblink.connect()
SELECT name, srvname, status, keep FROM dblink.connections, pg_foreign_server WHERE server = oid;
name | srvname | status | keep
------+---------+--------+------
(0 rows)
SELECT dblink.connect('conn_oracle', 'server_oracle');
connect
---------
t
(1 row)
SELECT name, srvname, status, keep FROM dblink.connections, pg_foreign_server WHERE server = oid;
name | srvname | status | keep
-------------+---------------+--------+------
conn_oracle | server_oracle | idle | t
(1 row)
-- dblink.exec() with an existing connection
SELECT * FROM dblink.query('conn_oracle', 'SELECT * FROM dblink_tbl ORDER BY id') AS t(i int, v text);
i | v
---+------
1 | X
2 | BB
3 | CCC
4 | DDDD
5 |
(5 rows)
BEGIN;
SELECT dblink.exec('conn_oracle', 'UPDATE dblink_tbl SET value = ''A'' WHERE id = 1');
exec
------
1
(1 row)
SELECT name, srvname, status, keep FROM dblink.connections, pg_foreign_server WHERE server = oid;
name | srvname | status | keep
-------------+---------------+--------+------
conn_oracle | server_oracle | used | t
(1 row)
ROLLBACK;
SELECT * FROM dblink.query('conn_oracle', 'SELECT * FROM dblink_tbl ORDER BY id') AS t(i int, v text);
i | v
---+------
1 | X
2 | BB
3 | CCC
4 | DDDD
5 |
(5 rows)
BEGIN;
SELECT dblink.exec('conn_oracle', 'UPDATE dblink_tbl SET value = ''A'' WHERE id = 1');
exec
------
1
(1 row)
SELECT name, srvname, status, keep FROM dblink.connections, pg_foreign_server WHERE server = oid;
name | srvname | status | keep
-------------+---------------+--------+------
conn_oracle | server_oracle | used | t
(1 row)
COMMIT;
SELECT * FROM dblink.query('conn_oracle', 'SELECT * FROM dblink_tbl ORDER BY id') AS t(i int, v text);
i | v
---+------
1 | A
2 | BB
3 | CCC
4 | DDDD
5 |
(5 rows)
-- dblink.query() with an existing connection
BEGIN;
SELECT * FROM dblink.query('conn_oracle', 'SELECT * FROM dblink_tbl ORDER BY id') AS t(id integer, value text) ORDER BY id;
id | value
----+-------
1 | A
2 | BB
3 | CCC
4 | DDDD
5 |
(5 rows)
SELECT name, srvname, status, keep FROM dblink.connections, pg_foreign_server WHERE server = oid;
name | srvname | status | keep
-------------+---------------+--------+------
conn_oracle | server_oracle | used | t
(1 row)
COMMIT;
-- dblink.open() with an existing connection
SELECT * FROM dblink.cursor_test_ora(dblink.open('conn_oracle', 'SELECT * FROM dblink_tbl ORDER BY id'), 100);
id | value
----+-------
1 | A
2 | BB
3 | CCC
4 | DDDD
5 |
(5 rows)
SELECT * FROM dblink.cursor_test_ora(dblink.open('conn_oracle', 'SELECT * FROM dblink_tbl ORDER BY id'), 2);
id | value
----+-------
1 | A
2 | BB
3 | CCC
4 | DDDD
5 |
(5 rows)
SELECT * FROM dblink.cursor_test_ora(dblink.open('conn_oracle', 'SELECT * FROM dblink_tbl ORDER BY id'), 1);
id | value
----+-------
1 | A
2 | BB
3 | CCC
(3 rows)
-- dblink.disconnect()
SELECT name, srvname, status, keep FROM dblink.connections, pg_foreign_server WHERE server = oid;
name | srvname | status | keep
-------------+---------------+--------+------
conn_oracle | server_oracle | idle | t
(1 row)
SELECT dblink.disconnect('conn_oracle');
disconnect
------------
t
(1 row)
SELECT name, srvname, status, keep FROM dblink.connections, pg_foreign_server WHERE server = oid;
name | srvname | status | keep
------+---------+--------+------
(0 rows)
-- dblink.query() with an anonymous connection
BEGIN;
SELECT * FROM dblink.query('server_oracle', 'SELECT * FROM dblink_tbl ORDER BY id') AS t(id integer, value text) ORDER BY id;
id | value
----+-------
1 | A
2 | BB
3 | CCC
4 | DDDD
5 |
(5 rows)
SELECT name, srvname, status, keep FROM dblink.connections, pg_foreign_server WHERE server = oid;
name | srvname | status | keep
---------------+---------------+--------+------
server_oracle | server_oracle | used | f
(1 row)
COMMIT;
SELECT name, srvname, status, keep FROM dblink.connections, pg_foreign_server WHERE server = oid;
name | srvname | status | keep
------+---------+--------+------
(0 rows)
-- dblink.exec() with an anonymous connection
BEGIN;
SELECT dblink.exec('server_oracle', 'UPDATE dblink_tbl SET value = value WHERE id < 3');
exec
------
2
(1 row)
SELECT name, srvname, status, keep FROM dblink.connections, pg_foreign_server WHERE server = oid;
name | srvname | status | keep
---------------+---------------+--------+------
server_oracle | server_oracle | used | f
(1 row)
COMMIT;
SELECT name, srvname, status, keep FROM dblink.connections, pg_foreign_server WHERE server = oid;
name | srvname | status | keep
------+---------+--------+------
(0 rows)
-- dblink.open() with an anonymous connection
SELECT * FROM dblink.cursor_test_ora(dblink.open('server_oracle', 'SELECT * FROM dblink_tbl ORDER BY id'), 100);
id | value
----+-------
1 | A
2 | BB
3 | CCC
4 | DDDD
5 |
(5 rows)
SELECT * FROM dblink.cursor_test_ora(dblink.open('server_oracle', 'SELECT * FROM dblink_tbl ORDER BY id'), 2);
id | value
----+-------
1 | A
2 | BB
3 | CCC
4 | DDDD
5 |
(5 rows)
SELECT * FROM dblink.cursor_test_ora(dblink.open('server_oracle', 'SELECT * FROM dblink_tbl ORDER BY id'), 1);
id | value
----+-------
1 | A
2 | BB
3 | CCC
(3 rows)
SELECT name, srvname, status, keep FROM dblink.connections, pg_foreign_server WHERE server = oid;
name | srvname | status | keep
------+---------+--------+------
(0 rows)
-- CLOB data read
SELECT dblink.exec('server_oracle', 'insert into lob_test values(1, lpad(''Z'', 2000, ''Z''), lpad(''z'', 1000, ''z''))');
exec
------
1
(1 row)
SELECT dblink.exec('server_oracle', 'insert into lob_test values(2, lpad(''Y'', 4000, ''Y''), lpad(''y'', 3000, ''y''))');
exec
------
1
(1 row)
SELECT id, length(value), length(value2) from dblink.query('server_oracle', 'select * from lob_test') as (id integer, value text, value2 text) order by id;
id | length | length
----+--------+--------
1 | 2000 | 1000
2 | 4000 | 3000
(2 rows)
-- dblink.query() with max_value_len option
SELECT * FROM dblink.query('server_oracle2', 'SELECT * FROM dblink_tbl ORDER BY id') AS t(id integer, value text) ORDER BY id;
id | value
----+-------
1 | A
2 | BB
3 | CCC
4 | DDDD
5 |
(5 rows)
SELECT * FROM dblink.query('server_oracle3', 'SELECT * FROM dblink_tbl ORDER BY id', 0, 4) AS t(id integer, value text) ORDER BY id;
id | value
----+-------
1 | A
2 | BB
3 | CCC
4 | DDDD
5 |
(5 rows)
-- dblink.open() with max_value_len option
SELECT * FROM dblink.cursor_test_ora(dblink.open('server_oracle', 'SELECT * FROM dblink_tbl ORDER BY id', 100, 4), 100);
id | value
----+-------
1 | A
2 | BB
3 | CCC
4 | DDDD
5 |
(5 rows)
-- connection without automatic transaction management
SELECT dblink.connect('conn_oracle', 'server_oracle', false);
connect
---------
t
(1 row)
SELECT dblink.exec('conn_oracle', 'DROP TABLE dblink_tbl');
exec
------
0
(1 row)
SELECT dblink.exec('conn_oracle', 'DROP TABLE lob_test');
exec
------
0
(1 row)
SELECT dblink.disconnect('conn_oracle');
disconnect
------------
t
(1 row)
SELECT dblink.connect('conn_oracle', 'server_oracle', false);
connect
---------
t
(1 row)
SELECT dblink.exec('conn_oracle', 'CREATE OR REPLACE PACKAGE dblink AS TYPE RT1 IS RECORD ( ret NUMBER ); TYPE RCT1 IS REF CURSOR RETURN RT1; PROCEDURE f_test(RC1 IN OUT RCT1, num IN NUMBER); END;');
exec
------
0
(1 row)
SELECT dblink.exec('conn_oracle', 'CREATE OR REPLACE PACKAGE BODY dblink AS PROCEDURE f_test(RC1 IN OUT RCT1, num IN NUMBER) AS BEGIN OPEN RC1 FOR select num + 1000 from dual; END f_test; END;');
exec
------
0
(1 row)
SELECT dblink.disconnect('conn_oracle');
disconnect
------------
t
(1 row)
-- dblink.call() with an anonymous connection
SELECT * FROM dblink.call('server_oracle', 'dblink.f_test(1)') AS t(a integer);
a
------
1001
(1 row)
-- dblink.call() with oracle standard library function as argument to oracle stored procedure
SELECT * FROM dblink.call('server_oracle', 'dblink.f_test(ceil(3.1))') AS t(a integer);
a
------
1004
(1 row)
-- dblink.call() with max_value_len option
SELECT * FROM dblink.call('server_oracle2', 'dblink.f_test(1)') AS t(a integer);
a
------
1001
(1 row)
SELECT * FROM dblink.call('server_oracle3', 'dblink.f_test(1)', 0, 4) AS t(a integer);
a
------
1001
(1 row)