简体   繁体   English

如何只从Oracle NCLOB复制前4000个字符到NVARCHAR2(4000)值?

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

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. 我是一名程序员,我正在编写一些SQL代码来从远程Oracle数据库中提取数据并将其插入到我们本地MS SQL Server上的某些表中。

I need to bring an Oracle NCLOB column to an NVARCHAR column in our MS SQL Server database. 我需要将Oracle NCLOB列引入MS SQL Server数据库中的NVARCHAR列。

We have no DBA staff to do this for me. 我们没有DBA工作人员为我这样做。

For my purposes, it is not critical to have the entire NCLOB value, so 4000 chars is simply an arbitrarily large number I chose. 就我的目的而言,拥有整个NCLOB值并不重要,因此4000个字符只是我选择的任意大数字。

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. 我的目标是尽可能地在Oracle端的NVARCHAR2字段中获取尽可能多的数据,并且仍然保持实际,以便在每日数据刷新中引入网络。

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. 我已经看到很多参考解决方案来获取所有数据,并获得超过4000个字符的数据等。但是,我正在寻找一个简单的版本,我可以轻松地进行和维护,而无需繁重的DBA级工作。

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

You will want to use dbms_lob.substr 您将需要使用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. 将获得clob的前4000个字符。 Note that when using SQL as I did, the max length is 4000. You can get 32k using plsql: 请注意,当我使用SQL时,最大长度为4000.您可以使用plsql获得32k:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM