Oracle与PostgreSQL数据写入的方法是什么

40次阅读
没有评论

共计 2680 个字符,预计需要花费 7 分钟才能阅读完成。

这篇文章主要介绍“Oracle 与 PostgreSQL 数据写入的方法是什么”,在日常操作中,相信很多人在 Oracle 与 PostgreSQL 数据写入的方法是什么问题上存在疑惑,丸趣 TV 小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Oracle 与 PostgreSQL 数据写入的方法是什么”的疑惑有所帮助!接下来,请跟着丸趣 TV 小编一起来学习吧!

在特殊字符(不可见字符,如 ASCII 0、控制字符、非法字符等)上,Oracle 非常宽松,基本上可以写入任何数据,包括不符合编码规则的数据。而 PostgreSQL 则不然,必须符合该字符集的编码,比如在 UTF8 字符集下,输入的字符编码比如符合 UTF8 编码。

Oracle
字符集为 GBK,创建数据表,插入特殊字符(0x00),没有问题

TEST-orcl@DESKTOP-V430TU3 drop table t_0x00 purge;
Table dropped.
TEST-orcl@DESKTOP-V430TU3 create table t_0x00(id int,c1 varchar2(200),c2 blob);
Table created.
TEST-orcl@DESKTOP-V430TU3 insert into t_0x00 values(1,chr(0),null);
1 row created.
TEST-orcl@DESKTOP-V430TU3 insert into t_0x00 values(2, c1 ||chr(0),null);
1 row created.
TEST-orcl@DESKTOP-V430TU3 insert into t_0x00 values(3,chr(0)|| c1 ,null);
1 row created.
TEST-orcl@DESKTOP-V430TU3 insert into t_0x00 values(4, c1 ||chr(0)|| c1 ,null);
1 row created.
TEST-orcl@DESKTOP-V430TU3 insert into t_0x00 values(5, c1 ||chr(0)|| c1 ,to_blob(HEXTORAW( 550055)));
1 row created.
TEST-orcl@DESKTOP-V430TU3 
TEST-orcl@DESKTOP-V430TU3 select * from t_0x00 where c1 like  % ||chr(0)|| % 
 ID C1 C2
---------- -------------------- --------------------
 1
 2 c1
 3 c1
 4 c1 c1
 5 c1 c1 550055
TEST-orcl@DESKTOP-V430TU3

PostgreSQL
字符集为 UTF8,创建数据表,插入特殊字符(0x00),无法插入

[local:/data/run/pg12]:5120 pg12@testdb=# \encoding
[local:/data/run/pg12]:5120 pg12@testdb=# drop table t_0x00;
insert into t_0x00 values(4, c1 ||E \x00 || c1 ,null);
insert into t_0x00 values(5, c1 ||E \x00 || c1 , \x550055 ::bytea);DROP TABLE
[local:/data/run/pg12]:5120 pg12@testdb=# create table t_0x00(id int,c1 varchar(200),c2 bytea);
CREATE TABLE
[local:/data/run/pg12]:5120 pg12@testdb=# 
[local:/data/run/pg12]:5120 pg12@testdb=# insert into t_0x00 values(1,E \x00 ,null);
ERROR: invalid byte sequence for encoding  UTF8 : 0x00
[local:/data/run/pg12]:5120 pg12@testdb=# insert into t_0x00 values(1,chr(0),null);
ERROR: null character not permitted
[local:/data/run/pg12]:5120 pg12@testdb=# insert into t_0x00 values(2,null,bytea  \x00 
INSERT 0 1
[local:/data/run/pg12]:5120 pg12@testdb=# insert into t_0x00 values(3,E \x00 || c1 ,null);
ERROR: invalid byte sequence for encoding  UTF8 : 0x00
[local:/data/run/pg12]:5120 pg12@testdb=# insert into t_0x00 values(4, c1 ||E \x00 || c1 ,null);
ERROR: invalid byte sequence for encoding  UTF8 : 0x00
[local:/data/run/pg12]:5120 pg12@testdb=# insert into t_0x00 values(5, c1 ||E \x00 || c1 , \x550055 ::bytea);
ERROR: invalid byte sequence for encoding  UTF8 : 0x00
[local:/data/run/pg12]:5120 pg12@testdb=# select * from t_0x00 where c1 like  % ||chr(0)|| % 
ERROR: null character not permitted
[local:/data/run/pg12]:5120 pg12@testdb=#

在 Oracle – PG 的迁移过程中,这些特殊字符是需要考虑的。

到此,关于“Oracle 与 PostgreSQL 数据写入的方法是什么”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注丸趣 TV 网站,丸趣 TV 小编会继续努力为大家带来更多实用的文章!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-26发表,共计2680字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)