
ora2pg 是怎么處理 Oracle 到 PostgreSQL 的數(shù)據(jù)類型轉(zhuǎn)換
參考文章:https://ora2pg.darold.net/documentation.html#Column-type-control
數(shù)值類型
- PG_NUMERIC_TYPE
如果設(shè)置為 1,則將可變長度的數(shù)字類型替換為 PostgreSQL 內(nèi)部類型。 Oracle 數(shù)據(jù)類型 NUMBER(p,s) 近似轉(zhuǎn)換為 PostgreSQL的 real 和 float 數(shù)據(jù)類型。 如果有貨幣字段或不希望小數(shù)部分的截?cái)鄦栴},您應(yīng)該在 PostgreSQL 中保留相同的 numeric(p,s) 數(shù)據(jù)類型,僅當(dāng)您需要精確性時(shí)才這樣做,因?yàn)槭褂?numeric(p,s) 比使用 real 或 double 慢。
test_dml=# create table tt_number (id int primary key, col1 real, col2 double precision, col3 float, col4 numeric(25,23));
test_dml=# \d tt_number
Table "public.tt_number"
Column | Type | Collation | Nullable | Default
--------+------------------+-----------+----------+---------
id | integer | | not null |
col1 | real | | |
col2 | double precision | | |
col3 | double precision | | |
col4 | numeric(25,23) | | |
Indexes:
"tt_number_pkey" PRIMARY KEY, btree (id)
-- float 會(huì)轉(zhuǎn)成 double,這倆是一個(gè)類型
test_dml=# insert into tt_number values (1, 3.1415, 3.1415, 3.1415, 3.1415);
test_dml=# insert into tt_number values (2, 3.141592657777777, 3.141592657777777, 3.141592657777777, 3.141592657777777);
test_dml=# insert into tt_number values (3, 3.1415926577777777777777777777777777, 3.1415926577777777777777777777777777, 3.1415926577777777777777777777777777, 3.1415926577777777777777777777777777);
test_dml=# select * from tt_number;
id | col1 | col2 | col3 | col4
----+-----------+--------------------+--------------------+---------------------------
1 | 3.1415 | 3.1415 | 3.1415 | 3.14150000000000000000000
2 | 3.1415927 | 3.141592657777777 | 3.141592657777777 | 3.14159265777777700000000
3 | 3.1415927 | 3.1415926577777777 | 3.1415926577777777 | 3.14159265777777777777778
(3 rows)
-- real 類型截?cái)啾A粜?shù)后7位
-- double 類型截?cái)啾A粜?shù)后16位
-- numeric(p,s) 可以設(shè)置精度,對(duì)超出精度的部分進(jìn)行四舍五入
- PG_INTEGER_TYPE
如果設(shè)置為 1,則將可變長度的數(shù)字類型替換為 PostgreSQL 內(nèi)部類型。 Oracle 數(shù)據(jù)類型 NUMBER(p) 或 NUMBER 在精度值之后轉(zhuǎn)換為 PostgreSQL的 smallint、integer 或 bigint 數(shù)據(jù)類型,如果沒有精度的 NUMBER 替換為 DEFAULT_NUMERIC。 - DEFAULT_NUMERIC
僅當(dāng) PG_INTEGER_TYPE 為 true 時(shí),默認(rèn)情況下不帶精度的 NUMBER 才會(huì)轉(zhuǎn)換為 bigint,您可以將此值覆蓋為任何 PG 類型,例如 integer 或 float。
test_dml=# create table tt_number (id int primary key, col1 smallint, col2 integer, col3 bigint, col4 float, col5 numeric);
test_dml=# \d tt_number
Table "public.tt_number"
Column | Type | Collation | Nullable | Default
--------+------------------+-----------+----------+---------
id | integer | | not null |
col1 | smallint | | |
col2 | integer | | |
col3 | bigint | | |
col4 | double precision | | |
col5 | numeric | | |
Indexes:
"tt_number_pkey" PRIMARY KEY, btree (id)
test_dml=# insert into tt_number values (1, 32768, 2147483648, 2147483648, 2147483648, 2147483648);
ERROR: smallint out of range
test_dml=# insert into tt_number values (1, 32767, 2147483648, 2147483648, 2147483648, 2147483648);
ERROR: integer out of range
test_dml=# insert into tt_number values (1, 32767, 2147483647, 2147483648, 2147483648, 2147483648);
INSERT 0 1
test_dml=# select * from tt_number;
id | col1 | col2 | col3 | col4 | col5
----+-------+------------+------------+------------+------------
1 | 32767 | 2147483647 | 2147483648 | 2147483648 | 2147483648
(1 row)
-- smallint、integer、bigint 都是整型,smallint 的范圍是(2的15次方) -32768 ~ -32767,integer 的范圍是(2的31次方) -2147483648 ~ -2147483647,bigint 的范圍(2的63次方) 。
| 數(shù)據(jù)類型 | ora2pg轉(zhuǎn)換參數(shù) | 轉(zhuǎn)換后的類型 |
|---|---|---|
| NUMBER(p,s) | PG_NUMERIC_TYPE=1 | real、float、double |
| - | PG_NUMERIC_TYPE=0 | numeric(p,s) |
| NUMBER(p) | PG_INTEGER_TYPE=1 | smallint、integer、bigint |
| - | PG_INTEGER_TYPE=0 | numeric(p) |
| NUMBER | PG_INTEGER_TYPE=1 | bigint(integer、float) |
| - | PG_INTEGER_TYPE=0 | numeric |
| FLOAT | - | double precision |
| DOUBLE PRECISION | - | double precision |
| INT | - | integer |
| INTEGER | - | integer |
| REAL | - | real |
| SMALLINT | - | smallint |
| BINARY_FLOAT | - | double precision |
| BINARY_DOUBLE | - | double precision |
| BINARY_INTEGER | - | integer |
| PLS_INTEGER | - | integer |
字符類型
| 數(shù)據(jù)類型 | 轉(zhuǎn)換后的類型 |
|---|---|
| CHAR | char |
| NCHAR | char |
| VARCHAR2 | varchar |
| NVARCHAR2 | varchar |
時(shí)間類型
| 數(shù)據(jù)類型 | 轉(zhuǎn)換后的類型 |
|---|---|
| DATE | timestamp |
| TIMESTAMP | timestamp |
| TIMESTAMP WITH TIME ZONE | timestamp with time zone |
| TIMESTAMP WITH LOCAL TIME ZONE | timestamp with time zone |
其他類型
| 數(shù)據(jù)類型 | 轉(zhuǎn)換后的類型 |
|---|---|
| LONG | text |
| LONG RAW | bytea |
| CLOB | text |
| NCLOB | text |
| BLOB | bytea |
| BFILE | bytea |
| RAW | bytea |
| RAW(16) | uuid |
| RAW(32) | uuid |
| UROWID | oid |
| ROWID | oid |
| DEC | decimal |
| DECIMAL | decimal |
| XMLTYPE | xml |
恩墨的 MTK 是怎么處理 Oracle 到 PostgreSQL 的數(shù)據(jù)類型轉(zhuǎn)換
- 在官方文檔中只找到一個(gè) Oracle 到 openGauss/MogDB 的數(shù)據(jù)類型的轉(zhuǎn)換對(duì)應(yīng)表,但是和 PostgreSQL 差距應(yīng)該不會(huì)很大
| Oracle | openGauss |
|---|---|
| SMALLINT | numeric |
| INTEGER | numeric |
| DECIMAL(8,5) | numeric(8,5) |
| NUMERIC(8,5) | numeric(8,5) |
| REAL | numeric |
| FLOAT(20) | numeric |
| NUMBER(8,5) | numeric(8,5) |
| BINARY_FLOAT | numeric |
| BINARY_DOUBLE | numeric |
| CHAR(8) | character(8) |
| NCHAR(8) | character(8) |
| VARCHAR(8) | character varying(8) |
| VARCHAR2(8) | character varying(8) |
| NVARCHAR2(8) | character varying(8) |
| DATE | timestamp without time zone |
| TIMESTAMP | timestamp without time zone |
| INTERVAL YEAR TO MONTH | interval |
| IDTS INTERVAL DAY TO SECOND | interval |
| LONG | text |
| RAW(111) | bytea |
| LONG RAW | bytea |
| CLOB | text/CLOB |
| BLOB | bytea/BLOB |
| NCLOB | text/NCLOB |
| BFILE | Not Support |
| User-Defined Types | Not Support |
| Any Types | Not Support |
| URI Data Types | Not Support |
| URIFactory Package | Not Support |
| SDO_GEOMETRY | Partially Supported |
| SDO_TOPO_GEOMETRY | Not Support |
| SDO_GEORASTER | Not Support |
Debezium 對(duì)常用數(shù)據(jù)類型的同步測試
CHAR and NCHAR and VARCHAR2 and NVARCHAR2
- PostgreSQL 數(shù)據(jù)庫中的字符類型
https://www.postgresql.org/docs/14/datatype-character.html
| Name | Description | 備注 |
|---|---|---|
| character varying(n), varchar(n) | variable-length with limit | n 是字符長度,不是字節(jié)長度 |
| character(n), char(n) | fixed-length, blank padded | n 是字符長度,不是字節(jié)長度 |
| text | variable unlimited length |
CHAR and NCHAR
- 根據(jù)上文兩個(gè)遷移工具對(duì) Oracle CHAR and NCHAR 類型的轉(zhuǎn)換形式,這里選擇 PostgreSQL 的 character 反向同步到 Oracle 的 CHAR and NCHAR 中。
--源端 PostgreSQL
test_dml=# create schema test;
drop table IF EXISTS test.to_char1;
create table test.to_char1 (id int primary key, col1 character(10), col2 character(10));
insert into test.to_char1 values (1, 'aaaaaaa', 'aaaaaaa');
insert into test.to_char1 values (2, '數(shù)據(jù)驅(qū)動(dòng),成就未來', '數(shù)據(jù)驅(qū)動(dòng),成就未來');
test_dml=# select * from test.to_char1;
id | col1 | col2
----+---------------------+---------------------
1 | aaaaaaa | aaaaaaa
2 | 數(shù)據(jù)驅(qū)動(dòng),成就未來 | 數(shù)據(jù)驅(qū)動(dòng),成就未來
(2 rows)
-- 目標(biāo)端 Oracle 19C PDB
create table test.to_char1 (id int primary key, col1 char(10), col2 nchar(10));
-- 啟動(dòng)同步預(yù)期的報(bào)出以下錯(cuò)誤,字符長度不夠。
-- 所以同樣是長度 10,PostgreSQL 是字符的長度,而 Oracle 是字節(jié)的長度。
-- 在 ZHS16GBK 字符集的數(shù)據(jù)庫里每個(gè)中文是2個(gè)字節(jié),"數(shù)據(jù)驅(qū)動(dòng),成就未來",加上中文的逗號(hào)和一個(gè)空格一共是19個(gè)字節(jié),CHAR 類型會(huì)同步空格。
ORA-12899: value too large for column "TEST"."TO_CHAR1"."COL1" (actual: 19, maximum: 10)
-- 目標(biāo)端增加長度
drop table test.to_char1 purge;
create table test.to_char1 (id int primary key, col1 char(20), col2 nchar(20));
- 同步到目標(biāo)端的數(shù)據(jù)

