Home » Developer & Programmer » Precompilers, OCI & OCCI » OCI Query (merged)
OCI Query (merged) [message #391437] |
Thu, 12 March 2009 04:47 |
vaishali.verma18
Messages: 6 Registered: March 2009
|
Junior Member |
|
|
Can anybody give me the sample code in OCI in C for receiving records of table in array of structure?
Or dynamically storing the resultset in an array..using array of pointers to structure...
Or any other help is invited
|
|
|
|
|
|
Re: OCI Query [message #391449 is a reply to message #391447] |
Thu, 12 March 2009 05:11 |
|
Michel Cadot
Messages: 68716 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Guide contains code.
You can also go to otn.oracle.com which contain many code examples.
And you should be more polite, if you want help.
Regards
Michel
[Updated on: Thu, 12 March 2009 05:11] Report message to a moderator
|
|
|
|
Re: OCI Query (merged) [message #391454 is a reply to message #391437] |
Thu, 12 March 2009 05:25 |
vaishali.verma18
Messages: 6 Registered: March 2009
|
Junior Member |
|
|
please look at the approach I am going with...M unable to understand y the statement is not getting executed...I am new to OCI..Plz help me..
typedef struct structEmployeeTab_t
{
int empno;
char ename[20];
char job[20];
int sal;
int deptno;
}EmployeeTab_t;
S32 oci_allocate_memory()
{
int i;
printf("Inside oci_allocate_memory\n");
for(i=0;i<NO_OF_ROWS;i++)
{
EmployeeTab_p[i]=(EmployeeTab_t *)malloc(sizeof(EmployeeTab_t));
if (NULL == EmployeeTab_p [i])
{
printf("Error in Initializing Memory for Employee Table Structure \n");
return UTIL_FAILURE;
break;
}
else
{
//printf("Memory Allocation for Employee Table Structure SUCCESS!!!\n");
}
}
return UTIL_SUCCESS;
}
void oci_define(OciHandle_t *ctxptr)
{
int i;
static int j=1;
printf("Inside oci_define\n");
for(i=1;i<=NoOfRows;i++)
{
checkerr(ctxptr->errhp,status=OCIDefineByPos(ctxptr->stmthp, &ctxptr->dfnhp, ctxptr->errhp,j, &EmployeeTab_p[i]->empno,sizeof(EmployeeTab_p[i]), SQLT_INT, NULL, NULL,NULL, OCI_DEFAULT));
j++;
/* checkerr(ctxptr->errhp,status= OCIDefineByPos(ctxptr->stmthp, &ctxptr->dfnhp, ctxptr->errhp, j, (dvoid *) &EmployeeTab_p[i]->ename,(sb4)sizeof(EmployeeTab_p[i]), SQLT_STR, (dvoid *) 0, (ub2 *)0,
(ub2 *)0, OCI_DEFAULT));
j++;
checkerr(ctxptr->errhp,status= OCIDefineByPos(ctxptr->stmthp, &ctxptr->dfnhp,ctxptr->errhp, j, (dvoid *) &EmployeeTab_p[i]->job,(sb4)sizeof(EmployeeTab_p[i]), SQLT_STR, (dvoid *) 0, (ub2 *)0,
(ub2 *)0, OCI_DEFAULT));
j++;*/
checkerr(ctxptr->errhp,status=OCIDefineByPos(ctxptr->stmthp, &ctxptr->dfnhp, ctxptr->errhp,j, &EmployeeTab_p[i]->sal,sizeof(EmployeeTab_p[i]), SQLT_INT, NULL, NULL,NULL, OCI_DEFAULT));
j++;
checkerr(ctxptr->errhp,status=OCIDefineByPos(ctxptr->stmthp, &ctxptr->dfnhp, ctxptr->errhp,j, &EmployeeTab_p[i]->deptno,sizeof(EmployeeTab_p[i]), SQLT_INT, NULL, NULL,NULL, OCI_DEFAULT));
j++;
//}
checkerr(ctxptr->errhp,status=OCIDefineArrayOfStruct(ctxptr->dfnhp,ctxptr->errhp,(ub4)sizeof(EmployeeTab_t), 0, 0, 0));
}
S32 oci_execute_statement(OciHandle_t *ctxptr)
{
S32 iter = UTIL_FALSE;
S32 count = 1;
S32 noOfRows;
printf("Executing OCIStmtExecute\n");
checkerr(ctxptr->errhp, status=OCIStmtExecute(ctxptr->svchp,ctxptr->stmthp,ctxptr->errhp, (ub4) count, (ub4) iter, (CONST OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_COMMIT_ON_SUCCESS));
}
Logs:
Inside oci_allocate_memory
oci_Init SUCCESS 0
Inside oci_connect
OCILogon SUCCESS!!!
oci_connect SUCCESS
query to be executed select empno,sal,deptno from empo
Executing OCIStmtPrepare
OCIStmtPrepare SUCCESS!!!
Inside oci_define
Executing OCIStmtExecute
Error - ORA-01007: variable not in select list
OCIStmtExecute FAILED!!!
Inside oci_fetch_rows
|
|
|
Goto Forum:
Current Time: Tue Nov 26 21:17:43 CST 2024
|