欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ORA-06512數(shù)字或值錯(cuò)誤字符串緩沖區(qū)太小異常詳解

 更新時(shí)間:2023年01月13日 09:43:58   作者:=PNZ=BeijingL  
最近工作中遇到了Oracle: ORA-06512:字符串緩沖區(qū)太小,報(bào)錯(cuò)的意思很簡(jiǎn)單,字符串緩沖區(qū)小了,這篇文章主要給大家介紹了關(guān)于ORA-06512數(shù)字或值錯(cuò)誤字符串緩沖區(qū)太小異常的相關(guān)資料,需要的朋友可以參考下

ORA-06512 網(wǎng)上最容易查到的解釋為

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.

舉個(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)文章

最新評(píng)論