VARCHAR2 and NVARCHAR2
- 根據(jù)上文兩個(gè)遷移工具對(duì) Oracle VARCHAR2 and NVARCHAR2 類型的轉(zhuǎn)換形式,這里選擇 PostgreSQL 的 character varying 和 text 反向同步到 Oracle 的 VARCHAR2 and NVARCHAR2 中。
--源端 PostgreSQL
drop table IF EXISTS test.to_varchar2;
create table test.to_varchar2 (id int primary key, col1 character varying(10), col2 text, col3 character varying(10), col4 text);
insert into test.to_varchar2 values (1, 'aaaaaaa', 'aaaaaaa', 'aaaaaaa', 'aaaaaaa');
insert into test.to_varchar2 values (2, '數(shù)據(jù)驅(qū)動(dòng),成就未來', '數(shù)據(jù)驅(qū)動(dòng),成就未來', '數(shù)據(jù)驅(qū)動(dòng),成就未來', '數(shù)據(jù)驅(qū)動(dòng),成就未來');
test_dml=# select * from test.to_varchar2;
id | col1 | col2 | col3 | col4
----+--------------------+--------------------+--------------------+--------------------
1 | aaaaaaa | aaaaaaa | aaaaaaa | aaaaaaa
2 | 數(shù)據(jù)驅(qū)動(dòng),成就未來 | 數(shù)據(jù)驅(qū)動(dòng),成就未來 | 數(shù)據(jù)驅(qū)動(dòng),成就未來 | 數(shù)據(jù)驅(qū)動(dòng),成就未來
(2 rows)
-- 目標(biāo)端 Oracle 19C PDB
create table test.to_varchar2 (id int primary key, col1 varchar2(10), col2 varchar2(10), col3 nvarchar2(10), col4 nvarchar2(10));
-- 啟動(dòng)同步預(yù)期的報(bào)出以下錯(cuò)誤,字符長度不夠。
-- 所以同樣是長度 10,PostgreSQL 是字符的長度,而 Oracle 是字節(jié)的長度。
-- 在 ZHS16GBK 字符集的數(shù)據(jù)庫里每個(gè)中文是2個(gè)字節(jié),"數(shù)據(jù)驅(qū)動(dòng),成就未來",加上中文的逗號(hào)一共是18個(gè)字節(jié)。
ORA-12899: value too large for column "TEST"."TO_VARCHAR2"."COL1" (actual: 18, maximum: 10)
-- 目標(biāo)端增加長度
drop table test.to_varchar2 purge;
create table test.to_varchar2 (id int primary key, col1 varchar2(20), col2 varchar2(20), col3 nvarchar2(20), col4 nvarchar2(20));
- 同步到目標(biāo)端的數(shù)據(jù)

