Tuesday, November 29, 2011

Data Types - Oracle Number - Java Integer - Java Long

Java Class Integer
The int data type is a 32-bit signed two's complement integer.
Max Value         The maximum value an int can have:   231-1   (2,147,483,647)
Min Value         The minimum value an int can have:   -231        (-2,147,483,648)

Java Class Long
The long data type is a 64-bit signed two's complement integer. 
Max Value        The maximum value an int can have:    9,223,372,036,854,775,807
Min Value         The minimum value an int can have:   -9,223,372,036,854,775,808 

Oracle Number Datatype
The NUMBER datatype stores fixed and floating-point numbers.
  • Positive numbers in the range 1 x 10-130 to 9.99...9 x 10125  with up to 38 significant digits 
  • Negative numbers in the range -1 x 10-130 to 9.99...99 x 10125 with up to 38 significant digits 
  • Zero 
You specify precision (total number of digits) and scale (number of digits to the right of the decimal point) as:
column_name NUMBER (precision, scale)
AND
NUMBER without Precision & Scale is 38 significant digits.


It is good practice to specify the scale and precision of a fixed-point number column for extra integrity checking on input. Specifying scale and precision does not force all values to a fixed length. If a value exceeds the precision, then Oracle returns an error. If a value exceeds the scale, then Oracle rounds it.

Specify an integer using the following form:
NUMBER(p)
This represents a fixed-point number with precision p and scale 0 and is equivalent to NUMBER(p,0).

Specify a floating-point number using the following form:
NUMBER 
The absence of precision and scale designators specifies the maximum range and precision for an Oracle number.

Below is a table from Oracle® Database Concepts Native Data Types
Input Data Specified As Stored As
7,456,123.89 NUMBER 7456123.89
7,456,123.89 NUMBER(*,1) 7456123.9
7,456,123.89 NUMBER(9) 7456124
7,456,123.89 NUMBER(9,2) 7456123.89
7,456,123.89 NUMBER(9,1) 7456123.9
7,456,123.89 NUMBER(6) (not accepted, exceeds precision)
7,456,123.89 NUMBER(7,-2) 7456100

1 comment:

  1. oracle.jbo.domain.Number num = new oracle.jbo.domain.Number(s.getSequenceNumber());
    setEmployeeId(num.intValue());
    ---- num.intValue() To get the integer value

    ReplyDelete