Oracle存储Proc Varchar 3字符限制

时间:2013-03-14 11:04:47

标签: oracle stored-procedures

这是我的存储过程:

CREATE OR REPLACE
PROCEDURE "YOUQI_SP"
(
    INPUT1 IN VARCHAR2,
    INPUT2 IN VARCHAR2,
    OUTPUT1 OUT VARCHAR2
)
AS
BEGIN
    OUTPUT1 := INPUT1 || INPUT2;
    DBMS_OUTPUT.PUT_LINE('INPUT1 : ' || INPUT1);
    DBMS_OUTPUT.PUT_LINE('INPUT2 : ' || INPUT2);
    DBMS_OUTPUT.PUT_LINE('OUTPUT1 : ' || OUTPUT1);
END YOUQI_SP;

执行时没有问题:BEGIN YOUQI_SP('a', 'bc', :output1); END;。结果如下:

Array
(
    [output1] => abc
)
Array
(
    [0] => INPUT1 : a
    [1] => INPUT2 : bc
    [2] => OUTPUT1 : abc
)

但如果我在输入中再添加一个字符,我将收到错误:

[code] => 6502
[message] => ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at "YOUQI_SP", line 9 ORA-06512: at line 1

通过将变量直接分配给OUTPUT1进一步证明了这一点。它最多只能容纳3个字符。知道如何让它返回3个以上的字符?谢谢!

1 个答案:

答案 0 :(得分:2)

看来你的输出变量太短了。考虑一下:

SQL> var output1 varchar2(2)
SQL> BEGIN YOUQI_SP('aXXX', 'bcXXXX', :output1); END;
  2  /
BEGIN YOUQI_SP('aXXX', 'bcXXXX', :output1); END;
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at "TEST1.YOUQI_SP", line 9
ORA-06512: at line 1


SQL> var output1 varchar2(30)
SQL> BEGIN YOUQI_SP('aXXX', 'bcXXXX', :output1); END;
  2  /
INPUT1 : aXXX
INPUT2 : bcXXXX
OUTPUT1 : aXXXbcXXXX

PL / SQL程序已成功完成。