Hi,
I'm still trying to update through a cursor, and I still can't get it to
work. The program fails at statement->execute(value) with the message
DBD::Oracle::st execute failed:
ORA-00936: missing expression (DBD ERROR: OCIStmtExecute)
at ./test.pl line 27, <STDIN> chunk 1.
What am I doing wrong now?
I wondered if the UPDATE statement should have ":csr" instead of "csr",
but then the program complained that I could not mix ':' and '?'
variables.
Here is the program:
#!/local/bin/perl5 -w
my($database, $user, $password) = ("lttest", "hbf");
use strict;
use DBI;
use DBD::Oracle qw(:ora_types);
&Login;
my $dbh = DBI->connect("dbi:Oracle:$database", $user, $password,
{ 'AutoCommit' => 0, 'RaiseError' => 1 });
my $sel = $dbh->prepare("
BEGIN
OPEN :csr FOR
SELECT fakultetnavn FROM lt.fakultet WHERE fakultetnavn IS NOT NULL
FOR UPDATE;
END;");
my $csr;
$sel->bind_param_inout(":csr", \$csr, 0, { ora_type => ORA_RSET } );
$sel->execute();
my $upd = $dbh->prepare("
UPDATE lt.fakultet SET fakultetnavn=? WHERE CURRENT OF csr");
while ((my $value) = $csr->fetchrow_array) {
my $new = change($value);
$upd->execute($new) if $new && $new ne $value;
}
undef $upd;
undef $csr;
undef $sel;
$dbh->rollback; # just testing so far
$dbh->disconnect;
########################################################################
########################################################################
sub change {
my($value) = @_;
$value =~ tr/A-Z/a-z/; # simple example
$value;
}
sub Login {
local($|) = 1;
$user = $ARGV[0] if $ARGV[0];
unless ($user) {
print "User: ";
chomp($user = <STDIN>);
}
$database = $1 if $user =~ s%\@([^\@/]*)(?=$|/)%%;
$password = $1 if $user =~ s%/([^\@/]*)$%%;
die "Invalid user '$user'\n" if $user =~ m%[,.\@/]%;
unless ($database) {
print "Database: ";
chomp($database = <STDIN>);
}
unless ($password) {
system("stty -echo");
print "Password for $user\@$database: ";
local($SIG{'INT'}) = \&signal_echo;
local($SIG{'TERM'}) = \&signal_echo;
chomp($password = <STDIN>);
system("stty echo");
print "\n";
}
}
sub signal_echo {
system("stty echo");
print "\n";
exit(130);
}