Why am I getting “Data conversion or data mapping error. SQLCODE=-802” on a simple DB2 select statement?

跟風遠走 提交于 2020-01-03 16:49:28

问题


I am accessing DB2 information on an IBM i (AS400) with PHP.

With this code:

$query = "SELECT * FROM QS36F.MYTABLE WHERE MYFIELD=120006";
$result = db2_prepare($conn, $query);
db2_execute($result);

$i=0;
while($row = db2_fetch_assoc($result) or die(db2_stmt_errormsg())){
    $i++;
    print "Row " . $i . " successful<br />";
}

I get:

SELECT * FROM QS36F.MYTABLE WHERE MYFIELD=120006

Row 1 successful
Row 2 successful
Row 3 successful
Row 4 successful
Data conversion or data mapping error. SQLCODE=-802

There should be more than 4 results. Why might this error be occurring?

More details:

  • This same error seems to happen on any value I search for in MYFIELD although it may be after a different number of successful results
  • MYFIELD is NUMERIC(7,0)
  • I can search other fields in the table(including numeric ones) and it works fine.

回答1:


There was invalid decimal data in the table. There were blanks instead of zeros. I moved zeros into those blanks and that fixed the problem




回答2:


If it can help someone else, I had the same error and found out I was making a join between mismatching data types: a DECIMAL(2,0) field and a VARCHAR(5) field. Till we have VARCHARs that can be converted into DECIMAL(2,0) it can work, otherwise it throws the error.




回答3:


According to the documentation, SQL0802 is arithmetic overflow. More than likely one of the rows has a data value that is too big for the php variable that you have declared for it, although I can't see that in the code you've posted. Or else there is some other funny data conversion not happening properly, for example if the QS36F.MYTABLE object is actually a view that is selecting from another table, and is converting one of the columns.



来源:https://stackoverflow.com/questions/5009180/why-am-i-getting-data-conversion-or-data-mapping-error-sqlcode-802-on-a-simp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!