Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle equivalent to SQL Server DATEPART

Tags:

We need to get the HOUR out of a DATETIME column (expecting values from 0 to 23 to be returned).

Is there an Oracle equivalent of the SQL Server DATEPART function?

like image 643
Raj More Avatar asked May 12 '11 14:05

Raj More


People also ask

Does Datepart work in Oracle?

The function works with a set of two arguments, an input date and the name of the part that has to be extracted from it. However, datepart() function works in SQL Server, Oracle, and Azure SQL databases only.

What is SQL Datepart?

The DATEPART() function returns a specified part of a date. This function returns the result as an integer value.

Is Oracle similar to SQL Server?

In short, both Oracle and SQL Server are powerful RDBMS options. Although there are a number of differences in how they work “under the hood,” they can both be used in roughly equivalent ways. Neither is objectively better than the other, but some situations may be more favorable to a particular choice.


1 Answers

An alternative is the EXTRACT function which is an ANSI standard and also works on other DBMS, but it also requires the use of current_timestamp (also ANSI) instead of sysdate

SELECT extract(hour from current_timestamp) 
FROM dual
like image 172
a_horse_with_no_name Avatar answered Sep 20 '22 18:09

a_horse_with_no_name