0

I have been calling stored procs in Oracle using doctrine doing something like:

$sql = "CALL namespace.my_proc(".$data_source_id.", to_date('".$account_period_start."', 'YYYY-MM-DD'),'".$updated_by."')";

$stmt = $this->getDoctrine()->getManager('fdw')->getConnection()->prepare($sql);
            $result = $stmt->execute();
            $stmt->closeCursor();

Now the DBA team has changed one of the stored procs to accept 2 output parameters (x and y) and I am not understanding how to make that happen. Can someone please assist me with that?

Thank You

3 Answers 3

3

I was able to find out the info. Hope it helps someone.

$sql = "CALL namespace.my_proc(".$data_source_id.", to_date('".$account_period_start."', 'YYYY-MM-DD'),'".$updated_by."', :x, :y)";
  $stmt = $this->getDoctrine()->getManager('fdw')->getConnection()->prepare($sql);
            $stmt->bindParam(':x', $x, \PDO::PARAM_INPUT_OUTPUT, 32);
            $stmt->bindParam(':y', $y, \PDO::PARAM_INPUT_OUTPUT, 32);
            $result = $stmt->execute();
Sign up to request clarification or add additional context in comments.

Comments

0

For most recent versions of doctrine:

$sql = 'call my_proc(:arg1, :arg2)';
$stmt = $em->getConnection()->prepare($sql);
$stmt->executeQuery([
    ':arg1' => 82,
    ':arg2' => 'Foo',
]);

However, for output parameters you apply the same logic for functions:

$sql = 'BEGIN :total := sum(:num1, :num2); END;';
$stmt = $em->getConnection()->prepare($sql);
$stmt->bindParam(':total', $total);
$stmt->executeQuery([
    ':num1' => 6,
    ':num2' => 7
]);

$total will store the output

Comments

0

here is the working snippet. No need of $sql part, because we use the procedure, instead of using sql statements.

$result = null;
DB::connection('orange')->executeProcedure('OS_USR.OSOPR.p_get_multiplication',
[
    'res' => &$result,
    'a' => 2,
    'b' => 3,
]);
return $result;

Note that this snippet uses Oracle connection with OCI8 driver by yajra/laravel-oci8.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.