1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!c:\perl\bin\perl.exe -w
# Datenbank -- Zelleninhalt verändern
use DBI;
$dbh = DBI->connect("dbi:Oracle:host=TestRechner;sid=ora1;port=1521", "test", "test");
if (!$dbh) {
print "Zgriff verweigert!\n";
exit (1);
}
$Abfrage1 = "SELECT SP1,SP2 FROM tab2 ORDER by SP1";
print "$Abfrage1 \n";
$sth = $dbh->prepare($Abfrage1);
$rv = $sth->execute();
print "$rv\n";
if ($rv <= 0) {
print "Keine Ergebniswerte!\n";
#exit (1);
}
while (@row = $sth->fetchrow_array) {
printf " %-40s %s\n",$row[0],$row[1];
}
$dbh->disconnect if ($dbh);
1 2 3 4 5 6 7 8
my $count = 0; while (my @row = $sth->fetchrow_array) { $count++; printf " %-40s %s\n",$row[0],$row[1]; } unless ($count) { print "Keine Ergebniswerte!\n"; }
Quote$rv = $sth->rows;
Returns the number of rows affected by the last row affecting command, or -1 if the number of
rows is not known or not available.
Generally, you can only rely on a row count after a non-"SELECT" "execute" (for some specific
operations like "UPDATE" and "DELETE"), or after fetching all the rows of a "SELECT" statement.
Quoteexecute returns the number of rows affected, if known. If no rows were affected, then execute returns ``0E0'', which Perl will treat as 0 but will regard as true
printf "%d", '0E0'; # 0
2011-05-25T12:49:23 rostiexecute('prepared statement') liefert als rv die Anzahl der betroffenen Zeilen.
QuoteFor "SELECT" statements, execute simply "starts" the query within the database engine. Use one
of the fetch methods to retrieve the data after calling "execute". The "execute" method does
not return the number of rows that will be returned by the query (because most databases can’t
tell in advance), it simply returns a true value.
2011-05-25T13:09:11 pq2011-05-25T12:49:23 rostiexecute('prepared statement') liefert als rv die Anzahl der betroffenen Zeilen.
ja, aber nur bei nicht-selects. also updates oder inserts.
ich schrieb es doch oben.