NUMBER and NUMBER(p)and NUMBER(p,s)
- PostgreSQL 數(shù)據(jù)庫中的數(shù)值類型
https://www.postgresql.org/docs/14/datatype-numeric.html
| Name | Storage Size | Description | Range |
|---|---|---|---|
| smallint | 2 bytes | small-range integer | -32768 to +32767 |
| integer | 4 bytes | typical choice for integer | 2147483648 to +2147483647 |
| bigint | 8 bytes | large-range integer | -9223372036854775808 to +9223372036854775807 |
| decimal | variable | user-specified precision, exact | up to 131072 digits before the decimal point; up to 16383 digits after the decimal point |
| numeric | variable | user-specified precision, exact | up to 131072 digits before the decimal point; up to 16383 digits after the decimal point |
| real | 4 bytes | variable-precision, inexact | 6 decimal digits precision |
| double precision | 8 bytes | variable-precision, inexact | 15 decimal digits precision |
| smallserial | 2 bytes | small autoincrementing integer | 1 to 32767 |
| serial | 4 bytes | autoincrementing integer | 1 to 2147483647 |
| bigserial | 8 bytes | large autoincrementing integer | 1 to 9223372036854775807 |
- smallint、integer 和 bigint 是整數(shù)類型,不存儲(chǔ)小數(shù)部分。
- integer 是最常用的類型,因?yàn)樗跀?shù)值范圍、存儲(chǔ)大小和性能之間提供了最佳平衡。
- numeric 推薦用于存儲(chǔ)貨幣數(shù)值和其他需要精確性的數(shù)值,但是 numeric 的計(jì)算性能非常慢。
- real 和 double precision 是不精確的浮點(diǎn)類型。
NUMBER
- 根據(jù)上文兩個(gè)遷移工具對(duì) Oracle NUMBER 類型的轉(zhuǎn)換形式,這里選擇 PostgreSQL 的 bigint、integer、float 和 numeric 反向同步到 Oracle 的 NUMBER 中。
drop table IF EXISTS test.to_number1;
create table test.to_number1 (id int primary key, col1 integer, col2 bigint, col3 float, col4 numeric);
insert into test.to_number1 values (1, 123, 123, 123.123, 123.123);
select * from test.to_number1;
id | col1 | col2 | col3 | col4
----+------+------+---------+---------
1 | 123 | 123 | 123.123 | 123.123
(1 row)
create table test.to_number1 (id int primary key, col1 number, col2 number, col3 number, col4 number);
- 問題: Numeric 類型的數(shù)據(jù)不能從 Kafka 同步到目標(biāo)端 Oracle。
tutorial-connect-1 | org.apache.kafka.connect.errors.ConnectException: Unsupported source data type: STRUCT

