问题
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 VARCHAR
s 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