[Orclib-users] how to pass a varray of varchar2 to oracle database using ocilib
Open source C and C++ library for accessing Oracle Databases
Brought to you by:
vince_del_paris
|
From: Xun C. <ch...@av...> - 2009-11-09 09:33:58
|
Hi,
I want to call a procedure which take a varray of varchar2 as a in parameter.
As a test, I write the following code to set the data
OCI_Coll * vchars;
OCI_Elem * elem;
OCI_TypeInfo *type;
char s[5][64];
int n;
strcpy(s[0], "2009-01-04 11:22:15");
strcpy(s[1], "2009-03-14 01:12:25");
strcpy(s[2], "2009-04-24 11:42:35");
strcpy(s[3], "2009-05-04 21:52:45");
strcpy(s[4], "2009-06-04 13:32:55");
....
n=5;
type = OCI_TypeInfoGet(conn, "string_array20", OCI_TIF_TYPE);
vchars = OCI_CollCreate(type);
for (i=0; i<n; i++) {
elem = OCI_ElemCreate(type);
OCI_ElemSetColl(elem, vchars);
OCI_ElemSetString(elem, s[i]));
OCI_CollAppend(vchars, elem);
}
where string_array20 is defined by following pl/sql statement:
create type string_array20 is varray(20) of varchar2(64);
Run the code show following message:
Elements are not compatible.
It seems that I should not use OCI_ElemSetString() here. If so, what should I do to pass
such a data type to the database?
Best regards,
Xun
|