I am having an issue with the OR statement in my SQL SELECT in perl.
######################### Open File and Split The Data Into An Array ####################################
$input_data_file = '/var/www/html/JG/TG/tower_gather.txt';
open (DAT, $input_data_file)
or die ("Could not open file!");
@raw_data = <DAT>;
close(DAT);
#########################################################################################################
$dbh_source2 = DBI->connect("dbi:Oracle:host=<ip-address>;port=<port-number>;sid=<sid>",'username','password');
$SEL = "SELECT DISTINCT SITE_NAME, SITEID, PE_DOWNLINK_PORT FROM CBHME.SERVICE_TOPOLOGY_VIEW WHERE LOWER(PE_FQDN) = ? OR PE_OSPF_LOOPBACK_IP = ?";
$fqdn = $q->param('PE_FQDN');
$sth = $dbh_source2->prepare($SEL);
print '<table border=1>';
print '<tr>';
print '<th>SUR FQDN</th>';
print '<th>Tower Name</th>';
print '<th>Site ID</th>';
print '<th>SUR Link</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>";
END {
$dbh_source2->disconnect if defined($dbh_source2);
}
~
The error:
[jgearh200@srv01-netops cgi-bin]$ ./tower_gather_script.cgi
DBD::Oracle::st execute failed: called with 1 bind variables when 2 are needed [for Statement "SELECT DISTINCT SITE_NAME, SITEID, PE_DOWNLINK_PORT FROM CBHME.SERVICE_TOPOLOGY_VIEW WHERE LOWER(PE_FQDN) = ? OR PE_OSPF_LOOPBACK_IP = ?" with ParamValues: :p1=undef, :p2=undef] at ./tower_gather_script.cgi line 33.
DBD::Oracle::st fetchrow_array failed: ERROR no statement executing (perhaps you need to call execute first) [for Statement "SELECT DISTINCT SITE_NAME, SITEID, PE_DOWNLINK_PORT FROM CBHME.SERVICE_TOPOLOGY_VIEW WHERE LOWER(PE_FQDN) = ? OR PE_OSPF_LOOPBACK_IP = ?" with ParamValues: :p1=undef, :p2=undef] at ./tower_gather_script.cgi line 35.
<table border=1><tr><th>SUR FQDN</th><th>Tower Name</th><th>Site ID</th><th>SUR Link</th></tr></table>[jgearh200@srv01-netops cgi-bin]$
So what I want it to be able to do:
I have a text area in which a user enters an FQDN or IP address line by line of a device and it goes into the Oracle Database and grabs certain information.
The SELECT statement is trying to grab that information based on what the user inputs (IP or FQDN).
Thank you
DBD::Oracle::st execute failed: called with 1 bind variables when 2 are needed...Well, there you go: you need to bind two variables to the select statement (ie the parts in
$SELwhere there are question marks) instead of just one.