laravel-oci8 icon indicating copy to clipboard operation
laravel-oci8 copied to clipboard

Oracle function with multiple parameters

Open lemmeV opened this issue 6 years ago • 1 comments

Summary of problem or feature request

I am trying to run an oracle function and get the result like in the documentation example here (via PDO): https://yajrabox.com/docs/laravel-oci8/master/function

Code snippet of problem

$pdo = DB::connection('connection_name')->getPdo();
$result = null;
$stmt = $pdo->prepare("begin :result := myFunction(:param1,:param2,:param3,:param4); end;");
$stmt->bindParam(':result', $result, \PDO::PARAM_STR);
$stmt->bindParam(':param1', $param1, \PDO::PARAM_INT);
$stmt->bindParam(':param2', $param2, \PDO::PARAM_INT);
$stmt->bindParam(':param3', $param3, \PDO::PARAM_STR);
$stmt->bindParam(':param4', $param4, \PDO::PARAM_STR);
$stmt->execute();

dd($result);

i recceive an error:

"Error Code    : 20001\r\nError Message : ORA-20001: General Error. Statement   
  : begin :result := myFunction(:param1,:param2,::param3,::param4); end;\r\nBindings    
  : [,1,1201,'my string','01-Aug-2019']\r\n",

In the statement part i see that it is trying to bind all 5 parameters into the function input, even though the the result should be the returning value ([,1,1201,'string','01-Aug-2019']).

If i change the order of the parameter binds and leave result to last, then i get the same error but with [1,1201,STL_AKTMNR,01-Aug-2019,] - so it look like its trying to insert the result parameter as the 5th input in the function.

Apart from having multiple parameters, the code is the same as example given:

// via PDO
$pdo = DB::getPdo();
$x = 2;

$stmt = $pdo->prepare("begin :y := myfunc(:x); end;");
$stmt->bindParam(':y', $y);
$stmt->bindParam(':x', $x);
$stmt->execute();

return $y; // prints 6

What could be the issue?

System details

  • Windows 10
  • 7.2.19
  • Laravel Version 5.8.27
  • Laravel-OCI8 Version v5.8.2

lemmeV avatar Aug 01 '19 11:08 lemmeV

Not sure but maybe try specifying the length on result?

$pdo = DB::connection('connection_name')->getPdo();
$result = null;
$stmt = $pdo->prepare("begin :result := myFunction(:param1,:param2,:param3,:param4); end;");
$stmt->bindParam(':result', $result, \PDO::PARAM_STR|\PDO::PARAM_INPUT_OUTPUT, 12);
$stmt->bindParam(':param1', $param1, \PDO::PARAM_INT);
$stmt->bindParam(':param2', $param2, \PDO::PARAM_INT);
$stmt->bindParam(':param3', $param3, \PDO::PARAM_STR);
$stmt->bindParam(':param4', $param4, \PDO::PARAM_STR);
$stmt->execute();

dd($result);

yajra avatar Sep 13 '19 00:09 yajra

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Oct 26 '22 03:10 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Nov 02 '22 03:11 github-actions[bot]