当前位置:网站首页>ORA-06512 数字或值错误字符串缓冲区太小
ORA-06512 数字或值错误字符串缓冲区太小
2022-08-03 09:18:00 【m0_67394230】
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 anexception handlerfor 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
相关资源:
Oracle Database Documentation - Oracle Database
PL/SQL User’s Guide and Reference – Contents
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- mysql8安装步骤教程
- For heavy two-dimensional arrays in PHP
- SQL每日一练(牛客新题库)——第5天:高级查询
- mysqldump导出提示:mysqldump [Warning] Using a password on the command line interface can be insecure
- WinCheck Script
- AD环境搭建
- The window of the chosen data flow
- 013-Binary tree
- STP普通生成树安全特性— bpduguard特性 + bpdufilter特性 + guard root 特性 III loopguard技术( 详解+配置)
- 好用的插件
猜你喜欢

固件工程师到底是干什么?

【微信小程序】底部有安全距离,适配iphone X等机型的解决方案

NFT到底有哪些实际用途?

SAP Analytics Cloud 和 SAP Cloud for Customer 两款 SaaS 软件的集成

Flink Yarn Per Job - 提交应用

Redis集群概念与搭建

110 MySQL interview questions and answers (continuous updates)

多媒体数据处理实验1:算术编码

SQL Daily Practice (Nioke New Question Bank) - Day 5: Advanced Query

慢 SQL 分析与优化
随机推荐
浅析什么是伪类和伪元素?伪类和伪元素的区别解析
删除文件夹时,报错“错误ox80070091:目录不是空的”,该如何解决?
Guava的缓存
unity的game界面里有canvas的线框?如何隐藏掉?
【LeetCode】622. Design Circular Queue
gpnmb+ gpnmb-AT2 cell idling mapping Epithelial cell idling mapping
10分钟带你入门chrome(谷歌)浏览器插件开发
mysqldump导出提示:mysqldump [Warning] Using a password on the command line interface can be insecure
关于Unity自定义Inspector面板的一些自定义编辑器扩展
When deleting a folder, the error "Error ox80070091: The directory is not empty" is reported. How to solve it?
cert-manager使用
Validate floating point input
判断根节点是否等于子节点之和
xtrabackup
ClickHouse查询语句详解
【LeetCode】101. Symmetric Binary Tree
Partition table (1)
Batch PNG format can be converted to JPG format
selenium IDE的3种下载安装方式
STP生成树选举结果查看及验证