Home » SQL & PL/SQL » SQL & PL/SQL » Extracting the digits after decimal from a float number
Extracting the digits after decimal from a float number [message #1120] Tue, 02 April 2002 19:28 Go to next message
Rajeev Katyal
Messages: 55
Registered: April 2002
Member
Suppose i have following data in my table

marks
-----
100.0056
20.0007
21.8989

what i want is to , extract 0056(infact 56) from first row, 7 from second row and 8989 from 3rd row.
how to go about it.
what funcion can be used
or only substr or instr() funtions can be used for above.
Re: Extracting the digits after decimal from a float number [message #1123 is a reply to message #1120] Tue, 02 April 2002 21:47 Go to previous messageGo to next message
Epe
Messages: 99
Registered: March 2002
Member
Hello,

as far as I know, only substr or instr functions.

epe
Re: Extracting the digits after decimal from a float number [message #1125 is a reply to message #1120] Wed, 03 April 2002 02:28 Go to previous messageGo to next message
D e e p a n k a r
Messages: 9
Registered: October 2001
Junior Member
select
substr('10.007',1,instr('10.007','.')-1)||
replace(substr('10.007',instr('10.007','.')),'0','')from dual
Re: Extracting the digits after decimal from a float number [message #1133 is a reply to message #1120] Wed, 03 April 2002 09:41 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Just for kicks, here's another way not using instr or substring:

sql>select c, to_number(replace(to_char(c - trunc(c)), '.')) dec
  2    from t;
 
        C       DEC
--------- ---------
  21.8989      8989
  20.0007         7
 100.0056        56


I wasn't sure if you needed the to_number conversion, but I threw it in there anyway...
Thanks , Re: Extracting the digits after decimal from a float number [message #1138 is a reply to message #1133] Wed, 03 April 2002 19:13 Go to previous message
Rajeev
Messages: 34
Registered: January 2000
Member
Well i just wanted to say thanks to Todd,Epe for replying.

but not sure whether this message will reach both of them or not

Rajeev
Previous Topic: PLS-00302 for simple update???
Next Topic: subquery and CLOB
Goto Forum:
  


Current Time: Fri May 03 05:18:31 CDT 2024