in reply to DBI Out parameters

Functions in pl/sql only take input arguments so your second bound parameter should be a simple bind_param call and if the function argument is something special (e.g., a cursor which it does no look like here) you may need an extra arg to bind_param to specify the type - see the pod.

What does your function return? A value of undef in '$id' is perfectly possible if you function returns NULL.

Replies are listed 'Best First'.
Re^2: DBI Out parameters
by almut (Canon) on Nov 19, 2008 at 14:20 UTC
    Functions in pl/sql only take input arguments

    Don't think that's true.  At least, I've been using bind_param_inout() with pl/sql function arguments (like the :l_chime in the OP) in quite a number of cases without any problems...

      Just to clarify what I meant. Functions in pl/sql only allow input arguments. You cannot write:

      FUNCTION fred (arg1 OUT INTEGER) RETURN integer;

      but you can write

      FUNCTION fred (arg1 IN INTEGER) RETURN integer;

      and the IN is implied anyway.

      Also, I was not saying bind_param_inout would not work on an input only parameter but it is pointless using it and may require an unnecessary overhead on input only arguments.

        You cannot write:
        FUNCTION fred (arg1 OUT INTEGER) RETURN integer;

        Yes you can... (and if you do use such output parameters, bind_param_inout is the way to bind/access them).

Re^2: DBI Out parameters
by Anonymous Monk on Nov 19, 2008 at 14:29 UTC
    Hi, i have tried using bind_param for my second parameter. Still no luck. I have come to the conclusion that maybe one cant get at the variable on the left side of :=? For example, if i got my designer to write the function as

    create procedure search(chime in varchar, id out number)

    then i could use bind_param_inout to get at the id? For example:

    $id = $plsql->bind_param_inout(":id",\$id,16);<br> print "$id";<p>
    Am i correct in thinking that? Thanks
      maybe one cant get at the variable on the left side of :=?

      It should work (I've done it many times myself...), so I think the problem lies elsewhere.

      You certainly can get function return values back in perl. You can also get output arguments back in procedures. I do this all the time with DBD::Oracle.

      use DBI; use strict; my $h = DBI->connect('dbi:Oracle:xxx','xxx','xxx'); eval {$h->do(q{drop function fred});}; my $sql = <<'EOT'; create function fred(a integer) return integer as begin return (a + 1); end; EOT $h->do($sql); my $s = $h->prepare(q{begin ? := fred(?); end;}); $s->bind_param(2, 1); my $res; $s->bind_param_inout(1, \$res, 100); $s->execute; print "fred=$res\n";

      outputs fred=2