- 源端連接器配置 “decimal.handling.mode”: “double”,重新同步數(shù)據(jù)

- 同步到目標(biāo)端的數(shù)據(jù)
SQL> select * from test.to_number1;
ID COL1 COL2 COL3 COL4
---------- ---------- ---------- ---------- ----------
1 123 123 123.123 123.123
NUMBER(p)
- 根據(jù)上文兩個(gè)遷移工具對(duì) Oracle NUMBER(p) 類型的轉(zhuǎn)換形式,這里選擇 PostgreSQL 的 smallint、integer、bigint 和 numeric(p) 反向同步到 Oracle 的 NUMBER(p) 中。
drop table IF EXISTS test.to_number2;
create table test.to_number2 (id int primary key, col1 smallint, col2 integer, col3 bigint, col4 numeric(10));
insert into test.to_number2 values (1, 1234, 12345, 123456, 1234567);
select * from test.to_number2;
id | col1 | col2 | col3 | col4
----+------+-------+--------+---------
1 | 1234 | 12345 | 123456 | 1234567
(1 row)
create table test.to_number2 (id int primary key, col1 number(4), col2 number(8), col3 number(10), col4 number(10));
- 同步到目標(biāo)端的數(shù)據(jù)
SQL> select * from test.to_number2;
ID COL1 COL2 COL3 COL4
---------- ---------- ---------- ---------- ----------
1 1234 12345 123456 1234567
NUMBER(p,s)
- 根據(jù)上文兩個(gè)遷移工具對(duì) Oracle NUMBER(p,s) 類型的轉(zhuǎn)換形式,這里選擇 PostgreSQL 的 real、double precision 和 numeric(p,s) 反向同步到 Oracle 的 NUMBER(p,s) 中。
drop table IF EXISTS test.to_number3;
create table test.to_number3 (id int primary key, col1 real, col2 double precision, col3 numeric(10,5));
insert into test.to_number3 values (1, 12.34, 12.345, 12.3456);
select * from test.to_number3;
id | col1 | col2 | col3
----+-------+--------+----------
1 | 12.34 | 12.345 | 12.34560
(1 row)
create table test.to_number3 (id int primary key, col1 number(10,5), col2 number(10,5), col3 number(10,5));
- 同步到目標(biāo)端的數(shù)據(jù)
SQL> select * from test.to_number3;
ID COL1 COL2 COL3
---------- ---------- ---------- ----------
1 12.34 12.345 12.3456
DATE and TIMESTAMP and TIMESTAMP(6)
https://www.postgresql.org/docs/14/datatype-datetime.html
| Name | Storage Size | Description | Low Value | High Value | Resolution |
|---|---|---|---|---|---|
| timestamp [(p)] [ without time zone ] | 8 bytes | both date and time (no time zone) | 4713 BC | 294276 AD | 1 microsecond |
| timestamp [(p)] with time zone | 8 bytes | both date and time, with time zone | 4713 BC | 294276 AD | 1 microsecond |
| date | 4 bytes | date (no time of day) | 4713 BC | 5874897 AD | 1 day |
| time [(p)] [ without time zone ] | 8 bytes | time of day (no date) | 00:00:00 | 24:00:00 | 1 microsecond |
| time [(p)] with time zone | 12 bytes | time of day (no date), with time zone | 00:00:00+1559 | 24:00:00-1559 | 1 microsecond |
| interval [ fields ] [(p)] | 16 bytes | time interval | -178000000 years | 178000000 years | 1 microsecond |
- 根據(jù)上文兩個(gè)遷移工具對(duì) Oracle DATE and TIMESTAMP 類型的轉(zhuǎn)換形式,這里選擇 PostgreSQL 的 timestamp without time zone 反向同步到 Oracle 的 DATE and TIMESTAMP 中。
drop table IF EXISTS test.to_date1;
create table test.to_date1 (id int primary key, col1 timestamp without time zone, col2 timestamp without time zone, col3 timestamp without time zone);
insert into test.to_date1 values (1, now(), now(), now());
select * from test.to_date1;
id | col1 | col2 | col3
----+----------------------------+----------------------------+----------------------------
1 | 2022-04-29 13:07:36.678886 | 2022-04-29 13:07:36.678886 | 2022-04-29 13:07:36.678886
(1 row)
create table test.to_date1 (id int primary key, col1 date, col2 timestamp, col3 timestamp(6));
- 問題:timestamp without time zone 類型同步到 Kafka 變成了數(shù)值,不能寫入到目標(biāo)端 Oracle 數(shù)據(jù)庫里
tutorial-connect-1 | java.sql.BatchUpdateException: ORA-00932: inconsistent datatypes: expected DATE got NUMBER


