开发者

Can a field data type change from row to row when using OracleDatareader

开发者 https://www.devze.com 2023-02-08 00:37 出处:网络
When using OracleDataReader (Oracle.DataAccess.Client) in a c# program to read data from a recordset are there any situations where the data type in one of the fields could change from row to row ( ex

When using OracleDataReader (Oracle.DataAccess.Client) in a c# program to read data from a recordset are there any situations where the data type in one of the fields could change from row to row ( except DBNull ).

I am thinking of situations like wh开发者_如何学运维ere the select uses a case statement that can return either a value from a column that is a number(9) or a value from a column that is defined as a number(14).

Are there any other gotcha's that might be relevant when up casting the value returned when using the indexer on the data reader e.g. int cityId = (int)dataReader["CityId"]; (except handling DBNull)


AFAIK, data type doesn't change on a row by row basis.

If the query uses a case statement that returns values from different data-types, the engine is responsible to pick the most appropriate to hold values for all, and it will describe the result-set using that data type, as the standard forces to use one data type per column in any result set.

Anyway, if you can't trust/know the source of the query, surround your cast in a try/catch sentence to get any unexpected result and act accordingly.


Each column in the result set will have the same data type and length/size/precision. JDBC connections

Using JDBC, these can actually be obtained from the result set metadata. Not sure whether there is an equivalent for C#

One oddity is a very special user defined type called SYS.ANYTYPE which is mostly used internally for replication. You can have three rows in a result set with one column. The data type of the column would be SYS.ANYTYPE but internally one could have a date value while another has a number and the last has a character. There are special packages for determining what is hidden inside any ANYTYPE value.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号