您在創建數據遷移或數據同步任務時,指定需要遷移或同步的對象后,數據傳輸會自動過濾不支持的表,可能會導致識別出的表數量和實際需要遷移或同步的表數量不一致,您可以通過本文的 SQL 語句進行查詢。
查詢表的基本信息
不同數據源類型查詢表基本信息的 SQL 語句如下。
MySQL 數據源
SELECT NULL TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_ROWS, TABLE_COLLATION, ENGINE FROM information_schema.tables WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA NOT IN( 'mysql', 'information_schema', 'performance_schema' ) AND TABLE_SCHEMA IN () AND TABLE_NAME IN ();
OceanBase 數據庫 MySQL 租戶數據源
SELECT /*+ query_timeout(600000000)*/ NULL TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_ROWS, TABLE_COLLATION, ENGINE FROM information_schema.tables WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA NOT IN( 'mysql', 'information_schema', 'performance_schema' ) AND BINARY TABLE_SCHEMA IN () AND BINARY TABLE_NAME IN ();
OceanBase 數據庫 Oracle 租戶數據源
SELECT /*+ query_timeout(600000000)*/ NULL, A.OWNER, A.TABLE_NAME, A.NUM_ROWS, A.PARTITIONED, A.IOT_TYPE FROM ALL_TABLES A WHERE A.TABLE_NAME IN ( SELECT OBJECT_NAME FROM ALL_OBJECTS WHERE UPPER(OBJECT_TYPE) = 'TABLE' ) AND A.OWNER NOT IN ('SYSTEM', 'SYS') AND A.TEMPORARY = 'N' AND A.OWNER IN () AND A.TABLE_NAME IN ();
Oracle 數據源
SELECT NULL, A.OWNER, A.TABLE_NAME, A.NUM_ROWS, A.PARTITIONED, A.IOT_TYPE FROM ALL_TABLES A WHERE (A.OWNER, A.TABLE_NAME) NOT IN ( SELECT OWNER, MVIEW_NAME FROM ALL_MVIEWS UNION ALL SELECT LOG_OWNER, LOG_TABLE FROM ALL_MVIEW_LOGS ) AND A.OWNER NOT IN ('SYSTEM', 'SYS') AND A.TEMPORARY = 'N' AND A.OWNER IN () AND A.TABLE_NAME IN ();
PostgreSQL 數據源
SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME FROM information_schema.tables WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA <> 'pg_catalog' AND TABLE_SCHEMA <> 'information_schema' AND TABLE_SCHEMA IN () AND TABLE_NAME IN ();
過濾外表
數據傳輸會默認過濾掉外表的遷移/同步,不同數據源類型過濾外表的 SQL 語句如下。
Oracle 數據源
SELECT NULL,A.OWNER,A.TABLE_NAME,A.NUM_ROWS,A.PARTITIONED,A.IOT_TYPE FROM ALL_TABLES A WHERE (A.OWNER,A.TABLE_NAME) NOT IN ( SELECT OWNER,MVIEW_NAME FROM ALL_MVIEWS UNION ALL SELECT LOG_OWNER,LOG_TABLE FROM ALL_MVIEW_LOGS) AND A.OWNER NOT IN ('SYSTEM','SYS') AND A.TEMPORARY='N' AND A.EXTERNAL != 'YES' %s
OceanBase 數據庫 Oracle 租戶
SELECT /*HINT*/ NULL,A.OWNER,A.TABLE_NAME,A.NUM_ROWS,A.PARTITIONED,A.IOT_TYPE FROM ALL_TABLES A WHERE A.TABLE_NAME IN ( SELECT OBJECT_NAME FROM ALL_OBJECTS WHERE UPPER(OBJECT_TYPE)='TABLE' ) AND A.OWNER NOT IN ('SYSTEM','SYS') AND A.TEMPORARY='N' AND A.EXTERNAL != 'YES' %s
查詢視圖
不同數據源類型查詢視圖的 SQL 語句如下。
MySQL 數據源
SELECT TABLE_NAME, TABLE_SCHEMA, VIEW_DEFINITION FROM information_schema.views WHERE TABLE_SCHEMA IN ();
OceanBase 數據庫 MySQL 租戶數據源
SELECT TABLE_NAME, TABLE_SCHEMA, VIEW_DEFINITION FROM information_schema.views WHERE TABLE_SCHEMA IN ();
OceanBase 數據庫 Oracle 租戶數據源
SELECT VIEW_NAME, OWNER FROM ALL_VIEWS WHERE OWNER IN () ORDER BY VIEW_NAME;
Oracle 數據源
SELECT VIEW_NAME, OWNER FROM ALL_VIEWS WHERE OWNER IN () ORDER BY VIEW_NAME;
查詢物化視圖
Oracle 數據源查詢物化視圖的 SQL 語句如下。
SELECT
MVIEW_NAME AS NAME,
OWNER
FROM
ALL_MVIEWS
WHERE
OWNER IN ()
UNION
SELECT
LOG_TABLE AS NAME,
LOG_OWNER
FROM
ALL_MVIEW_LOGS
WHERE
LOG_OWNER IN ();
查詢有主鍵的表
不同數據源類型查詢有主鍵的表的 SQL 語句如下。
MySQL 數據源
SELECT DISTINCT TABLE_NAME, TABLE_SCHEMA FROM information_schema.statistics WHERE TABLE_SCHEMA IN () AND upper(INDEX_NAME) = 'PRIMARY';
OceanBase 數據源 MySQL 租戶
SELECT DISTINCT TABLE_NAME, TABLE_SCHEMA FROM information_schema.statistics WHERE TABLE_SCHEMA IN () AND upper(INDEX_NAME) = 'PRIMARY';
Oracle 數據源
SELECT TABLE_NAME, OWNER FROM ALL_CONSTRAINTS WHERE OWNER IN () AND STATUS = 'ENABLED' AND VALIDATED = 'VALIDATED' AND CONSTRAINT_TYPE = 'P';
查詢有主鍵或非空唯一鍵的表
不同數據源類型查詢有主鍵或非空唯一鍵的表的 SQL 語句如下。
MySQL 數據源
SELECT DISTINCT TABLE_NAME, TABLE_SCHEMA FROM information_schema.statistics WHERE TABLE_SCHEMA IN () GROUP BY TABLE_SCHEMA, TABLE_NAME, INDEX_NAME HAVING count(*) = count( IF( upper(nullable) != 'YES' AND NON_UNIQUE = 0, 1, NULL ) );
OceanBase 數據庫 MySQL 租戶數據源
SELECT DISTINCT TABLE_NAME, TABLE_SCHEMA FROM information_schema.statistics WHERE TABLE_SCHEMA IN () GROUP BY TABLE_SCHEMA, TABLE_NAME, INDEX_NAME HAVING count(*) = count( IF( upper(nullable) != 'YES' and NON_UNIQUE = 0, 1, NULL ) );
Oracle 數據源
SELECT TABLE_NAME, OWNER FROM ALL_CONSTRAINTS WHERE OWNER IN () AND STATUS = 'ENABLED' AND VALIDATED = 'VALIDATED' AND CONSTRAINT_TYPE = 'P';
OceanBase 數據庫 Oracle 租戶數據源
SELECT /*+ query_timeout(600000000)*/ DISTINCT TABLE_NAME, OWNER FROM ( SELECT DC.OWNER, DC.TABLE_NAME, DC.CONSTRAINT_NAME FROM ALL_CONS_COLUMNS DCC JOIN ALL_CONSTRAINTS DC ON DCC.CONSTRAINT_NAME = DC.CONSTRAINT_NAME AND DCC.OWNER = DC.OWNER JOIN ALL_TAB_COLUMNS DTC ON DCC.COLUMN_NAME = DTC.COLUMN_NAME AND DCC.OWNER = DTC.OWNER AND DCC.TABLE_NAME = DTC.TABLE_NAME WHERE DCC.OWNER IN () AND DC.CONSTRAINT_TYPE IN ('U', 'P') GROUP BY DC.OWNER, DC.TABLE_NAME, DC.CONSTRAINT_NAME HAVING COUNT(*) = COUNT( CASE DTC.NULLABLE WHEN 'Y' THEN NULL ELSE 1 END ) MINUS SELECT TABLE_OWNER, TABLE_NAME, INDEX_NAME FROM ALL_IND_EXPRESSIONS WHERE TABLE_OWNER IN () );
查詢有 UNIQUE 函數索引的表
不同數據源類型查詢有 UNIQUE 函數索引的表的 SQL 語句如下。
Oracle 數據源
SELECT DISTINCT A.TABLE_NAME, A.TABLE_OWNER FROM ALL_IND_EXPRESSIONS A JOIN ALL_INDEXES B ON A.TABLE_OWNER = B.TABLE_OWNER AND A.TABLE_NAME = B.TABLE_NAME AND A.INDEX_NAME = B.INDEX_NAME WHERE A.TABLE_OWNER IN () AND B.UNIQUENESS = 'UNIQUE';
OceanBase 數據庫 Oracle 租戶數據源
SELECT /*+ query_timeout(600000000)*/ DISTINCT A.TABLE_NAME, A.TABLE_OWNER FROM ALL_IND_EXPRESSIONS A JOIN ALL_INDEXES B ON A.TABLE_OWNER = B.TABLE_OWNER AND A.TABLE_NAME = B.TABLE_NAME AND A.INDEX_NAME = B.INDEX_NAME WHERE A.TABLE_OWNER IN () AND B.UNIQUENESS = 'UNIQUE';
查詢是否存在某些數據類型的表
不同數據源查詢是否存在某些數據類型的表的 SQL 語句如下。
Oracle 數據源
SELECT DISTINCT TABLE_NAME AS TABLENAME, OWNER AS DBNAME FROM all_tab_columns WHERE OWNER IN () AND DATA_TYPE IN / NOT IN ();
MySQL 數據源
SELECT DISTINCT TABLE_NAME AS TABLENAME, TABLE_SCHEMA FROM information_schema.COLUMNS WHERE TABLE_SCHEMA IN () AND DATA_TYPE IN / NOT IN ();
查詢有主鍵且包含某些數據類型的表
不同數據源類型查詢有主鍵且包含某些數據類型的表的 SQL 語句如下。
OceanBase 數據庫 MySQL 租戶數據源
SELECT DISTINCT TABLE_NAME, TABLE_SCHEMA FROM information_schema.COLUMNS WHERE UPPER(COLUMN_KEY) = 'PRI' AND TABLE_SCHEMA IN () AND UPPER(COLUMN_TYPE) IN ();
MySQL 數據源
SELECT DISTINCT TABLE_NAME, TABLE_SCHEMA FROM information_schema.COLUMNS WHERE UPPER(COLUMN_KEY) = 'PRI' AND TABLE_SCHEMA IN () AND UPPER(COLUMN_TYPE) IN ();
查詢包含 LOB 類型的表
不同數據源類型查詢包含 LOB 類型的表的 SQL 語句如下。
Oracle 數據源
SELECT DISTINCT TABLE_NAME, OWNER FROM ALL_LOBS WHERE OWNER IN ();
OceanBase 數據庫 Oracle 租戶數據源
SELECT /*+ query_timeout(600000000)*/ DISTINCT TABLE_NAME, OWNER FROM ALL_TAB_COLUMNS WHERE DATA_TYPE IN ('BLOB', 'CLOB') AND OWNER IN ();
查詢 Oracle 數據庫中 row_movement 為 DISABLED 的表
SELECT
TABLE_NAME,
OWNER
FROM
ALL_TABLES
WHERE
OWNER IN ()
AND ROW_MOVEMENT = 'DISABLED';
查詢 OceanBase 數據庫中包含 pseudo 列的表
OceanBase 數據庫 MySQL 租戶
SELECT DISTINCT TABLE_NAME, TABLE_SCHEMA FROM information_schema.columns WHERE TABLE_SCHEMA IN () AND COLUMN_NAME in ( 'OMS_PK_INCRMT', 'OMS_OBJECT_NUMBER', 'OMS_RELATIVE_FNO', 'OMS_BLOCK_NUMBER', 'OMS_ROW_NUMBER' );
OceanBase 數據庫 Oracle 租戶
SELECT DISTINCT TABLE_NAME, OWNER FROM ALL_TAB_COLUMNS WHERE OWNER IN () AND COLUMN_NAME IN ( 'OMS_PK_INCRMT', 'OMS_OBJECT_NUMBER', 'OMS_RELATIVE_FNO', 'OMS_BLOCK_NUMBER', 'OMS_ROW_NUMBER' );
查詢列數量超過指定值的表
不同數據源類型查詢列數量超過指定值的表的 SQL 語句如下。
Oracle 數據源
SELECT TABLE_NAME, OWNER FROM ALL_TAB_COLUMNS WHERE OWNER = ? GROUP BY TABLE_NAME, OWNER HAVING COUNT(1) > ?;
OceanBase 數據庫 Oracle 租戶數據源
SELECT /*+ query_timeout(600000000)*/ TABLE_NAME, OWNER FROM ALL_TAB_COLUMNS WHERE OWNER = ? GROUP BY TABLE_NAME, OWNER HAVING COUNT(1) > ?;