ExecuteScalar returns System.Decimal or System.Double on diff Oracle srvrs
406905Oct 20 2003 — edited Oct 20 2003Hi,
Oracle Data Provider for .NET Developer's Guide states that Oracle type NUMBER maps to .NET type System.Decimal.
In my application I would like to retrieve value from database using simple query and OracleCommand.ExecuteScalar method. The problem is that on one database ExecuteScalar returns a value of type System.Decimal and on the other a value of type System.Double. Table creation script and C# code are shown below.
Since I declared column as NUMBER without any precision or scale, I wonder if there is a setting that specifies default values on Oracle server? If I declare column as NUMBER(38) I get the same result (System.Decimal) on both databases. But I would not like to change table creation scripts.
Oracle.DataAccess.dll (9.2.0.2102)
Database 1 (returns System.Decimal)
Oracle9i Enterprise Edition Release 9.2.0.2.0 - Production
PL/SQL Release 9.2.0.2.0 - Production
CORE 9.2.0.2.0 Production
TNS for Compaq Tru64 UNIX: Version 9.2.0.2.0 - Production
NLSRTL Version 9.2.0.2.0 � Production
Database 2 (returns System.Double)
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
PL/SQL Release 9.2.0.4.0 - Production
CORE 9.2.0.3.0 Production
TNS for Compaq Tru64 UNIX: Version 9.2.0.4.0 - Production
NLSRTL Version 9.2.0.4.0 - Production
Database scripts:
CREATE TABLE TEST_TABLE (ID NUMBER NOT NULL) LOGGING NOCACHE NOPARALLEL;
ALTER TABLE TEST_TABLE ADD (CONSTRAINT PK_TEST_TABLE PRIMARY KEY (ID));
INSERT INTO TEST_TABLE ( ID ) VALUES (1);
COMMIT;
C# code:
using System;
using System.Data;
using Oracle.DataAccess.Client;
namespace TestOracle
{
class MainRun
{
[STAThread]
static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("usage: TestOracle.exe DSN");
return;
}
string dsn = args[0];
OracleConnection connection = null;
OracleCommand cmd = null;
try
{
connection = new OracleConnection(dsn);
connection.Open();
cmd = new OracleCommand();
cmd.CommandText = "SELECT ID FROM TEST_TABLE";
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
object retVal = cmd.ExecuteScalar();
Console.WriteLine(retVal.GetType().FullName);
connection.Close();
}
finally
{
if (cmd != null)
cmd.Dispose();
if (connection != null)
connection.Dispose();
}
}
}
}