2017-01-08 57 views
-1

對於ETL目的,我需要將DB記錄轉換爲平面文件。爲此,我必須將所有記錄轉換爲CHAR。在那張表中,它有幾列CLOB數據類型。所以,我嘗試了以下功能:如何在Oracle中將CLOB轉換爲CHAR數據類型?

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"

+0

請澄清你的問題。首先,你確定要轉換爲CHAR而不是VARCHAR2嗎?你所有的價值都是一樣的嗎?然後,你的意思是「它不應該受限於字符長度......」 - 沒有長度限制的唯一數據類型是CLOB,這是它首先被引入的唯一原因。 – mathguy

+0

我將編輯我的答案。感謝您的建議 –

+0

另外:如果你已經嘗試了DBMS.LOBS_SUBSTR,那應該會給你一個不同的錯誤(比如沒有這樣的函數)。如果您難以複製GurV寫的內容,請使用「複製」和「粘貼」編輯。如果實際上你使用了正確的函數DBMS_LOB.SUBSTR,並且你得到了一個錯誤,那麼肯定不是**,因爲列中存在'null';那些會很好地工作。 – mathguy

回答

0

您可以使用DBMS_LOB.substr()

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

此外,從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

+0

我編輯了我的描述。我已經使用了你在這裏提到的。該錯誤是由於空值.. –

+0

@VigneshKiswanth - 不,它不是。 – mathguy

+0

爲了供您參考,我已經編輯了描述,並附上了我得到的錯誤類型。 –

相關問題