Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Function to round to the nearest 15
Thanks for everyone's help: Here's my final solution: I had to add 7 to get
the rounding to work correctly.
begin
for x in 1..120 Loop
dbms_output.put_line(to_char(x)|| ' ' ||to_char(floor((x+7)/60)+(.25 *
floor(mod((x+7),60)/15))) );
end loop;
end;
/
-----Original Message-----
Sent: Tuesday, March 26, 2002 7:38 AM
To: Multiple recipients of list ORACLE-L
This is exactly what you need.
SQL> col solution format 990.00
SQL> select
trunc(1/60)+(decode(round(mod(1,60)/15),0,1,round(mod(1,60)/15))*.25)
solution from dual;
0.25
SQL> select
trunc(7/60)+(decode(round(mod(7,60)/15),0,1,round(mod(7,60)/15))*.25)
solution from dual;
0.25
SQL> select
trunc(13/60)+(decode(round(mod(13,60)/15),0,1,round(mod(13,60)/15))*.25)
solution from dual;
0.25
SQL> select
trunc(19/60)+(decode(round(mod(19,60)/15),0,1,round(mod(19,60)/15))*.25)
solution from dual;
0.25
SQL> select
trunc(25/60)+(decode(round(mod(25,60)/15),0,1,round(mod(25,60)/15))*.25)
solution from dual;
0.50
SQL> select
trunc(31/60)+(decode(round(mod(31,60)/15),0,1,round(mod(31,60)/15))*.25)
solution from dual;
0.50
SQL> select
trunc(37/60)+(decode(round(mod(37,60)/15),0,1,round(mod(37,60)/15))*.25)
solution from dual;
0.50
SQL> select
trunc(43/60)+(decode(round(mod(43,60)/15),0,1,round(mod(43,60)/15))*.25)
solution from dual;
0.75
SQL> select
trunc(49/60)+(decode(round(mod(49,60)/15),0,1,round(mod(49,60)/15))*.25)
solution from dual;
0.75
SQL> select
trunc(55/60)+(decode(round(mod(55,60)/15),0,1,round(mod(55,60)/15))*.25)
solution from dual;
1.00
SQL> select
trunc(61/60)+(decode(round(mod(61,60)/15),0,1,round(mod(61,60)/15))*.25)
solution from dual;
1.25
SQL> select
trunc(67/60)+(decode(round(mod(67,60)/15),0,1,round(mod(67,60)/15))*.25)
solution from dual;
1.25
SQL> select
trunc(73/60)+(decode(round(mod(73,60)/15),0,1,round(mod(73,60)/15))*.25)
solution from dual;
1.25
SQL> select
trunc(79/60)+(decode(round(mod(79,60)/15),0,1,round(mod(79,60)/15))*.25)
solution from dual;
1.25
SQL> select
trunc(85/60)+(decode(round(mod(85,60)/15),0,1,round(mod(85,60)/15))*.25)
solution from dual;
1.50
SQL> select
trunc(91/60)+(decode(round(mod(91,60)/15),0,1,round(mod(91,60)/15))*.25)
solution from dual;
1.50
SQL> select
trunc(97/60)+(decode(round(mod(97,60)/15),0,1,round(mod(97,60)/15))*.25)
solution from dual;
1.50
SQL> select
trunc(103/60)+(decode(round(mod(103,60)/15),0,1,round(mod(103,60)/15))*.25)
solution from dual;
1.75
SQL> select
trunc(109/60)+(decode(round(mod(109,60)/15),0,1,round(mod(109,60)/15))*.25)
solution from dual;
1.75
SQL> select
trunc(115/60)+(decode(round(mod(115,60)/15),0,1,round(mod(115,60)/15))*.25)
solution from dual;
2.00
SQL> select
trunc(121/60)+(decode(round(mod(121,60)/15),0,1,round(mod(121,60)/15))*.25)
solution from dual;
2.25
SQL> select
trunc(127/60)+(decode(round(mod(127,60)/15),0,1,round(mod(127,60)/15))*.25)
solution from dual;
2.25
SQL> select
trunc(133/60)+(decode(round(mod(133,60)/15),0,1,round(mod(133,60)/15))*.25)
solution from dual;
2.25
SQL> select
trunc(139/60)+(decode(round(mod(139,60)/15),0,1,round(mod(139,60)/15))*.25)
solution from dual;
2.25
SQL> select
trunc(145/60)+(decode(round(mod(145,60)/15),0,1,round(mod(145,60)/15))*.25)
solution from dual;
2.50
SQL> select
trunc(151/60)+(decode(round(mod(151,60)/15),0,1,round(mod(151,60)/15))*.25)
solution from dual;
2.50
SQL> select
trunc(157/60)+(decode(round(mod(157,60)/15),0,1,round(mod(157,60)/15))*.25)
solution from dual;
2.50
SQL> select
trunc(163/60)+(decode(round(mod(163,60)/15),0,1,round(mod(163,60)/15))*.25)
solution from dual;
2.75
SQL> select
trunc(169/60)+(decode(round(mod(169,60)/15),0,1,round(mod(169,60)/15))*.25)
solution from dual;
2.75
SQL> select
trunc(175/60)+(decode(round(mod(175,60)/15),0,1,round(mod(175,60)/15))*.25)
solution from dual;
3.00
SQL> select
trunc(181/60)+(decode(round(mod(181,60)/15),0,1,round(mod(181,60)/15))*.25)
solution from dual;
3.25
SQL> select
trunc(187/60)+(decode(round(mod(187,60)/15),0,1,round(mod(187,60)/15))*.25)
solution from dual;
3.25
SQL> select
trunc(193/60)+(decode(round(mod(193,60)/15),0,1,round(mod(193,60)/15))*.25)
solution from dual;
3.25
SQL> select
trunc(199/60)+(decode(round(mod(199,60)/15),0,1,round(mod(199,60)/15))*.25)
solution from dual;
3.25
SQL> select
trunc(205/60)+(decode(round(mod(205,60)/15),0,1,round(mod(205,60)/15))*.25)
solution from dual;
3.50
SQL> select
trunc(211/60)+(decode(round(mod(211,60)/15),0,1,round(mod(211,60)/15))*.25)
solution from dual;
3.50
SQL> select
trunc(217/60)+(decode(round(mod(217,60)/15),0,1,round(mod(217,60)/15))*.25)
solution from dual;
3.50
SQL> select
trunc(223/60)+(decode(round(mod(223,60)/15),0,1,round(mod(223,60)/15))*.25)
solution from dual;
3.75
SQL> select
trunc(229/60)+(decode(round(mod(229,60)/15),0,1,round(mod(229,60)/15))*.25)
solution from dual;
3.75
SQL> select
trunc(235/60)+(decode(round(mod(235,60)/15),0,1,round(mod(235,60)/15))*.25)
solution from dual;
4.00
SQL> select
trunc(241/60)+(decode(round(mod(241,60)/15),0,1,round(mod(241,60)/15))*.25)
solution from dual;
4.25
SQL> select
trunc(247/60)+(decode(round(mod(247,60)/15),0,1,round(mod(247,60)/15))*.25)
solution from dual;
4.25
SQL> select
trunc(253/60)+(decode(round(mod(253,60)/15),0,1,round(mod(253,60)/15))*.25)
solution from dual;
4.25
SQL> select
trunc(259/60)+(decode(round(mod(259,60)/15),0,1,round(mod(259,60)/15))*.25)
solution from dual;
4.25
SQL> select
trunc(265/60)+(decode(round(mod(265,60)/15),0,1,round(mod(265,60)/15))*.25)
solution from dual;
4.50
SQL> select
trunc(271/60)+(decode(round(mod(271,60)/15),0,1,round(mod(271,60)/15))*.25)
solution from dual;
4.50
SQL> select
trunc(277/60)+(decode(round(mod(277,60)/15),0,1,round(mod(277,60)/15))*.25)
solution from dual;
4.50
SQL> select
trunc(283/60)+(decode(round(mod(283,60)/15),0,1,round(mod(283,60)/15))*.25)
solution from dual;
4.75
SQL> select
trunc(289/60)+(decode(round(mod(289,60)/15),0,1,round(mod(289,60)/15))*.25)
solution from dual;
4.75
SQL> select
trunc(295/60)+(decode(round(mod(295,60)/15),0,1,round(mod(295,60)/15))*.25)
solution from dual;
5.00
SQL> select
trunc(301/60)+(decode(round(mod(301,60)/15),0,1,round(mod(301,60)/15))*.25)
solution from dual;
5.25
SQL> select
trunc(307/60)+(decode(round(mod(307,60)/15),0,1,round(mod(307,60)/15))*.25)
solution from dual;
5.25
SQL> select
trunc(313/60)+(decode(round(mod(313,60)/15),0,1,round(mod(313,60)/15))*.25)
solution from dual;
5.25
SQL> select
trunc(319/60)+(decode(round(mod(319,60)/15),0,1,round(mod(319,60)/15))*.25)
solution from dual;
5.25
SQL> select
trunc(325/60)+(decode(round(mod(325,60)/15),0,1,round(mod(325,60)/15))*.25)
solution from dual;
5.50
SQL> select
trunc(331/60)+(decode(round(mod(331,60)/15),0,1,round(mod(331,60)/15))*.25)
solution from dual;
5.50
-----Message d'origine----- De: Thompson, Todd [mailto:tthompso_at_bcharrispub.com] Date: lundi 25 mars 2002 16:23 À: Multiple recipients of list ORACLE-L Objet: Function to round to the nearest 15 << Fichier: ATT250969.ATT>> I'm trying to convert a minutes field to hours and fractional hours. I need the fractional hours portion rounded to the nearest quarter hour... any SQL (no PLSQL) suggestions would be helpful. 1=.25 48=.75 90=1.5 95=1.5 98=1.75
--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author: Bernard, Gilbert
INET: Gilbert.Bernard_at_caissedesdepots.fr
Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists --------------------------------------------------------------------To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists --------------------------------------------------------------------To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). Received on Tue Mar 26 2002 - 07:48:22 CST