oracle批量文件入库,C++ Oracle批量高效入库

尝试往Oracle塞数据,使用的是ocilib;

效率:

100w记录 11.23s

10w记录 1.2s

离开配置谈效率都是扯淡,now 机器配置:

785adb3349e0594deeca3719c75e826c.png

开始解决问题

1.下载相应的库,比如windows 32bit下载 ocilib-4.2.0-windows.zip;

2.解压文件,把

a446748b7e525cb174cd4640f5a9fc97.png添加到自己的工程下;

3. 在需要的地方#include "ocilib.h";

4.over~~~

全部可执行代码:

#include "ocilib.h"

#pragma comment(lib, "ociliba.lib")

#define SIZE_ARRAY 100

#define NB_LOAD    1000

#define SIZE_COL1  20

#define SIZE_COL2  30

#define SIZE_COL3  8

#define NUM_COLS   3

int main(void)

{

OCI_Connection *cn;

OCI_DirPath    *dp;

OCI_TypeInfo   *tbl;

char val1[SIZE_COL1+1];

char val2[SIZE_COL2+1];

char val3[SIZE_COL3+1];

int i = 0, j = 0, nb_rows = SIZE_ARRAY;

boolean res = TRUE;

if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))

return EXIT_FAILURE;

cn  = OCI_ConnectionCreate("db", "user", "pw", OCI_SESSION_DEFAULT);

tbl = OCI_TypeInfoGet(cn, "test_directpath", OCI_TIF_TABLE);

dp  = OCI_DirPathCreate(tbl, NULL, NUM_COLS, nb_rows);

/* optional attributes to set */

OCI_DirPathSetBufferSize(dp, 64000);

OCI_DirPathSetNoLog(dp, TRUE);

OCI_DirPathSetParallel(dp, TRUE);

/* describe the target table */

OCI_DirPathSetColumn(dp, 1, "VAL_INT",  SIZE_COL1, NULL);

OCI_DirPathSetColumn(dp, 2, "VAL_STR",  SIZE_COL2, NULL);

OCI_DirPathSetColumn(dp, 3, "VAL_DATE", SIZE_COL3, "YYYYMMDD");

/* prepare the load */

OCI_DirPathPrepare(dp);

nb_rows = OCI_DirPathGetMaxRows(dp);

for (i = 0; i 

{

OCI_DirPathReset(dp);

for (j = 1; j <= nb_rows; j++)

{

/* fill test values */

sprintf(val1, "%04d", i + (i*100));

sprintf(val2, "value %05d", j + (i*100));;

sprintf(val3, "%04d%02d%02d", (j%23)+1 + 2000, (j%11)+1, (j%23)+1);

OCI_DirPathSetEntry(dp, j, 1, val1, (unsigned int) strlen(val1), TRUE);

OCI_DirPathSetEntry(dp, j, 2, val2, (unsigned int) strlen(val2), TRUE);

OCI_DirPathSetEntry(dp, j, 3, val3, (unsigned int) strlen(val3), TRUE);

}

/* load data to the server */

while (res)

{

int state = OCI_DirPathConvert(dp);

if ((state == OCI_DPR_FULL) || (state == OCI_DPR_COMPLETE))

res = OCI_DirPathLoad(dp);

if (state == OCI_DPR_COMPLETE)

break;

}

}

/* commits changes */

OCI_DirPathFinish(dp);

printf("%04d row(s) loaded\n", OCI_DirPathGetRowCount(dp));

/* free direct path object */

OCI_DirPathFree(dp);

OCI_Cleanup();

return EXIT_SUCCESS;

}

感兴趣的去这里看看

http://vrogier.github.io/ocilib/doc/html/index.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值