我有一个带有存储过程的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";
运行时,存储过程给我一个表[From |到| NrOfOfferedChats] 与值相比,日期是正确的。
(实施例)
[ 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
现在我从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;
}
}
}
}
来自oracle的数据是oracleReader = From:0015-09-14 01:00:00,000000000,To:0015-09-14 02:00:00,000000000,Chats:80
现在提出一个问题:从数据库到C#代码的更改可能是什么原因,任何关于如何解决它的建议都会被贬低。
答案 0 :(得分:0)
投掷这个周围2天后我发现了
CAST(TO_TIMESTAMP(SUBSTR("Started", 0, 13), 'yyyy-mm-dd hh24:MI') + 1/24 AS TIMESTAMP)
将时间戳从2014-09-16 08:00:00转换为16-SEP-14 02:00:00我仍然不知道为什么会这样转换,但是:
CAST(TO_CHAR("Started", 'YYYY-MM-dd HH24') || ':00:00' AS TIMESTAMP)
似乎解决了这个问题。