Search code examples
c++oracleocci

OCCI:ORA-01455: converting column overflows integer datatype


table:

CREATE TABLE STU(ID INT PRIMARY KEY, NAME VARCHAR2(20), AGE INT)
INSERT INTO STU VALUES(1, 'ZJW', 24)
INSERT INTO STU VALUES(2, 'YGL', 25)
INSERT INTO STU VALUES(3, 'ZLY', 24)
INSERT INTO STU VALUES(4, 'LBZ', 22)

cpp code:

int nId;  
string strName;
int nAge;
cout << "ID\t" << "NAME\t" << "AGE" << endl;
while (rs->next() == true)
{
     // get values using the getXXX() methods of Resultset
     nId = rs->getInt(1);
     strName = rs->getString(2);
     nAge = rs->getInt(3);

     cout << nId << "\t" << strName << "\t" << nAge << endl;
}

when i use occi to query data from oracle, i get this error: ORA-01455: converting column overflows integer datatype

my system is centos 64bit,and i know int is 2147483647,and oracle INTEGER is -231) to (231)-1. so why i get this overflow error? tks.


Solution

  • It doesn't matter if your system is 64 bit. If you compiled your program as 32 bit then it will run as 32 bit. getInt function is defined as (32 bit OCCI 12):

    virtual int getInt(unsigned int colIndex)=0;
    

    Integer size in C/C++ can be from 2 to 8 bytes, depending on type of CPU, OS, compiler and if the program is 32-bit or 64-bit. It could be that in your case getInt uses 2 bytes for integer if program is 32 bit and you get this error.

    You could check the size of int in your program by adding this line of code before while loop:

    cout << "Int size: " << sizeof(int) << endl;
    

    Strangely, it seems that there is no function getLong in ResultSet class. Maybe this will work:

    unsigned long nAge=(unsigned long)rs->getNumber(3);