ORA-06512數(shù)字或值錯誤字符串緩沖區(qū)太小異常詳解
ORA-06512 網(wǎng)上最容易查到的解釋為
CauseThis error is caused by the stack being unwound by unhandled exceptions in your PLSQL code.
The options to resolve this Oracle error are:
- Fix the condition that is causing the unhandled error.
- Write an exception handler for this unhandled error.
- Contact your DBA for help.
The ORA-06512 error message indicates the line number of the unhandled error in the PLSQL code. This is quite useful when troubleshooting.
舉個栗子來了解此異常
創(chuàng)建存儲過程TestProc,參數(shù)v_number是一個長度為2的數(shù)字, 存儲過程中將100賦值給v_number,執(zhí)行存儲過程后提示異常,ORA-06502表示發(fā)生的錯誤;ORA-06512表示發(fā)生的行數(shù),本例中 因為100的是3位數(shù)字, v_number只能處理2位數(shù)字
SQL> CREATE OR REPLACE PROCEDURE TestProc AS 2 v_number number(2); 3 BEGIN 4 v_number := 100; 5 END; 6 / Procedure created SQL> execute TestProc(); begin TestProc(); end; ORA-06502: PL/SQL: 數(shù)字或值錯誤 : number precision too large ORA-06512: 在 "BOSS643.TESTPROC", line 4 ORA-06512: 在 line 2
針對上述問題,可以重新定義數(shù)值長度解決這個問題, v_number定義為3
SQL> CREATE OR REPLACE PROCEDURE TestProc AS 2 v_number number(3); 3 BEGIN 4 v_number := 100; 5 END; 6 / Procedure created SQL> execute TestProc(); PL/SQL procedure successfully completed SQL>
如果將數(shù)值型修改成其他類型后也是同樣的, 例如字符串,v_str設置為處理長度為10的字符串, 當給v_str賦值大于長度10的字符串后, 提示數(shù)字或者值錯誤,符串緩沖區(qū)太小
SQL> CREATE OR REPLACE PROCEDURE TestProc2 AS 2 v_str varchar2(10); 3 BEGIN 4 v_str := "This is a test string"; 5 END; 6 / Procedure created SQL> execute TestProc2(); begin TestProc2(); end; ORA-06502: PL/SQL: 數(shù)字或值錯誤 : character string buffer too small ORA-06512: 在 "BOSS643.TESTPROC2", line 4 ORA-06512: 在 line 2
重新定義varchar2長度
SQL> CREATE OR REPLACE PROCEDURE TestProc2 AS 2 v_str varchar2(512); 3 BEGIN 4 v_str := "This is a test string"; 5 END; 6 / Procedure created SQL> execute TestProc2(); PL/SQL procedure successfully completed SQL>
當然你也可以自定義異常來處理,例如當出現(xiàn)異常后提示“數(shù)值越界” ,此方法將異常捕獲提示更加明確,個人認為ORA-06502異常已經(jīng)十分清楚了, 具體還看存儲過程對應的需求是否有明確提示需求
SQL> CREATE OR REPLACE PROCEDURE TestProc AS 2 v_number number(2); 3 BEGIN 4 v_number := 100; 5 EXCEPTION 6 WHEN OTHERS THEN 7 RAISE_APPLICATION_ERROR(-20001, "數(shù)值v_number越界"); 8 END; 9 / Procedure created SQL> exec TestProc(); begin TestProc(); end; ORA-20001: 數(shù)值v_number越界 ORA-06512: 在 "BOSS643.TESTPROC", line 7 ORA-06512: 在 line 2
相關資源:
總結
到此這篇關于ORA-06512數(shù)字或值錯誤字符串緩沖區(qū)太小異常的文章就介紹到這了,更多相關ORA-06512數(shù)字或值錯誤字符串緩沖區(qū)太小內(nèi)容請搜索以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持!
