Oracle: Bulk Insert multiple records with an INSERT statement ____oracle

Source: Internet
Author: User
Tags bulk insert

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



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.