Store big number in Oracle - oracle

I need to store number around 2147483647 in Oracle table.
What Oracle table field can you recommend as most suitable for this number?

From Oracle doc
NUMBER Datatype The NUMBER datatype stores fixed and floating-point
numbers. Numbers of virtually any magnitude can be stored and are
guaranteed portable among different systems operating Oracle Database,
up to 38 digits of precision.
The following numbers can be stored in a NUMBER column:
Positive numbers in the range 1 x 10-130 to 9.99...9 x 10125 with up
to 38 significant digits
https://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#i16209

Related

Can Oracle Database Sequence have a max value like 38 digits?

I am using Oracle 12.x DB and have a column with data type - NUMBER(38, 0) and would be populating this column from a Sequence. But I read the maximum value from a sequence would be 28 precision digits i.e. 10^28 -1 value.
Is there a way to generate a maximum of 38 digits value to populate the column mentioned above?
If Oracle sequence cannot go beyond 28 digits then WHY Oracle supports data type like NUMBER with 38 digits precision??
Thanks.
Yes, the limit of a sequence is 10^28-1. Oracle supports larger numbers because sequences aren't the only things to use the number data type. You'd have to ask Oracle why sequences don't go any higher than that.

Oracle NUMBER data type max limit with & without decimal points

I have a number field in the application which passes a numeric value to my Oracle procedure which is of NUMBER datatype. The numeric value can be positive, negative, with or without decimal points.
I need to restrict it from the application so I need to specify the maximum limit without any round-off. Can I please know what will be the limits for positive, negative, with, and without decimals points.
It is not really a range that is allowed, but a precision. You can pass any number with up to 38 digits, no matter if or where the decimal separator.
Okay:
+12345678901234567890123456789012345678
-12345678901234567890123456789012345678
+1.2345678901234567890123456789012345678
-1234567890123456789012345678901234567.8
May get slightly mutilated:
+123456789012345678901234567890123456789
-123456789012345678901234567890123456789
+1.23456789012345678901234567890123456789
-1234567890123456789012345678901234567.89
Demo with some longer numbers: https://dbfiddle.uk/?rdbms=oracle_18&fiddle=aa74ef09157dcf86daa76507e868fe49

Writing sas data to Hive with Numeric variable with More than 15 digits

I am trying to write a SAS data to Hive using SAS. I have a ID variable in the table which is >15 digits long and I need to keep this variable as Numeric when I write this data to Hive. I have tried the below script but it is giving me the below warning and the values in the Hive table are truncated to 15 digits with an "e".
data scr.EOB_tgt(dbtype=(nacct="BIGINT"))
;
format nacct best20.
ncust $10.
;
set lat2(keep=ncust nacct bal);
run;
NOTE: SAS variable labels, formats, and lengths are not written to DBMS tables.
WARNING: Value 1589000007877656 has more than 15 digits. It may not be accurately inserted to the BIGINT column.
Does anybody know how to overcome this issue?
I would like to be able to get the full 16 digit numeric value in the Hive table
SAS stores all numbers as 8 byte floating point. So you cannot represent integers with more than 15 digits exactly. To see the maximum integer that can be represented exactly use the CONSTANT() function.
data _null_;
x=constant('exactint');
put x 16. +1 x comma21.;
run;
Result:
9007199254740992 9,007,199,254,740,992
So if you have any ID values larger than 9,007,199,254,740,992 then you cannot store them as numbers in SAS.
Why are you storing ID values as numbers? There is no need to perform arithmetic on ID values.

How to calculate increase in storage usage on Oracle 11g?

How would I calculate or estimate the increased storage difference from increasing the precision on a column from number(2,0) to number(6,0)? Or is it the same? No difference? Let's pretend I have 1 million rows in the table. What does the arithmetic look like?
The precision of a number field is basically just a constraint on how much precision Oracle will retain when storing a value. The underlying number format is actually the same (it's a varying-width field, and not something like a fixed-sized integer or float) - the amount of space required is related to the number of digits in the specific numbers which are being stored.
So if you don't modify the values in the table, then the size shouldn't change. But if you increase the precision and then update the table with values with more digits, then they will potentially consume more space.

oracle NUMBER to hive

oracle DB is storing values as NUMBER, which from my understanding is max precision and scale. However hive documentation states that if you set DECIMAL with no precision or scale you will get DECIMAL(10,0) doc. What would the correct HIVE datatype be to accommodate ORACLE NUMBER.
Since Oracle allows any precision/scale for a NUMBER datatype, safest is to store it as Hive STRING, to avoid any kind of data loss.
depending on actual data/or it's usage, downstream can convert it to needed datatype.
According to Oracle docs:
NUMBER:
INT when the scale is 0 and the precision is less than 10
BIGINT when the scale is 0 and the precision is less than 19
DECIMAL when the scale is greater than 0 or the precision is greater
than 19

Resources