| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.tools -> How to use array of struct in pro*C
Hi, all:
I read Oracle white paper and some paper on the internet. They said Oracle V8.0.4 supports struct array for insert/query and pointer but I have some problem to implement it (I am using V8.0.4).
E.g.
EXEC SQL BEGIN DECLARE SECTION;
typedef struct TT {
char name[10];
int id } T;
T t1[2];
int *_id;
EXEC SQL END DECLARE SECTION;
void main()
{
_id = malloc(sizeof(int )*2);
int ii;
EXEC SQL SELECT id INTO :_id FROM test; /* suppose test table just has two
rows for id */
/* it doesn't work. error msg: select too many rows. I believe Pro*c still
think *_id = _id (one row) */
strcpy(t1[0].name,"Jordan");
t1[0].id = 12;
strcpy(t1[1].name, "Mason");
t1[1].id = 14;
EXEC SQL INSERT test(name, id) VALUES (:t1);
/* it doesn't compile. Error msg: using array of structs require that the
structs be named */
/* it works following but it is NOT really I want it.*/
for(ii = 0;ii<2;ii++)
{
EXEC SQL INSERT test(name, id) values(:t1[ii]);
}
EXEC SQL SELECT * INTO :t1 FROM TEST;
/* it doesn't compile. Error msg:using array of structs require that the
structs be named */
}
Could I declare point of struct and dynamically allocate this struct and then use it for insert and query?
Thanks in advance!
Kevin Gao Received on Mon Mar 12 2001 - 07:49:47 CST
![]() |
![]() |