Oracle bug 使用max或min函数into到一个char类型报字符缓冲区太小的错误
這個BUG出現會報錯如下:
selectto_char(max(RENEWAL_DATE))?intoM_YEAR_MONTH?fromt_renewal_schedule;
ORA-06502: PL/SQL:數字或值錯誤:?字符串緩沖區太小
這個時候有3個方法可以解決
1、setting initialisation parameter BLANK_TRIMMING=TRUE
2、declare PL/SQL CHAR and VARCHAR2 variable used in the INTO clause of SELECT statement as 4,000 bytes.
3、Use CAST?SQL?function to constraint the size to that of the variable size like
?SELECT CAST(MIN('Y') AS CHAR(1)) INTO C FROM DUAL;
CAST是強制轉換函數。
參數BLANK_TRIMMING設置為TRUE的時候可以解決我們的BUG問題,同時這個參數設置為TRUE會在進行變量的賦值的時候忽略末尾的空格,同時這個參數必須關閉數據庫進行更改。所以請評估下,是否可行。
?
試驗如下:
?
SQL> CREATE TABLE abc (
? 2? cont_no char(8),
? 3? plan_id char(7));
?
Table created
SQL> INSERT INTO abc VALUES ('123456 ?', '7654321'); ??---(這里空格有2位)
1 row inserted
SQL> commit;
?
SQL> DECLARE
?2???? c_Plan_ID char(6);
? 3? BEGIN
? 4???? SELECT cont_no INTO c_Plan_ID from abc;
? 5???? dbms_output.put_line(c_Plan_ID);
? 6? END;
? 7? /
DECLARE
?? c_Plan_ID char(6);
BEGIN
?? SELECT cont_no INTO c_Plan_ID from abc;
?? dbms_output.put_line(c_Plan_ID);
END;
ORA-06502: PL/SQL:數字或值錯誤:?字符串緩沖區太小
ORA-06512:在line 5
然后我們修改參數BLANK_TRIMMING為true
alter system set BLANK_TRIMMING=true scope=spfile;
重啟數據庫進行測試
進行測試
SQL>? DECLARE
?2???????? c_Plan_ID char(6);
? 3????? BEGIN
? 4???????? SELECT cont_no INTO c_Plan_ID from abc;
? 5???????? dbms_output.put_line(c_Plan_ID);
? 6????? END;
? 7? /
?
123456
?
PL/SQL procedure successfully completed
看到可以完成了
?
下面是METALINK的原話
SELECT containing a MIN or MAX into a CHAR variable inside a PL/SQL block Fails With ORA-06502 [ID 311653.1]??
Applies to:
Oracle?Server?-EnterpriseEdition - Version:10.1.0.4 to 10.1.0.4
Oracle Server -EnterpriseEdition - Version:9.2.0.6 to 9.2.0.7
Oracle Server -EnterpriseEdition - Version:10.2.0.1 to 10.2.0.1
This problem can occur on any platform.
?
Symptoms
SELECT containing a MIN or MAX into a CHAR variable inside a PL/SQL block Fails With:
?
?
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
?
Example:
?DECLAREC CHAR(1);BEGINSELECT MIN('Y') INTO C FROM dual;END;/DECLARE*ERROR at line 1:ORA-06502: PL/SQL: numeric or value error: character string buffer too smallORA-06512: at line 4Changes
After upgrading to Oracle10gR210.2.0.1
After applying10.1.0.4 patchset
After applying9.2.0.6 patchset
After applying9.2.0.7 patchset
Cause
This problem has been identified as
?
Bug:4458790 ORA-6502 selecting MAX/MIN into a CHAR variable in PLSQL
?
This problem is introduced in Oracle9i9.2.0.6, Oracle10g10.1.0.4 and 10.2.0.1 by the fix for Bug:3499258.
?
A PLSQL block which SELECTs a MAX or MIN into a fixed CHAR variable can fail with an unexpected ORA-6502 "character string buffer too small" error.
Solution
This problem is fixed in
?
Oracle9iR2 (9.2.0.8, terminal patchset)
Oracle11gR1(11.1.0.x or higher)
Oracle10gR1(10.1.0.5 or higher)
?
Oracle10gR2 (10.2.0.2 or higher)
?
Workarounds:
?
setting initialisation parameter BLANK_TRIMMING=TRUE
?
?
declare PL/SQL CHAR and VARCHAR2 variable used in the INTO clause of SELECT statement as 4,000 bytes.
?
?
Use CAST SQL function to constraint the size to that of the variable size like
?
SELECT CAST(MIN('Y') AS CHAR(1)) INTO C FROM DUAL;
?
轉載于:https://www.cnblogs.com/jmax/p/3161826.html
總結
以上是生活随笔為你收集整理的Oracle bug 使用max或min函数into到一个char类型报字符缓冲区太小的错误的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 退役啦
- 下一篇: jqgrid表格下拉搜索多选框优化—使用