Search code examples
c#sqloracle-databasesystem.data.oracleclient

Getting native Oracle column type in schema from MS OracleClient


I am using the deprecated System.Data.OracleClient from Microsoft to perform some remote querying of Oracle tables. I am technically unable to use the Oracle-provided ODP providers, regrettably, for reasons that aren't relevant here.

In performing a query, I would like to get the string representation of the Oracle type for a given column, and am relying on the GetSchemaTable() method of the OraceDataReader to have this information. I'm finding several things that are close, but not what I'm really looking for. This seems almost a ridiculously simple request.

I've tried several things that seemed hopeful, but were red herrings: I found the SchemaTableOptionalColumn.ProviderSpecificDataType column to return the Microsoft provider type name (eg. System.Data.OracleClient.OracleNumber), but all I want is the literal column type as defined in Oracle, eg NVARCHAR or NUMBER. I thought perhaps the ProviderType property, which returns a number, would map to the OracleType enumeration in the provider, but it doesn't. The other hope, DataType really maps more to the corresponding managed type of the column, which isn't what I'm looking for, either.

I thought surely someone has solved this before, but if they have, I've not yet found the right rock under which to look for it :)


Solution

  • Unfortunately I cannot test it, but it sounds like just want this method: OracleDataReader.GetDataTypeName, which gives you the dataType of a specific column of your query result.