你好,游客 登录 注册 搜索
背景:
阅读新闻

ORA-06502 assigning values from SQL to PL/SQL variable

[日期:2012-12-20] 来源:Linux社区   作者:robinson_0612 [字体:大 中 小]

3、尝试不同版本执行该查询
-->下面在Oracle 11g做类似模拟
SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

-->Author : Robinson
-->Blog : http://blog.csdn.net/robinson_0612

SQL> create table t(dt char(8));

Table created.

SQL> insert into t select '20121218' from dual;

1 row created.

SQL> insert into t select '20121219' from dual;

1 row created.

SQL> insert into t select '20121220' from dual;

1 row created.

SQL> commit;

Commit complete.

-->同样是原来的语句,而在Oracle 11g中没有这个问题
SQL> set serveroutput on;
SQL> DECLARE
2 tradedate_out CHAR (100);
3 BEGIN
4 SELECT tradedate
5 INTO tradedate_out
6 FROM (SELECT MIN (dt) AS tradedate FROM t) d;
7
8 DBMS_OUTPUT.Put_Line ('trade_date = ' || tradedate_out);
9 END;
10 /
trade_date = 20121218

PL/SQL procedure successfully completed.

4、解决
-->为保持原有查询语句不做大量修改,通过为外层查询添加TRIM函数后问题解决
goex_admin@CNMMBO> DECLARE
2 tradedate_out CHAR (100);
3 BEGIN
4 SELECT TRIM (tradedate)
5 INTO tradedate_out
6 FROM (SELECT MIN (dt) AS tradedate FROM t) d;
7
8 DBMS_OUTPUT.Put_Line ('trade_date = ' || tradedate_out);
9 END;
10 /
trade_date = 20121218

PL/SQL procedure successfully completed.

5、Oracle BUG
-->Metalink 上溜达了一下,还真有点收获,又是一个BUG,汗....
Bug:5564384 ORA-06502 assigning values from SQL to PL/SQL variables
Component: RDBMS
Fixed Ver(s): 10204 111
Symptom(s):
- When executing a SQL that contains a concatenation / MAX of CHAR values and assigning the result to a
PL/SQL output variable an ORA-6502 may be raised.
For example:
CREATE TABLE TESTE (T1 CHAR(1), T2 CHAR(1), T3 CHAR(1));
INSERT INTO TESTE VALUES ('S', 'S', 'S');
DECLARE
V_DUMMY VARCHAR2(3);
BEGIN
SELECT MAX(X) INTO V_DUMMY FROM (SELECT T1||T2||T3 X FROM TESTE);
END;
/
^
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
Available Workaround(s):
Declare the PLSQL output variables as varchar2(4000);
References:
Note:5564384.8 Bug 5564384 - ORA-6502 assigning values from SQL to PLSQL variables

linux
相关资讯       Oracle错误代码  ORA-06502 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款