- 源端連接器添加 “time.precision.mode”: “connect”


- 同步到目標(biāo)端的數(shù)據(jù)
SQL> alter session set NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS';
SQL> select * from test.to_date1;
ID COL1 COL2 COL3
---------- ------------------- ------------------------------ ------------------------------
1 2022-04-29 13:07:36 29-APR-22 01.07.36.678000 PM 29-APR-22 01.07.36.678000 PM
- 問題:當(dāng)前 docker 容器的時(shí)區(qū)不是東八區(qū),修改一下
# 修改 docker 容器的時(shí)區(qū)
[root@docker tutorial]# docker exec -it tutorial-postgres-1 bash
root@79ba8e3c5a7e:/# date -R
Fri, 29 Apr 2022 14:56:25 +0000
root@79ba8e3c5a7e:/# cd /etc/
root@79ba8e3c5a7e:/etc# mv localtime localtime.bak
root@79ba8e3c5a7e:/etc# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
root@79ba8e3c5a7e:/etc# exit
[root@docker tutorial]# docker restart tutorial-postgres-1
tutorial-postgres-1
[root@docker tutorial]# docker exec -it tutorial-postgres-1 bash
root@79ba8e3c5a7e:/# date
Fri 29 Apr 2022 10:58:55 PM CST
root@79ba8e3c5a7e:/# date -R
Fri, 29 Apr 2022 22:59:14 +0800
# 重啟 postgres 容器后,源端連接器任務(wù)會(huì)停止運(yùn)行,重新啟動(dòng)源端連接器任務(wù)
[root@docker tutorial]# curl -s -X GET localhost:8083/connectors/inventory-connector-datatype/status | jq
{
"name": "inventory-connector-datatype",
"connector": {
"state": "RUNNING",
"worker_id": "192.168.48.2:8083"
},
"tasks": [
{
"id": 0,
"state": "FAILED",
"worker_id": "192.168.48.2:8083",
"trace": "org.apache.kafka.connect.errors.ConnectException: An exception occurred in the change event producer. ... ...
}
],
"type": "source"
}
[root@docker tutorial]# curl -s -X POST localhost:8083/connectors/inventory-connector-datatype/tasks/0/restart
[root@docker tutorial]# curl -s -X GET localhost:8083/connectors/inventory-connector-datatype/status | jq
{
"name": "inventory-connector-datatype",
"connector": {
"state": "RUNNING",
"worker_id": "192.168.48.2:8083"
},
"tasks": [
{
"id": 0,
"state": "RUNNING",
"worker_id": "192.168.48.2:8083"
}
],
"type": "source"
}
- 時(shí)區(qū)正確后,同步一下數(shù)據(jù)看看
-- 源端插入數(shù)據(jù),時(shí)間正確
test_dml=# insert into test.to_date1 values (5, now(), now());
test_dml=# select * from test.to_date1;
id | col1 | col2 | col3
----+----------------------------+----------------------------+----------------------------
1 | 2022-04-29 13:07:36.678886 | 2022-04-29 13:07:36.678886 | 2022-04-29 13:07:36.678886
2 | 2022-04-29 14:52:55.596212 | 2022-04-29 14:52:55.596212 | 2022-04-29 14:52:55.596212
3 | 2022-04-29 14:59:57.756303 | 2022-04-29 14:59:57.756303 | 2022-04-29 14:59:57.756303
4 | 2022-04-29 23:00:36.561669 | 2022-04-29 23:00:36.561669 | 2022-04-29 23:00:36.561669
5 | 2022-04-29 23:06:25.568611 | 2022-04-29 23:06:25.568611 | 2022-04-29 23:06:25.568611
(5 rows)
-- 目標(biāo)端同步的數(shù)據(jù),時(shí)間正確
SQL> select * from test.to_date1;
ID COL1 COL2 COL3
---------- ------------------- ------------------------------ ------------------------------
1 2022-04-29 13:07:36 29-APR-22 01.07.36.678000 PM 29-APR-22 01.07.36.678000 PM
2 2022-04-29 14:52:55 29-APR-22 02.52.55.596000 PM 29-APR-22 02.52.55.596000 PM
3 2022-04-29 14:59:57 29-APR-22 02.59.57.756000 PM 29-APR-22 02.59.57.756000 PM
4 2022-04-29 23:00:36 29-APR-22 11.00.36.561000 PM 29-APR-22 11.00.36.561000 PM
5 2022-04-29 23:06:25 29-APR-22 11.06.25.568000 PM 29-APR-22 11.06.25.568000 PM
CLOB and LONG
- 根據(jù)上文兩個(gè)遷移工具對(duì) Oracle CLOB and LONG 類型的轉(zhuǎn)換形式,這里選擇 PostgreSQL 的 text 反向同步到 Oracle 的 CLOB and LONG 中。
drop table IF EXISTS test.to_clob1;
create table test.to_clob1 (id int primary key, col1 text, col2 text);
insert into test.to_clob1 values (1, '數(shù)據(jù)驅(qū)動(dòng),成就未來', '數(shù)據(jù)驅(qū)動(dòng),成就未來');
select * from test.to_clob1;
id | col1 | col2
----+--------------------+--------------------
1 | 數(shù)據(jù)驅(qū)動(dòng),成就未來 | 數(shù)據(jù)驅(qū)動(dòng),成就未來
(1 row)
create table test.to_clob1 (id int primary key, col1 CLOB, col2 LONG);
- 同步到目標(biāo)端的數(shù)據(jù)


