Home » Developer & Programmer » Precompilers, OCI & OCCI » Returning value from a select count() statement
Returning value from a select count() statement [message #231322] |
Mon, 16 April 2007 09:08 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
clancypc
Messages: 36 Registered: December 2006
|
Member |
|
|
I am trying to find the number of rows that will be returned by a query, so I have tried the code below, however the value is always returned as zero, when I know that there is a record in the database. Any ideas on what I am doing wrong?
strcpy(QueryString, "SELECT count(*) FROM ACC_INF WHERE acc_number = ':AccNum'\0");
/* Attach sql statement to statement handle */
TRACE(("1102: Preparing statement handle\n"));
OCIStmtPrepare( OraStmntHandlePtr,
OraErrorHandlePtr,
&QueryString,
strlen(QueryString),
OCI_NTV_SYNTAX,
OCI_DEFAULT );
/* Bind the input variable */
TRACE(("1103: Binding the input variable\n"));
RtrnValue = OCIBindByName( OraStmntHandlePtr,
&OraBindAccNumPtr,
OraErrorHandlePtr,
":AccNum",
-1,
AccRec->AccNum,
sizeof(AccRec->AccNum),
SQLT_STR,
NULL, NULL, NULL, NULL, NULL,
OCI_DEFAULT);
/* Define output variable */
RtrnValue = OCIDefineByPos( OraStmntHandlePtr,
&OraDefPtr[0],
OraErrorHandlePtr,
1,
&NumRecords, /* destination variable */
sizeof(NumRecords),
SQLT_INT,
(dvoid *) 0, (ub2 *) 0, (ub2 *) 0, OCI_DEFAULT);
if ( RtrnValue != 0 )
checkerr( OraErrorHandlePtr, RtrnValue);
/* Execute statement */
TRACE(("1104: Executing the statement\n"));
RtrnValue = OCIStmtExecute(OraServiceContextHandlePtr,
OraStmntHandlePtr,
OraErrorHandlePtr,
1, /* fetch first row */
0,
NULL,
NULL,
OCI_DEFAULT);
if ( RtrnValue != 0 )
checkerr( OraErrorHandlePtr, RtrnValue);
Thanks,
Peter
|
|
|
|
Goto Forum:
Current Time: Fri Feb 07 11:23:30 CST 2025
|