Home » SQL & PL/SQL » SQL & PL/SQL » How to get integer portion from a decimal (4 Megred)
How to get integer portion from a decimal (4 Megred) [message #544448] Tue, 21 February 2012 20:21 Go to next message
VINORACLE
Messages: 14
Registered: September 2011
Location: Calgary
Junior Member
Hi friends,
I hope you will be abale to help me on this as in the previous occations.

Using Oracle SQL Developer 2.1.1.64 to run the queries & Oracle 11g.

I have two numbers in two colomns of an oracle table(colomn a & colomn b). I am trying to divide colomn a/colomn b and putting the results in colomn c & also in colomn d (all in the same table) using update commands

Eg: UPDATE MTOTABLE_PWELD pw SET pw.WELDO=(pw.pipe_length/12000);

But here is the real issue. In colomn d I only need the integer portion of the division value.

For example , when I divide colomn a/colomn b , let us assume that we are getting a value of 2.56. Then I want the value of 2 to go to colomn d.

I tried round((colomn a/colomn b),0). But it rounds off 2.56 to 3.
I dont want that. I need the exact integer portion of the value to be seperated.

Pl help

Regards,

Vinod
Re: How to get integer portion from a decimal [message #544452 is a reply to message #544448] Tue, 21 February 2012 20:34 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>UPDATE MTOTABLE_PWELD pw SET pw.WELDO=(pw.pipe_length/12000);

not as above but as below

UPDATE MTOTABLE_PWELD pw SET pw.WELDO=((pw.pipe_length-mod(pw.pipe_length,12000))/12000);

it is a bad & dangerous practice to store a computed value in a column of static table

[Updated on: Tue, 21 February 2012 20:35]

Report message to a moderator

Re: How to get integer portion from a decimal [message #544454 is a reply to message #544452] Tue, 21 February 2012 22:25 Go to previous message
Barbara Boehmer
Messages: 9106
Registered: November 2002
Location: California, USA
Senior Member
SCOTT@orcl_11gR2> CREATE TABLE mtotable_pweld
  2    (pipe_length  NUMBER,
  3  	b	     NUMBER,
  4  	weldo	     NUMBER)
  5  /

Table created.

SCOTT@orcl_11gR2> INSERT INTO mtotable_pweld VALUES (30720, 12000, NULL)
  2  /

1 row created.

SCOTT@orcl_11gR2> SELECT * FROM mtotable_pweld
  2  /

PIPE_LENGTH          B      WELDO
----------- ---------- ----------
      30720      12000

1 row selected.

SCOTT@orcl_11gR2> UPDATE mtotable_pweld
  2  SET    weldo = TRUNC (pipe_length / b)
  3  /

1 row updated.

SCOTT@orcl_11gR2> SELECT * FROM mtotable_pweld
  2  /

PIPE_LENGTH          B      WELDO
----------- ---------- ----------
      30720      12000          2

1 row selected.

SCOTT@orcl_11gR2>

Previous Topic: UTL_FILE Package Issues
Next Topic: Usage of cursors in stored procedure
Goto Forum:
  


Current Time: Thu Jul 24 13:48:38 CDT 2025