invocare una procedura memorizzata con parametro di input e cursore in fuori nello script perl

Aug 24 2020

Cercando di eseguire una procedura in perl script, Procedi -> crea o sostituisci

PROCEDURE Getproc
(
    v_catg IN CHAR DEFAULT NULL,
    v_cursor OUT SYS_REFCURSOR
)
  1. per eseguire la procedura

    my $sth = $dbh->prepare(
        q{
            BEGIN
            Getproc(:category, :curs);
            END;
        }
    );
    
  2. per associare i / pe cursore

    $sth->bind_param(":category", $category1);
    
    $sth->bind_param_inout(":curs", \$cursrecords, 0, {ora_type => ORA_RSET});
    
    $sth->execute; $sth->finish; 
    
  3. Recupera i record dal cursore

    while ($hashRef = $cursrecords->fetchrow_hashref) {
        foreach (keys %$hashRef) { print "hashref:$hashRef and $_ is $hashRef->{$_}\n";
        }
    }
    

Il terzo passaggio non è recuperare nulla. curserecords=DBI::st=HASH(0x2371bd0)questo ha un oggetto hash. Qualcuno può aiutarmi a sapere cosa manca qui. Perché non riesco a recuperare le righe dalla tabella memorizzata nel cursore?


PROCEDURA per riferimento

create or replace PROCEDURE GetProc
(
    v_catg IN CHAR DEFAULT NULL,
    v_cursor OUT SYS_REFCURSOR
)
AS
BEGIN
IF ( v_catgIS NULL ) THEN
    BEGIN
        OPEN  v_cursor FOR
        SELECT EnvVar,
        VALUE 
        FROM table;
    END;
ELSE
    BEGIN
        OPEN  v_cursor FOR
        SELECT EnvVar ,
        VALUE 
        FROM table
        WHERE  Category = v_catg ;
    END;
END IF;

EXCEPTION
    WHEN OTHERS THEN raise_application_error(-20002,SQLCODE||':'||SQLERRM);
END;

Risposte

1 GerardH.Pille Aug 25 2020 at 20:29

Per favore prova (come nella collezione di René Nyffenegger )

my $sth = $dbh->prepare(
  q{
    DECLARE
      curs sys_refcursor;
    BEGIN
      Getproc(:category, :curs);
    END;
  });