I have a date (4/30/2012), an hour (4) and a minute (45). I need to convert that to an Oracle datetime value for comparison in a PLSQL/Oracle SELECT statement. Ideally, there would be a function like this (C# since I know it a little better):
var date = "4/30/2012";
var hour = "4";
var minute = "45";
DateTime myDateTime = convertDateTime(date, hour, minute);
I have a table with three columns to make up the date and time of an event. I have another table that has items that may or may not match based on their start and end dates. In pseudo SQL, here's what I'm trying to do:
SELECT
G.Name,
(SELECT MAX(Cost)
FROM CrappyTable AS C
WHERE G.StartTime < convertDateTime(C.Date, C.Hour, C.Minute)
AND G.EndTime > convertDateTime(C.Date, C.Hour, C.Minute)) as Cost
FROM GoodTable as G
WHERE G.Price < 100.00;
OR "Select name and max cost (from reported cost during a time range) where the price is less than $100."
Is there an existing function that might do something like the above convertDateTime
function?
Concatenate your date and time fields and pass them to TO_DATE (assumes 24 hour clock time):
TO_DATE(date||' '||hour||':'||minute,'MM/DD/YYYY HH24:MI')
This will convert your date/time values to an Oracle DATE type.
Or:
TO_DATE(date, 'MM/DD/YYYY') + hour/24 + minute/1440
来源:https://stackoverflow.com/questions/11404064/how-to-create-a-datetime-from-parts-in-oracle-plsql