ptum has asked for the wisdom of the Perl Monks concerning the following question:
Update: I can no longer replicate the original problem with inserting strings with ampersands. The prepare/execute approach with bind variables (suggested by [id://pajout] and [id://kwaping]) worked, but then, so did my original insert. I am tentatively concluding that, as [id://Roy Johnson] and [id://jhourcle] suggest, my problem was entirely within SQLPlus, and that the error I saw in my Perl DBI script execution was something else (probably a referential integrity issue). Presumably when I followed up on that original error by pasting the offending statement into SQLPlus, I was fooled by the &var replacement red herring.
Either that or evil database gnomes have been at work during the night, in an unnecessary effort to discredit me.
Thank you for all of your suggestions and help.
=================================Original post: I have some data which I need to insert into an Oracle table; the data has embedded ampersands in it, which causes Oracle to prompt for a parameter (and my insert to fail). Using SQLPlus, I see that I can either:
"set define off" or
"set escape \" and then escape the ampersand with a preceding backslash.
But I can't seem to get this to work through the DBI. Here's what I have tried so far:
I'm getting an error message much like this one:my $data_source = "dbi::Oracle:$sid"; my $sqlhandle = DBI->connect("dbi:Oracle:host=$host;sid=$sid;port=15 +21", $user, $password, { RaiseError => 1, AutoCommit => 0 }) or die "Can't connect to $data_source: $DBI::errstr"; my $func = $sqlhandle->prepare(q{ BEGIN set define off; END; }); my $result = $func->execute();
DBD::Oracle::st execute failed: ORA-06550: line 3, column 17: PL/SQL: ORA-00922: missing or invalid option ORA-06550: line 3, column 13: PL/SQL: SQL Statement ignored (DBD ERROR: error possibly near <*> indi +cator at char 31 in ' BEGIN set <*>define off; END; ') [for Statement " BEGIN set define off; END; "] at /blah/blah/Blah.pm line 348, <BLAHFILE> line 104133.
Any help or suggestions would be greatly appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Executing Oracle PL/SQL statements through the DBI
by Roy Johnson (Monsignor) on Mar 14, 2006 at 16:00 UTC | |
by ptum (Priest) on Mar 14, 2006 at 16:47 UTC | |
|
Re: Executing Oracle PL/SQL statements through the DBI
by kwaping (Priest) on Mar 14, 2006 at 15:30 UTC | |
by ptum (Priest) on Mar 14, 2006 at 15:48 UTC | |
|
Re: Executing Oracle PL/SQL statements through the DBI
by pajout (Curate) on Mar 14, 2006 at 15:15 UTC | |
by ptum (Priest) on Mar 14, 2006 at 15:26 UTC | |
by pajout (Curate) on Mar 14, 2006 at 15:45 UTC | |
by jhourcle (Prior) on Mar 14, 2006 at 15:46 UTC |