Oracle generates the full time of the next three days (detailed steps)

Time:2022-5-19

Demand: the x-axis time is the whole point time, which shows the prediction in the next three days (the x-axis shows the whole point time in the next three days), one scale every three hours, and the abscissa has a total of 24 scales

Step 1: take the current time


SELECT SYSDATE FROM DUAL

Step 2: take 24 points


SELECT TO_NUMBER(ROWNUM - 1) AS RN,sysdate FROM DUAL CONNECT BY ROWNUM<25

Step 4: Oracle time addition and subtraction


SELECT SYSDATE + 1/24 FROM DUAL

Sysdate + 1 means time plus one day, and 1 / 24 means time plus one hour;
You can also use numtodsinterval

Oracle date addition and subtraction

Both date and timestamp can be added or subtracted.
You can add year, month, day, hour, minute and second to the current date. There are three methods to operate different time types:(Compatible with Dm7

1. Use the built-in function numtodsinterval to increase hours, minutes and seconds

select sysdate, sysdate+numtodsinterval(30,'hour') from DUAL;-- Add 30 hours
select sysdate, sysdate+numtodsinterval(30,'minute') from DUAL;-- Add 30 minutes
select sysdate, sysdate+numtodsinterval(30,'second') from DUAL;-- Add 30 seconds

2. Add a simple number to increase the number of days

select sysdate, sysdate+3 from DUAL;-- Add 3 days

3. Use the built-in function add_ Months to add years and months

select sysdate, add_ months(sysdate,4) from DUAL;-- Increase by 4 months
select sysdate, add_ months(sysdate,12*4) from DUAL;-- Increase by 4 years

Subtract the current time and add ‘-‘ directly in front of the number.

Dm7 and SQL server can also use the DateAdd (datepart, number, date) function to add and subtract time

The date parameter is a legal date expression. Number is the number of intervals you want to add; This number is positive for future time and negative for past time.

The datepart parameter can be the following values:

  • Year YY, YYYY
  • Quarterly QQ, q
  • Month mm, M
  • Mid year day Dy, y
  • Day DD, D
  • Zhou wk, WW
  • Week DW, w
  • Hour HH
  • Min MI, n
  • Seconds SS, s
  • MS MS
  • Subtle MCS
  • Nanosecond NS

Step 4: judge the time of each scale according to each scale


SELECT to_char(SYSDATE + RN*3/24,'yyyy-mm-dd yyyy-mm-dd hh24:mi:ss') AS aimtime 
FROM(
	SELECT TO_NUMBER(ROWNUM - 1) AS RN,sysdate FROM DUAL CONNECT BY ROWNUM<25
)

Step 5: rounding


SELECT to_char(SYSDATE + RN*3/24,'yyyy-mm-dd hh24')||':00' AS aimtime 
FROM(
	SELECT TO_NUMBER(ROWNUM - 1) AS RN,sysdate FROM DUAL CONNECT BY ROWNUM<25
)

This is the end of this article about the full time of Oracle generation in the next three days (detailed steps). For more information about the full time of Oracle generation, please search the previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!