develooper Front page | perl.dbi.users | Postings from January 2012

Re: More of an oracle question than dbi...

Thread Previous | Thread Next
From:
Martin J. Evans
Date:
January 11, 2012 00:58
Subject:
Re: More of an oracle question than dbi...
Message ID:
4F0D4F36.7040500@easysoft.com
On 09/01/12 16:30, Bruce Johnson wrote:
> ...but I'm trying to do this via a script.
>
> The code:
>
> create or replace trigger resource_key before insert on resources
> for each row
> begin
> select resource_id_seq.nextval into :new.resource_id from dual;
> end;
>
> Works in sqlplus, but does not when executed via dbi or via jdbc.
>
> What I end up with instead is the code in the trigger:
>
> create or replace trigger resource_key before insert on resources
> for each row
> begin
> select resource_id_seq.nextval into :new.resource_id from dual
>
> And an error about an invalid sql command for the 'end;' bit.
>
> How do I make this work within dbi?
>
>

The following works fine for me:

use DBI;
use strict;
use warnings;

my $h = DBI->connect('dbi:Oracle:host=xxx.yyy.zzz;sid=xxx', 'xxx', 'yyy',
                      {RaiseError => 1});
my $sql = <<'EOT';
create or replace trigger job_audit_t1 before insert or update on job_audit for each row
   begin
      IF INSERTING THEN
         select job_audit_seq.nextval INTO :new.job_audit_id from dual;
         :new.created_by_user := user;
      ELSIF UPDATING THEN
         :new.modified_by_user := user;
      END IF;
   end;
EOT
$h->do($sql);

Show us the code, error and the SQL instead of just the SQL.

Martin
-- 
Martin J. Evans
Easysoft Limited
http://www.easysoft.com

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About