I have an oracle database with a stored procedure:
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 | To | NrOfOfferedChats ] The dates are correct compared to the values.
(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:
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
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.
After throwing this arround for 2 days i found out
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:
CAST(TO_CHAR("Started", 'YYYY-MM-dd HH24') || ':00:00' AS TIMESTAMP)
Seemed to solve the problem.