Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl Database question?

Status
Not open for further replies.

venkatpavan

Programmer
Feb 18, 2006
42
SG
Hi,

My sample script;

Select A,B,C from Table...doing database connection and getting query results.

If (defined $query_results),

than checking A from database = A from file,B from DB = B from file, than do....something

Else ,Do something else.

In the above script,

Q1: How do I check whether my query results more than one row or only one row or no rows at all.

Q2: How can I assign variables to the query result values,So that I can do above check.

Thanks,
V
 
Thanks for the reply,Below is the part of the script I'm using in PERL,

In this script,Using sql query I'm pulling the values B_ID,B_NUM,B_DT and B_LAST_NAM.

My question is How to read above values from the query and use it in our condition (As shown below),Could you please let me know how can I assign variables for this.



$sql = qq { SELECT
TABLEB.B_ID,
TABLEA.B_NUM,
TO_CHAR (TABLEA.B_DT, ‘YYYY/MM/DD’),
TABLEA.B_LAST_NAM
FROM TABLEB TABLEB, TABLEA TABLEA
WHERE TABLEB.B_ID = $CLIENT_PCN
AND TABLEB.B_ID_CD = ‘04’
AND TABLEB.R_CUST_NUM = 3000
AND TABLEB.B_SYS_ID = TABLEA.B_SYS_ID
AND TABLEB.R_CUST_NUM = TABLEA.R_CUST_NUM
AND TABLEA.GROUP_ID = ‘V’
};
print $sql;

$sth = $dbconnection -> prepare ($sql) || die ("Couldn't prepare SQL query : $!");
$sth -> execute || die ("Couldn't execute SQL query: $!");
$query_results = $sth -> fetchrow_arrayref;


if (defined $query_results) {
$query_results -> [0] and $B_NUM == $HIE_CLIENT and $B_DT == $CLIENT_DOB or $B_DT == $CLIENT_DOB and $B_LAST_NAM = $CLIENT_LNAME;
 
>> Q1: How do I check whether my query results more than one row or only one row or no rows at all.

no row if($#$query_results == -1)
one row if($#$query_results == 0)
more than one row if($#$query_results > 0)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top