Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

INTERVAL Arithmetic

Frank KulashDec 6 2022 — edited Dec 6 2022

In SQL, multiplying an INTERVAL by a NUMBER produces another INTERVAL. Is there an inverse operation that takes two INTERVALs, and produces a NUMBER, the ratio of the two intervals?
That is, instead of

DECLARE
     x	INTERVAL DAY TO SECOND;
     y	INTERVAL DAY TO SECOND;
     n  NUMBER;
BEGIN
     x := INTERVAL '1' MINUTE;
     n := 1.5;
     y := x * n;
     dbms_output.put_line (y || ' = y');
END;

where I compute y from the values I gave to x and n, how can I compute n from values I give to x and y? Is there an inverse function to NUMTODSINTERVAL in Oracle 18.4.0.0.0?

This post has been answered by Paulzip on Dec 7 2022
Jump to Answer
Comments
Post Details
Added on Dec 6 2022
13 comments
1,056 views