PL/SQL中long變數只允許儲存32768位元組

來源:互聯網
上載者:User

編程中發現預存程序、函數返回的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對象。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.