homer4all has asked for the wisdom of the Perl Monks concerning the following question:
DB: oracle 11gR2
I tried using $days = $ARGV[1], not sure but it doesn't work.
Usage: ./delete_data.pl -days 30Does above delete all days together or it will use cursor and delete one day at a time? Deleting one day at a time using bind variable will give better performance. Thanks...sub deleteData { $days = <how to have 10 here??>; my $sth = $dbh->prepare("DELETE FROM TEST_TABLE WHERE date = trunc(sysdate) - ?"); $sth->execute( $days ) or die $DBI::errstr; print "Number of rows deleted :" + $sth->rows; $sth->finish(); $dbh->commit or die $DBI::errstr; }
Update
Experts, How can we use value in sub which was accepted at script run?DB: oracle 11gR2
I tried using $days = $ARGV[0], not sure but it doesn't work.
Usage: ./delete_data.pl -days 30I'm not able to display value for $days even in logfile. Not sure why above just don't work, I have used suggestion solution from comment. Thanks...my $days; sub deleteData { my $rc; if (@ARGV) { $days = $ARGV[0]; $logfile-> logmessage ("Days in sub $days ...) } $days = shift (@ARGV); my $SQL = qq{ DELETE from TEST_TABLE WHERE trunc(date) < trunc(sysdate) - $days }; $sth->prepareCursor( $SQL ) or die $DBI::errstr; print "Number of rows deleted :" + $sth->rows; $sth->execute(); $rc++ $sth->finish() }
|
|---|