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

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.

Related

Oracle db sequence with hibenate sequence

I'm working in a project based on oracle db and JPA,
I have realized that a column whose value should be generated using a sequence SEQ_CASO has a precision= 12.
However in the sequence object declared in Oracle db I have found the maximum number is much bigger than a 12 figures number (9999999999999...):
I would like to know what would happen if the records number exceeded a 12 figures number in the db? Would the precision of 12 numbers defined by JPA crush the app or something?
Answering to your main question:
I would like to know what would happen if the records number exceeded a 12 figures number in the db?
Considering the code you quoted was made by reverse engineering, the column is probably defined in Oracle as NUMBER(12,0) (precision 12, scale 0).
That said, when the sequence in your application arrives to the point of generating 13 digit numbers, the Oracle database will return the following error when trying to insert these numbers in your table:
ORA-01438: value larger than specified precision allows for this column
The definition of precision and scale can be tricky in Oracle, especially when they are not explicitly defined (i.e. the col is defined just as NUMBER - no precision or scale specified).
More information about precision and scale:
What is the difference between precision and scale?
What is the default Precision and Scale for a Number in Oracle?
you don't need to define unique,nullable attributes with #Column annotation. When you define #Id annotation then it becomes primary key column which is not null and unique.
Even you don't need to define precision attribute and it works properly without it.
#Id
#SequenceGenerator(name="SEQ_CASO",sequenceName="SEQ_CASO_PK",initialValue=1500000,allocationSize=1)
#GeneratedValue(generator="SEQ_CASO",strategy=GenerationType.Sequence)
#Column("ID")
private long Id;

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.

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

Store big number in 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

Resources