將Mysql表復制到Oracle時非法使用長數據類型

[英]illegal use of LONG datatype while copying Mysql table to Oracle


I have a MySQL and a Oracle server. I have to periodically copy some tables from MySQL to Oracle server and this is done via a scheduled PLSQL procedure and for this I have created a DBLINK between MySQL and Oracle. Everything is working fine until I had to copy one table which started giving error

我有一個MySQL和一個Oracle服務器。我必須定期地從MySQL復制一些表到Oracle服務器,這是通過一個預定的PLSQL過程完成的,為此我在MySQL和Oracle之間創建了一個DBLINK。一切正常,直到我不得不復制一個開始出錯的表

Example

例子

create table table_to_copy
as
select * from table_to_copy@DBLINK;

"oracle sql error ora-00997 illegal use of long datatype"

“oracle sql error ora-00997非法使用長數據類型”


I have read couple of comments and this is mostly because of implicit conversion and most of the suggestions were to perform explicit to_lob conversion. But doing anything manual is not a feasible option.

我讀過一些評論,這主要是因為隱式轉換,大多數建議是執行顯式to_lob轉換。但是手工操作並不是一個可行的選擇。

Please note that

請注意,

  • work arrangement is such I do not have any access to MySQL server the only thing I get is table name and have DBLINK. So I can only pull data using select statement
  • 工作安排是這樣的,我沒有任何訪問MySQL服務器的唯一我得到的東西是表名和有DBLINK。所以我只能使用select語句來提取數據
  • Solution for above mentioned issue has to be dealt in some kind of automated fix. This is because the request for table copy can be hundreds of table as any given point and I cannot go through all tables to fix/check manually.
  • 上述問題的解決方案必須通過某種自動修復來解決。這是因為對表復制的請求可以像任何給定的點一樣有數百個表,我不能遍歷所有表來手動修復/檢查。

Please help, your expert comments are highly valuable for me.

請幫忙,你的專家意見對我很有價值。

Note : there are some other questions here which might look similar like Illegal use of LONG datatype Oracle but they don't have the solution to what I am looking for.

注意:這里還有一些其他問題,可能類似於非法使用長數據類型Oracle,但是它們沒有解決我所尋找的問題。

1 个解决方案

#1


0  

I appreciate that this is rather late, and that I don't have this exact setup. However, what I have done from Oracle (11gR2) to SQL Server (2008R2 and earlier) is to read INFORMATION_SCHEMA.COLUMNS through the database link and then dynamically generate a string to EXECUTE IMMEDIATE in PL/SQL.

我很感激這已經很晚了,而且我沒有這樣的設置。然而,我從Oracle (11gR2)到SQL Server (2008R2及更早的版本)所做的就是讀取INFORMATION_SCHEMA。通過數據庫鏈接的列,然后動態地生成一個字符串,以在PL/SQL中立即執行。

DECLARE
  TYPE associative_array IS TABLE OF VARCHAR2(100) INDEX BY VARCHAR2(50);

  data_type_tranforms associative_array;
  dynamicSQL varchar2(32767);
  column_list varchar2(32767) := '';
  expressions varchar2(32767) := '';

  FUNCTION apply_transform(column_name VARCHAR2, data_type VARCHAR2) RETURN VARCHAR2 AS
    transformed VARCHAR2(1000);
  BEGIN
    IF data_type_transforms.exists(data_type) THEN
      transformed :=  replace(data_type_transforms(data_type),'$$',column_name);
    ELSE
      transformed := column_name;
    END IF;
    RETURN transformed;
  END apply_transform;

  FUNCTION strip_last_character(input VARCHAR2) RETURN VARCHAR2 AS
    /* Remove the delimiter trailing after the last entry */
  BEGIN
    RETURN SUBSTR(input, 1, LENGTH(input) - 1);
  END strip_last_character;

BEGIN
  data_type_transforms('LONG') := 'to_lob($$)';

  FOR col IN (
    SELECT column_name
      ,data_type
    FROM information_schema.columns@DBLINK
    WHERE table_name = 'TABLE_TO_COPY'
    ORDER BY ordinal_position
  ) LOOP
    column_list := column_list || col.column_name ||',';
    expressions := expressions || apply_transform(col.column_name, col.data_type) ||','; 
  END LOOP;
  dynamicSQL := 'INSERT INTO table_to_copy ('||
    strip_last_character(column_list)||
    ') SELECT '||
    strip_last_character(expressions)||
    ' FROM table_to_copy@DBLINK';

  EXECUTE IMMEDIATE dynamicSQL;
END;

I keep a series of templates in a PL/SQL index-by array, with the index being a data type and the value being an expression like 'to_date(''$$'',''YYYYMMDD'')' from which the characters $$ get replaced with the column_name. If you need to drop a data type entirely, which I often do, I just put an empty string in the data-type array.

我在PL/SQL index-by數組中保存了一系列模板,索引是一種數據類型,值是一個表達式,比如'to_date(" $ "、" yyyyymmdd ")'。如果您需要完全刪除數據類型(我經常這樣做),我只需在數據類型數組中放入一個空字符串。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/12/20/712f1934f6446a44655de8d15a329fa3.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com