2014-05-23 154 views
0

我有列名message和一個表,該表類型NCLOB的ID這是VARCHAR2類型與超過4000個字符中的Oracle SQL中的XML更新NCLOB列

我想更新particlular的消息ID。我使用下面的查詢

update table_name set message='<<long XML Message>>' where ID=value 

我收到以下錯誤:

Error at Command Line:6 Column:38 
Error report: 
SQL Error: ORA-01704: string literal too long 
01704. 00000 - "string literal too long" 
*Cause: The string literal is longer than 4000 characters. 
*Action: Use a string literal of at most 4000 characters. 
     Longer values may only be entered using bind variables. 

我試圖存儲XML到一個變量和更新列這個變量,但沒有用的

+0

字符串多長於4000個字符?如果它總是小於32k,那麼你可以將它分配給PL/SQL中的CLOB變量,然後將其用於插入。否則,你將不得不將CLOB建立到高達32k的縫隙,這是一點點工作。你用變量嘗試了什麼,爲什麼它不起作用? –

回答

1

Oracle對文字字符串的長度有限制,您正在達到該限制。你可以將它分成4000個字符的塊。這可能會爲你做。我目前無法測試它。

update table_name set message= '<4K>' || '<4K>' || '<4K>' where ID=value 

它看起來像上面不會工作。

所以,讓我們試試這個,有1K塊:

update table_name set message= '<1st 1K>' where ID=value; 
update table_name set message= message || '<2nd 1K>' where ID=value; 
update table_name set message= message || '<3rd 1K>' where ID=value; 
update table_name set message= message || '<4th 1K>' where ID=value; 

我能夠添加的80K消息長度。 我剛纔停止了,沒有錯誤。

+0

不是。在嘗試將最終值分配給列之前,它會嘗試將多個4k字符串組合成一個,因此它仍然會出錯。有了不同的錯誤,但不幸的是,它仍然無法正常工作。 –

+0

你是對的,第一種方法不起作用,但我不放棄......看起來,如果你使用更新將更小的字符串添加到NCLOB,它的工作原理! – Bob

+0

有趣;我不認爲這也可以。 [但它確實](http://sqlfiddle.com/#!4/1aa14/3)。 –

相關問題