简体   繁体   English

Oracle数据库在C#中使用devart从存储过程返回错误的行

[英]Oracle database returns faulty rows from stored procedure using devart in C#

I have an oracle database with a stored procedure: 我有一个带有存储过程的oracle数据库:

PROCEDURE "CalculateChats"
  (
    "In_Conf" IN NUMBER,
    "In_From" IN TIMESTAMP,
    "In_To" IN TIMESTAMP,
    "Out_Cursor" OUT "Cursor"
  ) AS
  BEGIN
  OPEN "Out_Cursor" FOR
  SELECT 
  TO_TIMESTAMP(SUBSTR("Started", 0, 13), 'yyyy-mm-dd hh24:MI' ) as "From", 
  CAST(TO_TIMESTAMP(SUBSTR("Started", 0, 13), 'yyyy-mm-dd hh24:MI') + 1/24 AS TIMESTAMP) as "To", 
  COUNT(*) as "Chats"
  FROM "SomeTableContainingChats" 
  WHERE "Conf" = "In_Conf" 
  AND "Started" >= "In_From"
  AND "Started" <= "In_To" 
  GROUP BY SUBSTR("Started", 0, 13) 
  ORDER BY SUBSTR("Started", 0, 13) ASC;
  END "CalulateChats";

When run, the stored procedure gives me a table [ From | 运行时,存储过程为我提供了一个表[From | To | 到| NrOfOfferedChats ] The dates are correct compared to the values. NrOfOfferedChats]日期与值相比是正确的。

(Example) (例)

[ From                         | To                            | Chats ]
2014-09-15 08:00:00,000000000   2014-09-15 09:00:00,000000000   61
2014-09-15 09:00:00,000000000   2014-09-15 10:00:00,000000000   96
2014-09-15 10:00:00,000000000   2014-09-15 11:00:00,000000000   113
2014-09-15 11:00:00,000000000   2014-09-15 12:00:00,000000000   80

Now i pick it up from the C# code: 现在,我从C#代码中进行选择:

 using (var oraclePackage = new OraclePackage())
        {
            oraclePackage.Connection = DbConnection;
            oraclePackage.PackageName = @"CHAOS.""HiddenPackageName""";

            oraclePackage.Parameters.AddWithValue("In_Conf", conf);
            oraclePackage.Parameters.AddWithValue("In_From", from);
            oraclePackage.Parameters.AddWithValue("In_To", to);
            oraclePackage.Parameters.AddWithValue("Out_Cursor", null).Direction = ParameterDirection.Output;
            oraclePackage.Parameters["Out_Cursor"].OracleDbType = OracleDbType.Cursor;

            oraclePackage.ExecuteProcedure(@"""CalculateChats""", oraclePackage.Parameters, true);

            using (OracleDataReader oracleReader = ((OracleCursor)oraclePackage.Parameters["Out_Cursor"].Value).GetDataReader())
            {
                if (oracleReader.HasRows)
                {
                    while (oracleReader.Read())
                    {
                       oracleReader;
                    }
                }
            }
        }

And the data from the oracle is oracleReader = From: 0015-09-14 01:00:00,000000000, To: 0015-09-14 02:00:00,000000000, Chats: 80 来自oracle的数据是oracleReader = From:0015-09-14 01:00:00,000000000,To:0015-09-14 02:00:00,000000000,Chats:80

Now for the question: What could be a possible cause for the alteration from the database to the C# code, and any suggestion on how to solve it would be apreciated. 现在要解决的问题是:从数据库到C#代码的更改可能是什么原因,并且对如何解决它的任何建议都将不胜感激。

After throwing this arround for 2 days i found out 扔了2天后,我发现了

CAST(TO_TIMESTAMP(SUBSTR("Started", 0, 13), 'yyyy-mm-dd hh24:MI') + 1/24 AS TIMESTAMP)

Was converting the timestamp from 2014-09-16 08:00:00 to 16-SEP-14 02:00:00 i'm still not aware why it was converted that way but: 正在将时间戳从2014-09-16 08:00:00转换为16-SEP-14 02:00:00我仍然不知道为什么将其转换为这种方式,但是:

CAST(TO_CHAR("Started", 'YYYY-MM-dd HH24') || ':00:00' AS TIMESTAMP)

Seemed to solve the problem. 似乎解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM