ORA-06502:PL / SQL:数字或值错误:字符串缓冲区太小,当PLSQL调用

时间:2015-12-18 14:25:32

标签: php oracle plsql

我已经开始收到以下错误,因为我在此过程中添加了o_ID,一切正常,直到我添加到o_ID,是否与设置o_ID有关可能是错误的数据类型?我已经查阅过任何其他相关主题,但无济于事。

o_ID被调用之前,

PR_LOAD_XML_FILE最初设置如下:

$id = 0;
$stmt->bindParam('o_ID', $id);

来自日志

2015-12-18T13:02:06+00:00 ERR (3): An exception occurred while executing 'BEGIN PR_LOAD_XML_FILE (
        i_XML => :i_XML,
        i_FILENAME => :i_FILENAME,
        o_ID => :o_ID,
        on_ErrorID => :on_ErrorID
        );
    END;' with params ["<?xml version=\"1.0\" encoding=\"UTF-8\" ?><test><TestDetails><TestVersionId>3244<\/TestVersionId><Marks>20<\/Marks><\/TestDetails><\/test>", "test.csv"]:

ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 1

程序规范

PROCEDURE PR_LOAD_XML_FILE (
    i_XML IN CLOB,
    i_FILENAME IN XML_DOC.FILENAME%TYPE,
    o_ID OUT NUMBER,
    on_ErrorID OUT INTEGER
);

程序正文

PROCEDURE PR_LOAD_XML_FILE (
        i_XML IN CLOB,
        i_FILENAME IN XML_DOC.FILENAME%TYPE,
        o_ID OUT NUMBER,
        on_ErrorID OUT INTEGER
    ) IS
        doc_id XML_DOC.id%TYPE;
        xml        XMLTYPE;
    BEGIN
        ...
    END PR_LOAD_XML_FILE;

1 个答案:

答案 0 :(得分:2)

我认为当您调用过程时,您将设置变量以接收o_ID的值作为字符串。这是我嘲笑你的包裹:

CREATE OR REPLACE PACKAGE PKG_PR_LOAD_XML_FILE
AS
  PROCEDURE PR_LOAD_XML_FILE (
    i_XML IN CLOB,
    i_FILENAME IN varchar2,
    o_ID OUT NUMBER,
    on_ErrorID OUT INTEGER );
END PKG_PR_LOAD_XML_FILE;
/
CREATE OR REPLACE PACKAGE BODY PKG_PR_LOAD_XML_FILE
AS
  PROCEDURE PR_LOAD_XML_FILE (
    i_XML IN CLOB,
    i_FILENAME IN varchar2,
    o_ID OUT NUMBER,
    on_ErrorID OUT INTEGER )
  IS

  BEGIN
    dbms_output.put_line( 'i_XML: '||i_XML );
    dbms_output.put_line( 'i_FILENAME: '||i_FILENAME );
    o_ID := 999999;
    on_ErrorID := 123456789;
  END PR_LOAD_XML_FILE;
END PKG_PR_LOAD_XML_FILE;
/

在SQL * Plus中,我将首先定义这两个绑定变量。请注意绑定变量v_o_ID如何设置为 varchar2(4)。这意味着失败,因为o_ID的值在过程中设置为 999999 ,超过4个字符(如果o_ID的值设置为9999,是4个字符或更少,然后程序调用工作正常,但错误仍然存​​在,并且一旦o_ID的值大于4个字符就会悄悄上升):

SQLPlus> var v_o_ID varchar2(4)
SQLPlus> var v_on_ErrorID number

现在我在SQL * Plus中调用该过程,它将失败

SQLPlus> exec PKG_PR_LOAD_XML_FILE.PR_LOAD_XML_FILE( '<heres my XML>', 'heresfilename.csv', :v_o_ID, :v_on_ErrorID);
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 1

现在我将绑定变量v_o_ID设置为数字,过程调用将是成功。如果使用print命令打印绑定变量,则可以看到过程中收到的值:

SQLPlus> var v_o_ID number

SQLPlus> exec PKG_PR_LOAD_XML_FILE.PR_LOAD_XML_FILE( '<heres my XML>', 'heresfilename.csv', :v_o_ID, :v_on_ErrorID);
i_XML: <heres my XML>
i_FILENAME: heresfilename.csv

PL/SQL procedure successfully completed.
SQLPlus> print v_o_ID
    V_O_ID
----------
    999999

SQLPlus> print v_on_ErrorID
V_ON_ERRORID
------------
   123456789