[20210723]Database link and user defined datatypes.txt

lfree發表於2021-07-23

[20210723]Database link and user defined datatypes.txt

--//如何透過db link訪問使用者定義型別.按照連結做測試.


1.環境:
SCOTT@book> @ ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

2.測試:
create type tt as object (x number);
/
create table t (x tt);
insert into t values (tt(1));
commit;

SCOTT@book> select t.x.x from t t;
       X.X
----------
         1

--//OK,本地訪問沒有問題.

CREATE PUBLIC DATABASE LINK LOOPBACK USING 'localhost:1521/book';

SCOTT@book> select t.x.x from t@LOOPBACK t;
       X.X
----------
         1

--//採用本地loopback測試不出來.

3.繼續:
CREATE PUBLIC DATABASE LINK L78
 CONNECT TO SCOTT
 IDENTIFIED BY <Password>
 USING '192.168.100.78:1521/book';

SCOTT@test> select sysdate from dual@l78;
SYSDATE
-------------------
2021-07-23 09:47:24

--//OK.

SCOTT@test> select t.x.x from t@L78 t;
select t.x.x from t@L78 t
       *
ERROR at line 1:
ORA-22804: remote operations not permitted on object tables or user-defined type columns

SCOTT@test> select type_name,TYPE_OID from user_types@L78;
TYPE_NAME                      TYPE_OID
------------------------------ --------------------------------
TT                             C7C175F2E6ED5C33E0534E64A8C010B5

SCOTT@test> create type tt oid 'C7C175F2E6ED5C33E0534E64A8C010B5' as object(x number)
  2  /

Type created.
--//視乎建立的type不指定可以唯一.

SCOTT@test> select t.x.x from t@L78 t;
       X.X
----------
         1

--//感覺type的東西很少用,做一個記錄.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2782847/,如需轉載,請註明出處,否則將追究法律責任。

相關文章