Referencing Oracle user defined types over DBLINK?

前端 未结 2 1682
眼角桃花
眼角桃花 2020-12-17 05:55

I\'m working in two different Oracle schemas on two different instances of Oracle. I\'ve defined several types and type collections to transfer data between these schemas.

相关标签:
2条回答
  • 2020-12-17 06:02

    I have read the Oracle Documentation and it is not very difficult.

    You need to add an OID to your type definitions in both databases.

    You can use a GUID as OID.

    SELECT SYS_OP_GUID() FROM DUAL; 
    
    SYS_OP_GUID()
    --------------------------------
    AE34B912631948F0B274D778A29F6C8C
    

    Now create your UDT in both databases with the SAME OID.

    create type testlinktype oid 'AE34B912631948F0B274D778A29F6C8C' as object
    ( v1 varchar2(10) , v2 varchar2(20) );
    /
    

    Now create a table:

    create table testlink 
    ( name testlinktype);
    
    insert into testlink values (testlinktype ('RC','AB'));
    
    commit;
    

    Now you can select from the table via the dblink in the other database:

    select * from testlink@to_ora10;
    
    NAME(V1, V2)
    --------------------------
    TESTLINKTYPE('RC', 'AB')
    

    If you get error ORA-21700 when you try to select via the dblink the first time, just reconnect.

    0 讨论(0)
  • 2020-12-17 06:17

    I think the underlying issue is that Oracle doesn't know how to automatically serialize/deserialize your custom type over the wire, so to speak.

    Your best bet is probably to pass an XML (or other) representation over the link.

    0 讨论(0)
提交回复
热议问题