Skip to content

Instantly share code, notes, and snippets.

@carloscasalar
Last active August 23, 2018 07:01
Show Gist options
  • Save carloscasalar/77d2359c067283b7628b to your computer and use it in GitHub Desktop.
Save carloscasalar/77d2359c067283b7628b to your computer and use it in GitHub Desktop.
Oracle tips

Oracle Tips

Profiling

Dates and queries

Number of day of the week

Being 1 for monday to 7 for sunday.

select 1 + trunc(sysdate) - trunc(sysdate, 'IW') from dual;

Last 12 mondays

select trunc(next_day((sysdate - 7 * (12 - rownum + 1)), 'MON'))
from dual
connect by level <= 12
order by 1 desc

Tricks

Select from dual with 10 rows.

SELECT ROWNUM FROM DUAL CONNECT BY LEVEL <=10 ORDER BY 1 ASC;

Timestamp expression

Filter a timestamp column without use of TO_TIMESTAMP:

SELECT foo
FROM   bar
WHERE  date_created = TIMESTAMP '2018-02-26 00:00:00.000000'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment