All
I'm trying to get a particular field to update in my database. The code below reads from a table in my database. If the value of $row4 matches what I'm looking for change the values of $row3.
Now this works from the command prompt with no problem. What I'm trying to figure out is how do I update $row3 in my database table. Do I have to do a push or prepare another statement and then call it from there?
I'm just looking for some guidence on this one. Thanks in advance
Bobby
b.curtis@stanleyassociates.com
#!/usr/bin/perl # #Connects to a Sybase Database use DBI qw(neat_list); #Loads DBI module #Connect.... my $dbh = DBI->connect("dbi:ODBC:davs", "<username>", "<password>", { PrintError => 0, RaiseError => 1 }) or die "Can't connect to database: $DBI::errstr\n"; #Prepare statement.... my $sth = $dbh->prepare("SELECT * FROM STAGING.STAGING_PREPOUICS;") or + die "Can't prepare SQL statement: $DBI::errstr\n"; #Excute statement.... $sth->execute or die "Can't execute SQL statment: $DBI::errstr\n"; #Retrive Rows.... while( @row = $sth->fetchrow_array() ) { if($row[4] =~ m/ENG/i) { $row[3]='EN'; } elsif($row[4] =~ m/AVN/i) { $row[3]='AV'; } elsif($row[4] =~ m/TRAN/i) { $row[3]='TN'; } elsif($row[4] =~ m/QM/i) { $row[3]='QM'; } elsif($row[4] =~ m/MI/i) { $row[3]='MI'; } elsif($row[4] =~ m/POLICE/i || $row[4] =~ m/MP/i) { $row[3]='MP'; } elsif($row[4] =~ m/CHAPLAIN/i) { $row[3]='CH'; } elsif($row[4] =~ m/INF/i) { $row[3]='IN'; } elsif($row[4] =~ m/FA/i) { $row[3]='FA'; } elsif($row[4] =~ m/MED/i) { $row[3]='MD'; } elsif($row[4] =~ m/SIG/i) { $row[3]='SC'; } elsif($row[4] =~ m/MAIN/i) { $row[3]='SS'; } elsif($row[4] =~ m/AR/i) { $row[3]='AR'; } else { $row[3]='PU'; } print "Unit Info:\n"; print "$row[0],$row[1],$row[2],$row[3],$row[4],$row[5]\n"; } warn "Data fetching terminated early by error: $DBI::errstr\n" if $DBI::err; #Finish statement.... $sth->finish; #Disconnect..... $dbh->disconnect or warn "Disconnection failed: $DBI::errstr\n"; exit;
In reply to Updating database question by curtisb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |