简体   繁体   English

使用 OCCI C++ 批量写入 Oracle 数据库

[英]bulk write in an Oracle database with OCCI c++

I am new to oracle database with occi.我是 occi 的 oracle 数据库的新手。

I want to know how can i insert multiple row at single time with occi in my c++ code?我想知道如何在我的 C++ 代码中使用 occi 一次插入多行?

int createStatement(Connection* i_pDBConn)
    {
        int retVal = SUCCESS;

        try
        {
            m_pDBStmt = i_pDBConn->createStatement("INSERT INTO RATED_EVENT_EPM VALUES (:1, :2, :3, :4, :5)");
        }
        catch(SQLException& ex)
        {
            cout<<__FILE__<<":"<<__LINE__<<" "<<ex.getMessage()<<endl;
            retVal = FAILURE;
            return retVal;
        }

        m_pDBStmt->setMaxIterations(1000);
        m_pDBStmt->setMaxParamSize(1, 10);

        return retVal;
    }


    int insertRatedEventDetailInDB(Connection* i_pDBConn, string i_string)
    {
        int retVal = SUCCESS;

        try
        {
            m_pDBStmt->setString(1, i_string);

            if((0 != m_pDBStmt->getCurrentIteration()) && 0 == (m_pDBStmt->getCurrentIteration()%1000))
            {
                m_pDBStmt->executeUpdate();
                i_pDBConn->commit();
            }
            else
            {
                m_pDBStmt->addIteration();
            }
        }
        catch(SQLException& ex)
        {
            cout<<__FILE__<<":"<<__LINE__<<" "<<ex.getMessage()<<endl;
            retVal = FAILURE;
        }

        return retVal;
    }

so after created statement single time and then call "insertRatedEventDetailInDB" function multiple time to multiple insert row and need to execute after every 1000 time.所以在创建语句单次之后,然后多次调用“insertRatedEventDetailInDB”函数来多次插入行,并且需要每1000次执行一次。

It seems like you're looking for executeArrayUpdate():看起来您正在寻找 executeArrayUpdate():

If all data is provided with the setDataBuffer() methods or output streams (that is, no setxxx() methods besides setDataBuffer() or getStream() are called), then there is a simplified way of doing iterative execution.如果所有数据都通过 setDataBuffer() 方法或输出流提供(即,除了 setDataBuffer() 或 getStream() 之外没有 setxxx() 方法被调用),那么有一种简化的迭代执行方式。

In this case, you should not call setMaxIterations() and setMaxParamSize().在这种情况下,您不应调用 setMaxIterations() 和 setMaxParamSize()。 Instead, call the setDataBuffer() or getStream() method for each parameter with the appropriate size arrays to provide data for each iteration, followed by the executeArrayUpdate(int arrayLength) method.相反,使用适当大小的数组为每个参数调用 setDataBuffer() 或 getStream() 方法以为每次迭代提供数据,然后是 executeArrayUpdate(int arrayLength) 方法。 The arrayLength parameter specifies the number of elements provided in each buffer. arrayLength 参数指定每个缓冲区中提供的元素数。 Essentially, this is same as setting the number of iterations to arrayLength and executing the statement.本质上,这与将迭代次数设置为 arrayLength 并执行语句相同。

See Oracle's documentation for more details - https://docs.oracle.com/cd/E24693_01/appdev.11203/e10764/performance.htm有关更多详细信息,请参阅 Oracle 文档 - https://docs.oracle.com/cd/E24693_01/appdev.11203/e10764/performance.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM