如何在 Oracle 中将 CLOB 转换为 CHAR 数据类型?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41533486/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:22:08  来源:igfitidea点击:

How to convert CLOB to CHAR datatype in Oracle?

sqloracle

提问by Vignesh Kiswanth

For ETL Purpose, I need to convert DB records into flat-files. For that, I have to convert all the records as CHAR. In that table, it's having few columns with CLOB datatype. So, I tried the following functions:

出于 ETL 目的,我需要将数据库记录转换为平面文件。为此,我必须将所有记录转换为 CHAR。在那个表中,它有几个 CLOB 数据类型的列。所以,我尝试了以下功能:

DBMS.LOBS_SUBSTR(column_name, Length(column_name))

Error: ORA-06502 Pl/sql: numeric value error: character string buffer too small ORA-06512: at line 1 06502. 00000 - "PL/SQL: numeric or value error ℅s"

错误:ORA-06502 Pl/sql:数值错误:字符串缓冲区太小 ORA-06512:在第 1 行 06502. 00000 -“PL/SQL:数值或值错误 ℅s”

回答by Gurwinder Singh

You can use DBMS_LOB.substr()

您可以使用 DBMS_LOB.substr()

select DBMS_LOB.substr(col, 4000) from table;

Also, from the docs, restrictions are as:

此外,从docs,限制如下:

For fixed-width n-byte CLOBs, if the input amount for SUBSTR is greater than (32767/n), then SUBSTR returns a character buffer of length (32767/n), or the length of the CLOB, whichever is lesser. For CLOBs in a varying-width character set, n is the maximum byte-width used for characters in the CLOB

对于固定宽度的 n 字节 CLOB,如果 SUBSTR 的输入量大于 (32767/n),则 SUBSTR 返回长度为 (32767/n) 的字符缓冲区,或 CLOB 的长度,以较小者为准。对于可变宽度字符集中的 CLOB,n 是用于 CLOB 中字符的最大字节宽度