OCI-22053: overflow error caused when retreiving valid data inserted using System.Data.OracleClient

博客介绍了使用System.Data.OracleClient插入有效数值(Decimal)后无法用相同客户端检索的示例,指出这可能是Oracle客户端与Microsoft数据提供程序间的按位翻译错误,测试环境为VisualStudio2003、Oracle 9i客户端及服务器,均运行在Windows 2000 SP4上。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

See the following example of how to insert a valid numeric value (a Decimal) using the System.Data.OracleClient that cannot be retreived using the same System.Data.OracleClient.

It is apparently some sort of bit-wise translation error between the Oracle Client and the Microsoft Data Provider.  This test was run with VisualStudio2003 and Oracle 9i Client v9.2.0.4.0 connecting to Oracle Server 9.2.0.4.0, all running on Windows 2000 SP4.



using System;
using System.Data;
using System.Data.OracleClient;

namespace OdpTest
{
    /// <summary>
    /// The following command line application code illustrates haw a value that was inserted
    /// using the System.Data.OracleClient causes an overflow error when retreiving it using
    /// the same System.Data.OracleClient.
    /// </summary>
    public class OverflowTest
    {
        private const string CONNECT_STRING = "USER ID=foo;PASSWORD=bar;DATA SOURCE=foobar";

        [STAThread]
        private static void Main(string[] args)
        {
            using (OracleConnection conn = new OracleConnection(CONNECT_STRING))
            {
                conn.Open();
                try
                {
                    using (OracleCommand createCmd = conn.CreateCommand())
                    {
                        createCmd.CommandText = "create table overflow_test (num NUMBER)";
                        createCmd.ExecuteNonQuery();
                    }

                    using (OracleCommand insertCmd = conn.CreateCommand())
                    {
                        insertCmd.CommandText = "insert into overflow_test (num) values (:a)";
                        OracleParameter p = insertCmd.CreateParameter();
                        p.ParameterName = "a";
                        p.Value = 61M / 3M; // The magic value (there are more than just this one)
                        p.Direction = ParameterDirection.Input;
                        p.DbType = DbType.Decimal;
                        insertCmd.Parameters.Add(p);
                        Console.Error.WriteLine("Storing value: " + p.Value.ToString());
                        insertCmd.ExecuteNonQuery();
                    }

                    using (OracleCommand selectCmd = conn.CreateCommand())
                    {
                        selectCmd.CommandText = "select * from overflow_test";

                        DataTable overflowTest = new DataTable("overflow_test");
                        DataColumn num = new DataColumn("num", typeof (decimal));
                        overflowTest.Columns.Add(num);

                        OracleDataAdapter oda = new OracleDataAdapter(selectCmd);
                        oda.Fill(overflowTest);

                        int i = 0;
                        foreach (DataRow row in overflowTest.Rows)
                        {
                            Console.Error.Write("Row[{0}]:", i);
                            for (int j = 0; j < row.Table.Columns.Count; j++)
                            {
                                Console.Error.Write(" {0}", row[j]);
                            }
                            Console.Error.WriteLine();
                        }
                        i++;
                    }
                }
                finally
                {
                    using (OracleCommand deleteCmd = conn.CreateCommand())
                    {
                        deleteCmd.CommandText = "drop table overflow_test";
                        deleteCmd.ExecuteNonQuery();
                    }
                }
            }
        }
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值