Oracle 12.2.0.1 keeps throwing ORA-01406
Posted: 02.09.2019, 18:53
An other day, an other interesting error. I connected my application to an Oracle server with the client version number in the subject. When I'm trying to select data from a table, an ORA-01406 exception is thrown every second or so. My code is like the following:
Procedure TForm1.ExecuteButtonClick(Sender: TObject);
Begin
Try
SQLQuery.SQL.Text := 'SELECT Note FROM MYTABLE';
SQLQuery.Open;
Except
On E:Exception Do ShowMessage(E.Message);
End;
End;
If I change the ClientCodePage from UTF-8 to nothing, the error is not thrown (but characters are displayed incorrectly ofc). I managed to find the record where the problem appeared (increasing "WHERE ROWNUM < x") but when I'm selecting only that one record, it shows up without errors.
The field is a status-like field and I can see other records having the exact same status displaying correctly.
The exception is thrown in CheckOracleError procedure, ZDbcOracleUtils.pas at line 1158.
SQLMonitor shows:
[2019.09.02 18:11:58.402] SQL trace: 2019-09-02 18:11:58 cat: Prepare, proto: oracle-9i, msg: Statement 3 : select note from mytable
[2019.09.02 18:11:58.452] SQL trace: 2019-09-02 18:11:58 cat: Execute prepared, proto: oracle-9i, msg: Statement 3
[2019.09.02 18:11:58.459] SQL trace: 2019-09-02 18:11:58 cat: Prepare, proto: oracle-9i, msg: Statement 4 : SELECT OWNER, TABLE_NAME, COLUMN_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE, DATA_DEFAULT, COLUMN_ID FROM SYS.ALL_TAB_COLUMNS Where TABLE_NAME like 'MYTABLE' order by COLUMN_ID
[2019.09.02 18:11:58.474] SQL trace: 2019-09-02 18:11:58 cat: Execute prepared, proto: oracle-9i, msg: Statement 4
[2019.09.02 18:12:02.400] SQL trace: 2019-09-02 18:12:02 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:04.616] SQL trace: 2019-09-02 18:12:04 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:08.933] Tab 0, TESTORACLE: EZSQLException was raised with the message: SQL Error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:09.098] SQL trace: 2019-09-02 18:12:09 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:22.732] SQL trace: 2019-09-02 18:12:22 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:24.601] SQL trace: 2019-09-02 18:12:24 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:27.174] SQL trace: 2019-09-02 18:12:27 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:30.706] SQL trace: 2019-09-02 18:12:30 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:31.929] SQL trace: 2019-09-02 18:12:31 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:34.298] SQL trace: 2019-09-02 18:12:34 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:35.396] SQL trace: 2019-09-02 18:12:35 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:38.098] SQL trace: 2019-09-02 18:12:38 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:39.220] SQL trace: 2019-09-02 18:12:39 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:42.221] SQL trace: 2019-09-02 18:12:42 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:44.119] SQL trace: 2019-09-02 18:12:44 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:47.928] SQL trace: 2019-09-02 18:12:47 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:52.839] SQL trace: 2019-09-02 18:12:52 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:59.194] SQL trace: 2019-09-02 18:12:59 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:01.148] SQL trace: 2019-09-02 18:13:01 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:05.535] SQL trace: 2019-09-02 18:13:05 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:06.477] SQL trace: 2019-09-02 18:13:06 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:09.151] SQL trace: 2019-09-02 18:13:09 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:10.761] SQL trace: 2019-09-02 18:13:10 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:14.181] SQL trace: 2019-09-02 18:13:14 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:19.951] SQL trace: 2019-09-02 18:13:19 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:22.850] SQL trace: 2019-09-02 18:13:22 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:23.836] SQL trace: 2019-09-02 18:13:23 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:24.722] SQL trace: 2019-09-02 18:13:24 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:26.557] SQL trace: 2019-09-02 18:13:26 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:30.316] SQL trace: 2019-09-02 18:13:30 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[...]
There are multiple anomalies here:
- There are no cycles in the code, so why the error keeps popping back up? See with bold, my application actually caught the exception once. Is it possible that the error buffer is not cleared out properly?
- Since the record seems to be causing the issue can be selected individually, it must not be an encoding issue. However it works with no codepage selected... can it be a buffer overflow?
- It also worths to mention that if I add "ORDER BY ID" to my command to fetch different rows (Oracle processes WHERE first and then ORDER BY) the magic number is the same (609), which means it only could download 608 records correctly, not depending on the contents.
- Connecting a different Oracle test database the same query executes flawlessly. This can be because of different server versions or different data though.
Unfortunately I will not be able to send an extract from the database as it contains commercial, probably sensitive information and I'd get in trouble for sharing it but I'm happy to do some debugging if someone could point me to a direction.
I'm using Delphi 10.2.3 but since the error is raised in the driver I don't think it's relevant.
Thank you for everyone, who is willing to help finding the culprit
Edit: I forgot, using Zeos 7.2.4 (r5698), reporting as 7.2.5-rc
Edit-edit: Adding SQLQuery.Close; to the exception handler stops the messages from keep popping up. Having data-aware components assigned to the ZQuery component seems to make no difference.
Procedure TForm1.ExecuteButtonClick(Sender: TObject);
Begin
Try
SQLQuery.SQL.Text := 'SELECT Note FROM MYTABLE';
SQLQuery.Open;
Except
On E:Exception Do ShowMessage(E.Message);
End;
End;
If I change the ClientCodePage from UTF-8 to nothing, the error is not thrown (but characters are displayed incorrectly ofc). I managed to find the record where the problem appeared (increasing "WHERE ROWNUM < x") but when I'm selecting only that one record, it shows up without errors.
The field is a status-like field and I can see other records having the exact same status displaying correctly.
The exception is thrown in CheckOracleError procedure, ZDbcOracleUtils.pas at line 1158.
SQLMonitor shows:
[2019.09.02 18:11:58.402] SQL trace: 2019-09-02 18:11:58 cat: Prepare, proto: oracle-9i, msg: Statement 3 : select note from mytable
[2019.09.02 18:11:58.452] SQL trace: 2019-09-02 18:11:58 cat: Execute prepared, proto: oracle-9i, msg: Statement 3
[2019.09.02 18:11:58.459] SQL trace: 2019-09-02 18:11:58 cat: Prepare, proto: oracle-9i, msg: Statement 4 : SELECT OWNER, TABLE_NAME, COLUMN_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE, DATA_DEFAULT, COLUMN_ID FROM SYS.ALL_TAB_COLUMNS Where TABLE_NAME like 'MYTABLE' order by COLUMN_ID
[2019.09.02 18:11:58.474] SQL trace: 2019-09-02 18:11:58 cat: Execute prepared, proto: oracle-9i, msg: Statement 4
[2019.09.02 18:12:02.400] SQL trace: 2019-09-02 18:12:02 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:04.616] SQL trace: 2019-09-02 18:12:04 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:08.933] Tab 0, TESTORACLE: EZSQLException was raised with the message: SQL Error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:09.098] SQL trace: 2019-09-02 18:12:09 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:22.732] SQL trace: 2019-09-02 18:12:22 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:24.601] SQL trace: 2019-09-02 18:12:24 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:27.174] SQL trace: 2019-09-02 18:12:27 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:30.706] SQL trace: 2019-09-02 18:12:30 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:31.929] SQL trace: 2019-09-02 18:12:31 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:34.298] SQL trace: 2019-09-02 18:12:34 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:35.396] SQL trace: 2019-09-02 18:12:35 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:38.098] SQL trace: 2019-09-02 18:12:38 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:39.220] SQL trace: 2019-09-02 18:12:39 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:42.221] SQL trace: 2019-09-02 18:12:42 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:44.119] SQL trace: 2019-09-02 18:12:44 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:47.928] SQL trace: 2019-09-02 18:12:47 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:52.839] SQL trace: 2019-09-02 18:12:52 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:12:59.194] SQL trace: 2019-09-02 18:12:59 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:01.148] SQL trace: 2019-09-02 18:13:01 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:05.535] SQL trace: 2019-09-02 18:13:05 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:06.477] SQL trace: 2019-09-02 18:13:06 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:09.151] SQL trace: 2019-09-02 18:13:09 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:10.761] SQL trace: 2019-09-02 18:13:10 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:14.181] SQL trace: 2019-09-02 18:13:14 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:19.951] SQL trace: 2019-09-02 18:13:19 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:22.850] SQL trace: 2019-09-02 18:13:22 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:23.836] SQL trace: 2019-09-02 18:13:23 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:24.722] SQL trace: 2019-09-02 18:13:24 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:26.557] SQL trace: 2019-09-02 18:13:26 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[2019.09.02 18:13:30.316] SQL trace: 2019-09-02 18:13:30 cat: Other, proto: oracle-9i, msg: FETCH ROW, errcode: 1406, error: OCI_ERROR: ORA-01406: fetched column value was truncated
[...]
There are multiple anomalies here:
- There are no cycles in the code, so why the error keeps popping back up? See with bold, my application actually caught the exception once. Is it possible that the error buffer is not cleared out properly?
- Since the record seems to be causing the issue can be selected individually, it must not be an encoding issue. However it works with no codepage selected... can it be a buffer overflow?
- It also worths to mention that if I add "ORDER BY ID" to my command to fetch different rows (Oracle processes WHERE first and then ORDER BY) the magic number is the same (609), which means it only could download 608 records correctly, not depending on the contents.
- Connecting a different Oracle test database the same query executes flawlessly. This can be because of different server versions or different data though.
Unfortunately I will not be able to send an extract from the database as it contains commercial, probably sensitive information and I'd get in trouble for sharing it but I'm happy to do some debugging if someone could point me to a direction.
I'm using Delphi 10.2.3 but since the error is raised in the driver I don't think it's relevant.
Thank you for everyone, who is willing to help finding the culprit
Edit: I forgot, using Zeos 7.2.4 (r5698), reporting as 7.2.5-rc
Edit-edit: Adding SQLQuery.Close; to the exception handler stops the messages from keep popping up. Having data-aware components assigned to the ZQuery component seems to make no difference.