Atlas91
Atlas91

Reputation: 5904

How to Convert integer to decimal in oracle

how can i convert a integer to decimal in oracle? Is there any function like TO_CHAR? I need to put this function on a where clause. Thanks

SELECT IDDS,
       ID
FROM   T_TABLEONE
WHERE  CAST(ID as DECIMAL)='1,301131832E19';

Upvotes: 1

Views: 36905

Answers (2)

David Aldridge
David Aldridge

Reputation: 52346

If you apply a function to the column then you can run the risks of:

  1. being unable to use a regular index on that column
  2. obscuring the expected cardinality of the result set, which can cause query optimisation problems.

So it's generally a bad practice, and you'd do better to cast your literal to the same type as the column, in this case using to_number().

However in this case I'm surprised that it's necessary, as Oracle's type conversion in recent releases should be able to cope with comparing an integer column to a number expressed in scientific notation: http://sqlfiddle.com/#!4/336d3/8

Upvotes: 1

Mitch Wheat
Mitch Wheat

Reputation: 300559

Use CAST:

CAST(myInt AS DECIMAL)

Upvotes: 0

Related Questions