-1

这是我的存储过程:

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 个字符吗?谢谢!

4

1 回答 1

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 过程成功完成。

于 2013-03-14T11:39:34.757 回答