hs has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am trying to run a ORacle anonymous block using perl DBI, but I am receiving error as mentioned below. Please help..
sub runThis($procT) { my $dbh1=DBI->connect("dbi:ODBC:$db","$usr","$pass", {RaiseError => 1 , PrintError => 0} ); $sqlstmt1 = "BEGIN $procT END;"; $sth1 = $dbh1->do($sqlstmt1) or die $dbh1->errstr; $dbh1 -> disconnect; } runThis("BEGIN NULL; END;");
--------------------------------------- Error message:
DBD::ODBC::db do failed: [Oracle][ODBC][Ora]ORA-06550: line 1, column +7: PLS-00103: Encountered the symbol "END" when expecting one of the foll +owing:
---------------------------- Thanks

Replies are listed 'Best First'.
Re: execute Oracle anonymous procedure using perl
by NetWallah (Canon) on Feb 04, 2016 at 20:27 UTC
    Please use <code> tags , as described in Markup in the Monastery.

    You are effectively passing the command:

    BEGIN BEGIN NULL;END;END
    To oracle. This seems to generate an Oracle syntax error.

    To see what it does, run that using "sqlplus", and see if you get the same result.

            ...The words of the Prophets are written on the Facebook wall.

      Thanks for response. I am using ODBC as see in the DBI statement.
Re: execute Oracle anonymous procedure using perl
by poj (Abbot) on Feb 04, 2016 at 20:26 UTC
    #!perl use strict; use DBD::Oracle; runThis("BEGIN :now := CURRENT_TIMESTAMP ; END;"); sub runThis { my $procT = shift; my $dbh1=DBI->connect( 'dbi:Oracle:host=localhost;sid=xe','user','password', {RaiseError => 1 , PrintError => 0} ); my $now = ''; my $sth1 = $dbh1->prepare($procT); $sth1->bind_param_inout(":now",\$now,0); $sth1->execute; $dbh1->disconnect; print "time now is $now\n"; }
    poj

        What are your OS, Perl and Oracle versions ?

        poj
Re: execute Oracle anonymous procedure using perl
by mje (Curate) on Feb 08, 2016 at 10:14 UTC

    In ODBC you use '{call procname (arguments)}'.