#!/usr/bin/perl use strict; use DBI; my $dbh_o = DBI->connect ('dbi:Oracle:devdb, 'user', 'pass') or die("Cannot connect"); my $SQL = "SELECT ID FROM THE_TABLE"; # ID is the primary key for THE_TABLE and is a RAW field my $sth_o = $dbh_o->prepare( $SQL ); $sth_o->execute(); my $object_id; $sth_o->bind_columns( undef, \$object_id); while ($sth_o->fetch()) { my $SQL2 = "SELECT THE_NUM, THE_VALUE FROM THE_OTHER_TABLE WHERE PROPERTY_ID = 'biglongstring' AND PARENT_ID = '" . $object_id . "'"; # PROPERTY_ID and PARENT_ID are both raw fields. I only need rows where PROPERTY_ID is a certain value. If the data was entered correctly THE_NUM should indicate the order the item was added to the record (i.e. the first item added will be 0, the 2nd item added will be 1, etc) my $sth_o2 = $dbh_o->prepare($SQL2); $sth_o2->execute(); my($num, $val); $sth_o2->bind_columns(undef, \$num, \$val); while($sth_o2->fetch()) { if ($num > 0) { # omitting stuff that produces the value $text; my $SQL3 = "UPDATE THE_TABLE SET THE_TEXT_FIELD='" . $text . "' WHERE OBJECT_ID = '$object_id'; # omitting code to run this query. } } }