BLOB
https://www.postgresql.org/docs/14/datatype-binary.html
| Name | Storage Size | Description |
|---|---|---|
| bytea | 1 or 4 bytes plus the actual binary string | variable-length binary string |
- 根據(jù)上文兩個(gè)遷移工具對(duì) Oracle BLOB 類型的轉(zhuǎn)換形式,這里選擇 PostgreSQL 的 bytea 反向同步到 Oracle 的 BLOB 中。
drop table IF EXISTS test.to_blob1;
create table test.to_blob1 (id int primary key, col1 bytea);
insert into test.to_blob1 values (1, '數(shù)據(jù)驅(qū)動(dòng),成就未來');
select * from test.to_blob1;
id | col1
----+----------------------------------------------------------
1 | \xe695b0e68daee9a9b1e58aa8efbc8ce68890e5b0b1e69caae69da5
(1 row)
create table test.to_blob1 (id int primary key, col1 BLOB);
- 同步到目標(biāo)端的數(shù)據(jù)
SQL> select * from test.to_blob1;
ID COL1
---------- -------------------------------------------------------
1 E695B0E68DAEE9A9B1E58AA8EFBC8CE68890E5B0B1E69CAAE69DA5

- BLOB 把中文轉(zhuǎn)成亂碼了,同步一張圖片看看效果


- 目標(biāo)端Oracle 成功打開圖片

自動(dòng)創(chuàng)建表的數(shù)據(jù)類型
- 如果同步的記錄到目標(biāo)端,發(fā)現(xiàn)目標(biāo)端沒有表或字段,當(dāng)配置了 auto.create 和 auto.evolve 會(huì)自動(dòng)在目標(biāo)端創(chuàng)建表或者列,此時(shí)列的字段類型就會(huì)由連接器來指定。

最后修改時(shí)間:2022-05-03 08:34:05
「喜歡這篇文章,您的關(guān)注和贊賞是給作者最好的鼓勵(lì)」
關(guān)注作者
【版權(quán)聲明】本文為墨天輪用戶原創(chuàng)內(nèi)容,轉(zhuǎn)載時(shí)必須標(biāo)注文章的來源(墨天輪),文章鏈接,文章作者等基本信息,否則作者和墨天輪有權(quán)追究責(zé)任。如果您發(fā)現(xiàn)墨天輪中有涉嫌抄襲或者侵權(quán)的內(nèi)容,歡迎發(fā)送郵件至:contact@modb.pro進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),墨天輪將立刻刪除相關(guān)內(nèi)容。




