This is the data that I would like to sort.
AAAAAAAA 0.0.0.0 hs01.stuff.net
BBBBBBBB 0.0.0.0 hs01.morestuff.net
CCCCCCCC 0.0.0.0 hs01.evenmorestuff.net
DDDDDDDD 0.0.0.0 hs01.stuff.net
EEEEEEEE 0.0.0.0 hs01.stuff.net
FFFFFFFF 0.0.0.0 hs01.evenmorestuff.net
GGGGGGGG 0.0.0.0 hs01.stuff.net
HHHHHHHH 0.0.0.0 hs01.evenmorestuff.net
This is the result of the ORDER BY:
AAAAAAAA 0.0.0.0 hs01.stuff.net
BBBBBBBB 0.0.0.0 hs01.morestuff.net
CCCCCCCC 0.0.0.0 hs01.evenmorestuff.net
DDDDDDDD 0.0.0.0 hs01.stuff.net
EEEEEEEE 0.0.0.0 hs01.stuff.net
FFFFFFFF 0.0.0.0 hs01.evenmorestuff.net
GGGGGGGG 0.0.0.0 hs01.stuff.net
HHHHHHHH 0.0.0.0 hs01.evenmorestuff.net
THE SAME OUTPUT, so something went wrong.
This is what I have tried thus far
$dbh_source2 = DBI->
connect("dbi:Oracle:host=????;port=????;sid=????",'????','????');
$SEL = "SELECT DISTINCT
PE_LOOPBACK_IP,
PE_FQDN
FROM TABLE_NAME
WHERE SITE_NAME = ?
ORDER BY PE_FQDN";
$sth = $dbh_source2->prepare($SEL);
This does not work and does not sort the last column by the name. Does ORDER BY only sort based on the first character? Are the numbers that are within the name causing it to fail?
Here is the code that I use to display the data:
print '<table border=1>';
print '<tr>';
print '<th>Tower name</th>';
print '<th>SUR IP</th>';
print '<th>SUR FQDN</th>';
print '</tr>';
foreach my $data_line (@raw_data) {
chomp $data_line;
$sth->execute($data_line);
while (my @row = $sth->fetchrow_array ) {
#Print data into cells#
print "<tr>";
print "<td>$data_line</td>";
foreach (@row) {
print "<td>$_</td>";
}
print "</tr>";
#print "<$data_line>\t @row\n";
}
}
print "</table>";
Looks like your SQL is doing exactly what you’re asking it to. You execute your statement eight times. Each time the result set contains only one row, so the the sort does nothing.
You have two options. You can either change your SQL so that you do one select which returns all of the rows that you want sorted how you want it. Or you keep your existing SQL but store the data returned from each execution in an array and sort that array before displaying the results.