简体   繁体   中英

bulk write in an Oracle database with OCCI c++

I am new to oracle database with occi.

I want to know how can i insert multiple row at single time with occi in my c++ code?

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.

It seems like you're looking for 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.

In this case, you should not call setMaxIterations() and 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. The arrayLength parameter specifies the number of elements provided in each buffer. Essentially, this is same as setting the number of iterations to arrayLength and executing the statement.

See Oracle's documentation for more details - https://docs.oracle.com/cd/E24693_01/appdev.11203/e10764/performance.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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