I have 2 tables and, I want to create a join in SQL developer through the date times. Example, first table has a START_DATETIME 3/28/1999 15:38:00 and second table has START_DATETIME 3/28/1999 15:47:00, I want to join by date and hour only. Leaving out the min. How can I trunc the min to create a join between these tables. Please help.
CodePudding user response:
Use the trunc()
function. The Oracle TRUNC function returns a date truncated to a specific unit of measure. In your case, you'll want to use HH, HH12 or HH24 for the hour format.
The syntax will be trunc(a.start_datetime, 'HH24')
.
The Oracle documentation contain a much lengthier explanation about each of the formats you can specify.
CodePudding user response:
One option is to use to_char
function with appropriate format model, e.g.
from tab_1 a join tab_2 b on to_char(a.start_datetime, 'dd.mm.yyyy hh24') =
to_char(b.start_datetime, 'dd.mm.yyyy hh24')