curtisb has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Updating database question
by dragonchild (Archbishop) on Jun 30, 2005 at 18:21 UTC | |
by curtisb (Monk) on Jun 30, 2005 at 18:47 UTC | |
by dragonchild (Archbishop) on Jun 30, 2005 at 18:53 UTC | |
|
Re: Updating database question
by Fletch (Bishop) on Jun 30, 2005 at 18:40 UTC | |
by jhourcle (Prior) on Jun 30, 2005 at 20:41 UTC | |
by curtisb (Monk) on Jun 30, 2005 at 18:46 UTC | |
by Fletch (Bishop) on Jun 30, 2005 at 19:29 UTC | |
|
Re: Updating database question
by shiza (Hermit) on Jun 30, 2005 at 18:55 UTC | |
by curtisb (Monk) on Jun 30, 2005 at 18:59 UTC | |
by shiza (Hermit) on Jun 30, 2005 at 19:03 UTC | |
by curtisb (Monk) on Jun 30, 2005 at 19:25 UTC | |
by shiza (Hermit) on Jun 30, 2005 at 19:31 UTC | |
by dragonchild (Archbishop) on Jun 30, 2005 at 19:04 UTC | |
by shiza (Hermit) on Jun 30, 2005 at 19:26 UTC | |
by dragonchild (Archbishop) on Jun 30, 2005 at 21:03 UTC | |
|
Re: Updating database question
by VSarkiss (Monsignor) on Jul 01, 2005 at 02:50 UTC |