DBLink中,对于CLOB字段的处理需要相对比较特殊些。
- 不做任务处理,例如执行“SELECT MODE_CODE,TRANSFORM_CHANGE_CONTENT from PROD_INTERRUPTION_MODE@LINK2SERVER516 WHERE ROWNUM<=10”,其中“TRANSFORM_CHANGE_CONTENT”为CLOB字段,则会报“ORA-22992: cannot use LOB locators selected from remote tables”的错误。
- 采用临时表方式实现对LOB字段的选取:
创建一个临时表“create global temporary table TMP_TBL_MODE(
MODE_CODE VARCHAR2(16),
TRANSFORM_CHANGE_CONTENT CLOB
)on commit delete rows;”,
再执行“INSERT INTO TMP_TBL_MODE SELECT MODE_CODE,TRANSFORM_CHANGE_CONTENT from PROD_INTERRUPTION_MODE@LINK2SERVER516;”后,临时表中就将对应的数据选取过来了,最后再通过执行“SELECT * from TMP_TBL_MODE;”,即可查看到结构,验证OK - 采用将CLOB转换为VARCHAR的方式实现:
首先需要用到函数“dbms_lob.substr( clob_column, for_how_many_bytes, from_which_byte );”
通过创建如下视图:
CREATE OR REPLACE VIEW DBLINK_V_MODE_TET AS
SELECT MODE_CODE, dbms_lob.substr(TRANSFORM_CHANGE_CONTENT,4000,1) TRANSFORM_CHANGE_CONTENT
FROM PROD_INTERRUPTION_MODE
WHERE ROWNUM <= 10;
通过执行“SELECT MODE_CODE,TRANSFORM_CHANGE_CONTENT from DBLINK_V_MODE_TET@LINK2SERVER516;”,即可实现查看到结果,验证OK