Home » Developer & Programmer » Precompilers, OCI & OCCI » An error was occured for this query
An error was occured for this query [message #267709] |
Fri, 14 September 2007 06:07 |
abdelkaoui
Messages: 1 Registered: September 2007
|
Junior Member |
|
|
I'm trying to execute this source code, but an error was occured. I can run this code by this query :
char *query = "select nom,prenom from client";
but when I add the condition like this:
char *query = "select nom,prenom from client where code =:c";
there are an error in result
char *query = "select nom,prenom from client where code =:c";
/* Allocate and prepare SQL statement */
rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_sql,
OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0);
rc = OCIStmtPrepare(p_sql, p_err, (OraText *) query,
(ub4) 37, (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT);
// Bind the values for the bind variables
code = 1;
rc = OCIBindByName(p_sql, &p_bnd, p_err, (text *) ":c",
-1, (dvoid *) &code, sizeof(int), SQLT_INT, (dvoid *) 0,
(ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
// Define the select list items
rc = OCIDefineByPos(p_sql, &p_dfn, p_err, 1, (dvoid *) &nom,
(sword) 20, SQLT_STR, (dvoid *) 0, (ub2 *)0,
(ub2 *)0, OCI_DEFAULT);
// Define the select list items
rc = OCIDefineByPos(p_sql, &p_dfn, p_err, 2, (dvoid *) &prenom,
(sword) 20, SQLT_STR, (dvoid *) 0, (ub2 *)0,
(ub2 *)0, OCI_DEFAULT);
// Execute the SQL statment
rc = OCIStmtExecute(p_svc, p_sql, p_err, (ub4) 0, (ub4) 0,
(CONST OCISnapshot *) 0, (OCISnapshot *) 0, OCI_DEFAULT);
if(rc == OCI_SUCCESS)
{
while (rc != OCI_NO_DATA) {/* Fetch the remaining data */
printf("%s %s \n",nom,prenom);
rc = OCIStmtFetch(p_sql, p_err, 1, 0, 0);
}
}
else
{
printf("Une erreur s'est produite dans l'execution de la requete SQL");
}
Best regards
Abdelkaoui
|
|
|
|
|
Goto Forum:
Current Time: Fri Dec 06 23:17:23 CST 2024
|