久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

ORA-06512數字或值錯誤字符串緩沖區太小異常詳解

瀏覽:74日期:2023-03-12 15:25:33

ORA-06512 網上最容易查到的解釋為

Cause

This 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.

舉個栗子來了解此異常

創建存儲過程TestProc,參數v_number是一個長度為2的數字, 存儲過程中將100賦值給v_number,執行存儲過程后提示異常,ORA-06502表示發生的錯誤;ORA-06512表示發生的行數,本例中 因為100的是3位數字, v_number只能處理2位數字

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: 數字或值錯誤 : number precision too large
ORA-06512: 在 "BOSS643.TESTPROC", line 4
ORA-06512: 在 line 2

 針對上述問題,可以重新定義數值長度解決這個問題, 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> 

如果將數值型修改成其他類型后也是同樣的, 例如字符串,v_str設置為處理長度為10的字符串, 當給v_str賦值大于長度10的字符串后, 提示數字或者值錯誤,符串緩沖區太小

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: 數字或值錯誤 : 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> 

當然你也可以自定義異常來處理,例如當出現異常后提示“數值越界” ,此方法將異常捕獲提示更加明確,個人認為ORA-06502異常已經十分清楚了, 具體還看存儲過程對應的需求是否有明確提示需求

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, "數值v_number越界");
  8  END;
  9  /
 
Procedure created
 
SQL> exec TestProc();
 
begin TestProc(); end;
 
ORA-20001: 數值v_number越界
ORA-06512: 在 "BOSS643.TESTPROC", line 7
ORA-06512: 在 line 2

相關資源:

總結

到此這篇關于ORA-06512數字或值錯誤字符串緩沖區太小異常的文章就介紹到這了,更多相關ORA-06512數字或值錯誤字符串緩沖區太小內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!

標簽: Oracle
主站蜘蛛池模板: 涿鹿县| 黑水县| 宝坻区| 永顺县| 广安市| 清原| 治多县| 襄垣县| 陕西省| 鄯善县| 桂林市| 池州市| 礼泉县| 玉环县| 东乡族自治县| 萨迦县| 界首市| 筠连县| 鹤庆县| 兴和县| 嘉定区| 颍上县| 漳浦县| 兰西县| 东乌珠穆沁旗| 平利县| 辰溪县| 北流市| 枣庄市| 新昌县| 泰州市| 康马县| 浦县| 瑞金市| 夏河县| 丽水市| 灵台县| 即墨市| 乌苏市| 宁阳县| 墨竹工卡县|