Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

php - ORA-06502: PL/SQL: numeric or value error: character string buffer too small - Executing using OCI interface

I am completely flaberghasted and dont understand what i need to do to fix this error. I have a plsql procedure that accepts a varchar2 string and an OUT param which is a number.Can you pls help me as i am learning and new to plsql and php.

type of columns member_name is VARCHAR2(100) and member_id is NUMBER(20)

create or replace procedure GET_MEMBER_ID (V_MEMBER_NAME IN  VARCHAR2,V_MEMBER_ID OUT NUMBER ) AS 
BEGIN
SELECT member_id INTO V_MEMBER_ID
FROM mn_member WHERE member_name = V_MEMBER_NAME;
END;
/

i execute the above stored procedure from php as follows

   error_reporting(E_ALL);
   ini_set('display_errors', 1);
   $conn = oci_connect("$user","$password","$sid");

   $MEMBER_ID=0;
   $MEMBER_NAME='45390';
   echo gettype($MEMBER_NAME), "
";
   echo gettype($MEMBER_ID), "
";

   $sql_get_member_id = "BEGIN GET_MEMBER_ID(:MEMBER_NAME,:MEMBER_ID);END;";
   $stmt1 = oci_parse($conn,$sql_get_member_id);

   //  Bind the input parameter
   oci_bind_by_name($stmt1,':MEMBER_NAME',$MEMBER_NAME);
   oci_bind_by_name($stmt1,':MEMBER_ID',$MEMBER_ID);

   oci_execute($stmt1);
   echo "Member ID is ".$MEMBER_ID;
?>

This is the output i see in php

string integer Warning: oci_execute() [function.oci-execute]: ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 1 in rtp2/test.php on line 26 Member ID is 0

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm no PHP guy, but from the docs:

"You must specify maxlength when using an OUT bind so that PHP allocates enough memory to hold the returned value."

Maybe try something like:

   //  Bind the input parameter
   oci_bind_by_name($stmt1,':MEMBER_NAME',$MEMBER_NAME);
   oci_bind_by_name($stmt1,':MEMBER_ID',$MEMBER_ID,20,SQLT_INT);

Not sure about the SQLT_INT data type specification necessity.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...