How to Copy Only First 4000 Characters from Oracle NCLOB to NVARCHAR2(4000) Value?

房东的猫 提交于 2019-12-11 18:55:09

问题


I am a programmer, and I am writing some SQL code to pull data from a remote Oracle database and insert it into some tables on our local MS SQL Server.

I need to bring an Oracle NCLOB column to an NVARCHAR column in our MS SQL Server database.

We have no DBA staff to do this for me.

For my purposes, it is not critical to have the entire NCLOB value, so 4000 chars is simply an arbitrarily large number I chose.

My goal is to have as much of the data in my NVARCHAR2 field on the Oracle side as I can and still keep it practical to bring across the network in a daily data refresh.

I have seen many many references to solutions to get all the data, and to get data more than 4000 characters, etc. However, I am seeking a simple version that I can easily put in and maintain without heavy-duty DBA-level work.


回答1:


Check out http://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11_QUESTION_ID:367980988799.

You will want to use dbms_lob.substr

Per the post referenced above:

dbms_lob.substr( clob_column, for_how_many_bytes, from_which_byte );

for example:

select dbms_lob.substr( x, 4000, 1 ) from T;

will get me the first 4000 characters of the clob. Note that when using SQL as I did, the max length is 4000. You can get 32k using plsql:

declare my_var long; begin for x in ( select X from t )
loop my_var := dbms_lob.substr( x.X, 32000, 1 ); ....



来源:https://stackoverflow.com/questions/21739294/how-to-copy-only-first-4000-characters-from-oracle-nclob-to-nvarchar24000-valu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!