編程中發現預存程序、函數返回的long類型過大時,報ORA-06502: PL/SQL: 數字或值錯誤 : 字串緩衝區太小
PL/SQL中long變數只允許儲存32768位元組(32K)
超過建議使用clob
Hi,
I've a procedure written in PL/SQL where in application numbers are getting concatenated to a variable in loop. And the length is exceeding 32767 ( Max for VARCHAR2) . Then I tried with LONG datatype for that variable but same happenes there. Then I made the variable as CLOB. IT works and even the functions like SUBSTR,LENGTH also works on variable of type CLOB. Surprised to see this
Can anybody explain me the reason :-
1 Why LONG doesn't accept value more than 32760 in Pl/SQL .?
2. Why substr and length functions worked with CLOB datatype when they were supposed to use DBMS_LOB package ?
3.Is there any performance impact of using variable as CLOB in Procedure for storing longer strings ?
Thanks
Sunil
Hi, the same kind of problem i am having....
i have seen that long pl/sql variable can have only 32760. but same time in Oracle database, long (as database column) can have upto 2gb of data. as if having 2gb of size, there should be some way to insert that much data. so i want to know what is the way to store more than 32k by a pl/sql variable?
for that i tried clob as pl/sql variable and it gets >32k and shows length 43K. and i inserted this into long column and i didn't say any error. i selected the long database column into clob pl/sql variable and it gives only 4000 bytes of data.
and everybody replies me to change the data type to clob in table.But I can't change it into clob datatype since i have to do some modifications in existing appl. and the table is referred by many procedures and functions.
Thanks,
Dhamayanthi K.
在oracle中,有4個大對象(lobs)類型可用,分別是blob,clob,bfile,nclob。
下面是對lob資料類型的簡單介紹。
blob:二進位lob,為位元據,最長可達4GB,存貯在資料庫中。
clob:字元lob,字元資料,最長可以達到4GB,存貯在資料庫中。
bfile:二進位檔案;存貯在資料庫之外的唯讀型位元據,最大長度由作業系統限制。
nclob:支援對位元組字元集合(nultibyte characterset)的一個clob列。
對於如何檢索和操作這些lob資料一直是oracle資料庫開發人員經常碰到的問題。下面我將在oracle對lob資料處理的一些方法和技巧,介紹給讀者,希望能夠對讀者以後的開發有所協助。
oracle中可以用多種方法來檢索或操作lob資料。通常的處理方法是通過dbms_lob包。
在oracle開發環境中我們可以用dbms_lob包來處理!dbms_lob包功能強大,簡單應用。既可以用來讀取內部的lob對象,也可以用來處理bfile對象。但處理兩者之間,還有一點差別。處理內部lob對象(blob,clob)時,可以進行讀和寫,但處理外部lob對象bfile時,只能進行讀操作,寫的操作可以用pl/sql處理。另外用sql也可以處理lob,但要注意sql僅可以處理整個lob,不能操作lob的資料片。
在dbms_lob包中內建了read(),append,write(),erase(),copy(),getlength(),substr()等函數,可以很方便地操作lob對象。