ORA-06512數(shù)字或值錯(cuò)誤字符串緩沖區(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.
舉個(gè)栗子來(lái)了解此異常
創(chuàng)建存儲(chǔ)過(guò)程TestProc,參數(shù)v_number是一個(gè)長(zhǎng)度為2的數(shù)字, 存儲(chǔ)過(guò)程中將100賦值給v_number,執(zhí)行存儲(chǔ)過(guò)程后提示異常,ORA-06502表示發(fā)生的錯(cuò)誤;ORA-06512表示發(fā)生的行數(shù),本例中 因?yàn)?00的是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ù)字或值錯(cuò)誤 : number precision too large ORA-06512: 在 "BOSS643.TESTPROC", line 4 ORA-06512: 在 line 2
針對(duì)上述問(wèn)題,可以重新定義數(shù)值長(zhǎng)度解決這個(gè)問(wèn)題, 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設(shè)置為處理長(zhǎng)度為10的字符串, 當(dāng)給v_str賦值大于長(zhǎng)度10的字符串后, 提示數(shù)字或者值錯(cuò)誤,符串緩沖區(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ù)字或值錯(cuò)誤 : character string buffer too small ORA-06512: 在 "BOSS643.TESTPROC2", line 4 ORA-06512: 在 line 2
重新定義varchar2長(zhǎng)度
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>
當(dāng)然你也可以自定義異常來(lái)處理,例如當(dāng)出現(xiàn)異常后提示“數(shù)值越界” ,此方法將異常捕獲提示更加明確,個(gè)人認(rèn)為ORA-06502異常已經(jīng)十分清楚了, 具體還看存儲(chǔ)過(guò)程對(duì)應(yī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
相關(guān)資源:
Oracle Database Documentation - Oracle Database
PL/SQL User's Guide and Reference -- Contents
總結(jié)
到此這篇關(guān)于ORA-06512數(shù)字或值錯(cuò)誤字符串緩沖區(qū)太小異常的文章就介紹到這了,更多相關(guān)ORA-06512數(shù)字或值錯(cuò)誤字符串緩沖區(qū)太小內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Oracle用戶密碼設(shè)為不過(guò)期的兩種方法
這篇文章主要介紹了Oracle用戶密碼設(shè)為不過(guò)期的兩種方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-12-12Oracle遞歸樹(shù)形結(jié)構(gòu)查詢功能
oracle樹(shù)狀結(jié)構(gòu)查詢即層次遞歸查詢,是sql語(yǔ)句經(jīng)常用到的,在實(shí)際開(kāi)發(fā)中組織結(jié)構(gòu)實(shí)現(xiàn)及其層次化實(shí)現(xiàn)功能也是經(jīng)常遇到的。這篇文章給大家介紹了Oracle遞歸樹(shù)形結(jié)構(gòu)查詢功能,需要的朋友參考下2019-09-09用Oracle9ias開(kāi)發(fā)無(wú)線應(yīng)用程序開(kāi)發(fā)者網(wǎng)絡(luò)Oracle
用Oracle9ias開(kāi)發(fā)無(wú)線應(yīng)用程序開(kāi)發(fā)者網(wǎng)絡(luò)Oracle...2007-03-03如何解決Oracle EBS R12 - 以Excel查看輸出格式為“文本”的請(qǐng)求時(shí)亂碼
這篇文章主要介紹了如何解決Oracle EBS R12 - 以Excel查看輸出格式為“文本”的請(qǐng)求時(shí)亂碼的相關(guān)資料,需要的朋友可以參考下2015-09-09Oracle數(shù)據(jù)加載和卸載的實(shí)現(xiàn)方法
這篇文章主要介紹了Oracle數(shù)據(jù)加載和卸載的實(shí)現(xiàn)方法,非常不錯(cuò),具有一定的參考借鑒加載,需要的朋友可以參考下2018-08-08