Solved

using sysdate in an Oracle query

Posted on 2014-03-27
3
760 Views
Last Modified: 2014-03-27
Experts,

Does anyone know the syntax in Oracle to find a date?

Examples:
the first day of the current month
The first day of the current week
0
Comment
Question by:morinia
  • 2
3 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 125 total points
ID: 39960061
select trunc(sysdate,'mm') from dual -- first day of month


select trunc(sysdate,'dy') from dual -- first day of week


week start/end is dependent on NLS calendar settings
0
 
LVL 40

Assisted Solution

by:Sharath
Sharath earned 125 total points
ID: 39960074
SELECT TRUNC(SYSDATE, 'MM') First_Day_Of_Month,
         TRUNC(TO_DATE(SYSDATE),'D') First_Day_Of_Week
 FROM dual;
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 39960106
TO_DATE(SYSDATE)

don't do TO_DATE() on SYSDATE, it's already a date

  just put the TRUNC directly against the sysdate result as shown in the first post
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Query 26 64
Not able to drop or recreate an Oracle stored procedure 1 31
Import and exporting Oracle Data with encrypted columns 4 29
Oracle function to insert records? 15 42
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to recover a database from a user managed backup

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question