50

I used oracle dictionary views to find out column differences if any between two schema's. While syncing data type discrepancies I found that both NUMBER and INTEGER data types stored in all_tab_columns/user_tab_columns/dba_tab_columns as NUMBER only so it is difficult to sync data type discrepancies where one schema/column has number datatype and another schema/column has integer data type.

While comparison of schema's it show datatype mismatch. Please suggest if there is any other alternative apart form using dictionary views or if any specific properties from dictionary views can be used to identify if data type is integer.

5
  • 2
    :Number is the built in datatype for oracle while Integer is ANSI datatypes and datatypes from the IBM products SQL/DS and DB2,So Oracle Internally convert Integer to NUMBER(38) .I think the only way to get the actual data type from SELECT DBMS_METADATA.GET_DDL('TABLE', '<table_name>','<schema_name>') AS DDL FROM DUAL; Commented Nov 21, 2012 at 13:59
  • This is the last option I'm thinking as I have only few discrepancies and it will impact performance as well tedious to get column position from different tables.
    – Anand
    Commented Nov 21, 2012 at 17:25
  • Hello Experts,Any other advice please...
    – Anand
    Commented Nov 22, 2012 at 7:00
  • 4
    I got reply from oracle support that integer datatype is deprecated and keyword retained for compatibility. Integer datatype is treated as number(38,0) datatype.
    – Anand
    Commented Nov 23, 2012 at 6:29
  • 1
    The reply from Oracle Support isn't very helpful since INTEGER is still very much in use and, as you have found, reported by utilities such as SQL*Plus DESCRIBE. From my tests it appears that INTEGER is reported where data_type = 'NUMBER', data_precision is null and data_scale = 0, but it would be nice to see that confirmed officially. Commented Apr 19, 2016 at 12:43

3 Answers 3

40

the best explanation i've found is this:

What is the difference betwen INTEGER and NUMBER? When should we use NUMBER and when should we use INTEGER? I just wanted to update my comments here...

NUMBER always stores as we entered. Scale is -84 to 127. But INTEGER rounds to whole number. The scale for INTEGER is 0. INTEGER is equivalent to NUMBER(38,0). It means, INTEGER is constrained number. The decimal place will be rounded. But NUMBER is not constrained.

  • INTEGER(12.2) => 12
  • INTEGER(12.5) => 13
  • INTEGER(12.9) => 13
  • INTEGER(12.4) => 12
  • NUMBER(12.2) => 12.2
  • NUMBER(12.5) => 12.5
  • NUMBER(12.9) => 12.9
  • NUMBER(12.4) => 12.4

INTEGER is always slower then NUMBER. Since integer is a number with added constraint. It takes additional CPU cycles to enforce the constraint. I never watched any difference, but there might be a difference when we load several millions of records on the INTEGER column. If we need to ensure that the input is whole numbers, then INTEGER is best option to go. Otherwise, we can stick with NUMBER data type.

Here is the link

2
  • So to return to the OP's question, are you saying the solution is to check for data_scale = 0? From my tests, it appears that data_precision must also be null otherwise DESCRIBE etc show NUMBER. Commented Apr 19, 2016 at 12:40
  • INTEGER is not equivalent to NUMBER(38,0) as INTEGER's range is (-231) to (231)-1 which comes out to -21474836 to 21474835 and these are just 8 digits.
    – Ankit
    Commented Sep 1, 2022 at 4:12
24

Integer is only there for the sql standard ie deprecated by Oracle.

You should use Number instead.

Integers get stored as Number anyway by Oracle behind the scenes.

Most commonly when ints are stored for IDs and such they are defined with no params - so in theory you could look at the scale and precision columns of the metadata views to see of no decimal values can be stored - however 99% of the time this will not help.

As was commented above you could look for number(38,0) columns or similar (ie columns with no decimal points allowed) but this will only tell you which columns cannot take decimals, and not what columns were defined so that INTS can be stored.

Suggestion: do a data profile on the number columns. Something like this:

 select max( case when trunc(column_name,0)=column_name then 0 else 1 end ) as has_dec_vals
 from table_name
11

This is what I got from oracle documentation, but it is for oracle 10g release 2:

When you define a NUMBER variable, you can specify its precision (p) and scale (s) so that it is sufficiently, but not unnecessarily, large. Precision is the number of significant digits. Scale can be positive or negative. Positive scale identifies the number of digits to the right of the decimal point; negative scale identifies the number of digits to the left of the decimal point that can be rounded up or down.

The NUMBER data type is supported by Oracle Database standard libraries and operates the same way as it does in SQL. It is used for dimensions and surrogates when a text or INTEGER data type is not appropriate. It is typically assigned to variables that are not used for calculations (like forecasts and aggregations), and it is used for variables that must match the rounding behavior of the database or require a high degree of precision. When deciding whether to assign the NUMBER data type to a variable, keep the following facts in mind in order to maximize performance:

  • Analytic workspace calculations on NUMBER variables is slower than other numerical data types because NUMBER values are calculated in software (for accuracy) rather than in hardware (for speed).
  • When data is fetched from an analytic workspace to a relational column that has the NUMBER data type, performance is best when the data already has the NUMBER data type in the analytic workspace because a conversion step is not required.
1
  • 2
    Does this have anything to do with distinguishing between NUMBER and INTEGER when querying dictionary views? Commented Apr 19, 2016 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.