oracle NVARCHAR 到 VARCHAR 之间的转换
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14651426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Conversion between NVARCHAR to VARCHAR
提问by Wishper
I've got an Oracle DB with ALL the character columns defined as NVARCHAR or NCHAR or NCLOB, using charset UTF-16.
我有一个 Oracle 数据库,其中所有字符列都定义为 NVARCHAR 或 NCHAR 或 NCLOB,使用字符集 UTF-16。
Now I want to migrate to a new DB that has charset UTF-8. Since it can store unicode characters, I'm wandering if I will be able to import data converting column types.
现在我想迁移到具有字符集 UTF-8 的新数据库。由于它可以存储 unicode 字符,我在犹豫是否能够导入数据转换列类型。
The reason I'm doubtful is I know that I cannot convert a NVARCHAR2 column in a VARCHAR2 if not empty.
我怀疑的原因是我知道如果不是空的,我不能在 VARCHAR2 中转换 NVARCHAR2 列。
What is the best option to perform the import. Will datapump complain if I import the schema, modify the column types and after that I'll import the data?
执行导入的最佳选择是什么。如果我导入架构,修改列类型,然后我将导入数据,datapump 会抱怨吗?
Thank
谢谢
回答by Andrew Brennan
Yes datapump would be unimpressed with your proposed solution. You need to use to_char() or cast( MYNVARCHAR2 as VARCHAR2 ) to convert the datatypes after the import or before the export. As far as I know, any characters which can't be converted will be turned into '?'s so you have to be careful not to convert any data that contains non-english-alphabet characters.
是的,datapump 不会对您提出的解决方案留下深刻印象。您需要使用 to_char() 或 cast( MYNVARCHAR2 as VARCHAR2 ) 在导入之后或导出之前转换数据类型。据我所知,任何无法转换的字符都会被转换成 '?',所以你必须小心不要转换任何包含非英文字母字符的数据。
It will probably be easiest to just import the data as is into a different schema, then convert the data while copying it to the correct, modified schema. i.e.
将数据按原样导入不同的模式可能是最简单的,然后在将数据复制到正确的、修改过的模式的同时转换数据。IE
impdp remap_schema=myschema:tempschema
insert into myschema.mytable (select myprimarykey, to_char(mynvarchar2) from tempschema.mytable);
impdp remap_schema=myschema:tempschema
插入到 myschema.mytable(从 tempschema.mytable 中选择 myprimarykey, to_char(mynvarchar2));
But this will obviously use up twice the space in your database.
但这显然会占用数据库中两倍的空间。