Inserts multiple records in bulk with an INSERT statement, with the following example:
First set up such a table T:
Sql> DESC T
Name Null? Type
----------------------------------------- -------- ----------------------------
NUM number
BIN RAW (30)
Program code:
typedef struct RAWTYPE {
unsigned short len;
unsigned char buf[30]; The size of the BUF must be the same size as the Bin field of the table T.
} Rawtype;
EXEC SQL TYPE Rawtype is Varraw (30); Similarly, the size of the Varraw must be the same size as the Bin field of the table T.
void Fun (...)//function
{
...
int wnum[3];
int rnum[3];
Rawtype Wbin[3];
Rawtype Rbin[3];
memcpy (Wbin[0].buf, "123", 3);
Wbin[0].len = 3;
Wnum[0] = 1;
memcpy (Wbin[1].buf, "abcdef", 6);
Wbin[1].len = 6;
WNUM[1] = 2;
memcpy (Wbin[2].buf, "People's Republic of China", 14);
Wbin[2].len = 14;
WNUM[2] = 3;
printf ("\---write:---\ n");
for (n=0; n<3; n++)
{
printf ("wnum[%d] =%d\n", N, Wnum[n]);
printf ("wbin[%d] (len =%d):", N, Wbin[n].len);
for (i=0; i<wbin[n].len; i++)
printf ("%02x", Wbin[n].buf[i]);
printf ("\ n");
}
EXEC SQL INSERT INTO T (NUM, BIN) VALUES (: Wnum,: Wbin);
EXEC SQL COMMIT WORK;
printf ("\ n---read:---\ n");
EXEC SQL Select NUM, BIN into:rnum,: Rbin from T;
for (n=0; n<3; n++)
{
printf ("rnum[%d] =%d\n", N, Rnum[n]);
printf ("rbin[%d] (len =%d):", N, Rbin[n].len);
for (i=0; i<rbin[n].len; i++)
printf ("%02x", Rbin[n].buf[i]);
printf ("\ n");
}
...
}
Run Result:
---write:---
Wnum[0] = 1
Wbin[0] (len = 3): 31 32 33
WNUM[1] = 2
Wbin[1] (len = 6): 61 62 63 64 65 66
WNUM[2] = 3
WBIN[2] (len =): E4 B8 AD E5 8D 8E E4 ba ba E6 B0 E5 85
---read:---
Rnum[0] = 1
Rbin[0] (len = 3): 31 32 33
RNUM[1] = 2
Rbin[1] (len = 6): 61 62 63 64 65 66
RNUM[2] = 3
RBIN[2] (len =): E4 B8 AD E5 8D 8E E4 ba ba E6 B0 E5 85
And look at the records in T:
Sql> SELECT * from T;
NUM BIN
---------- ------------------------------------------------------------
1 313233
2 616263646566
3 e4b8ade58d8ee4babae6b091e585