Why does a large number change value when stored in Oracle DB

During a software project, we stumbled upon an error where we injected a large number (17 digits) from Java into an Oracle DB procedure. A number changed its value sometimes +1 or -1. Sometimes the same thing remained. We checked the debug log of the Oracle driver and saw that it printed the correct number. We also tried restarting the Java application server between each request in order to resolve caching errors. All the same results.

Any ideas why this is happening?

Here is the code:

// Datasource configuration <New class="oracle.jdbc.pool.OracleDataSource"> <Set name="DriverType">thin</Set> <Set name="URL">jdbc:oracle:thin:@xxxx</Set> <Set name="User">uuuu</Set> <Set name="Password">pppp</Set> </New> // JAVA SimpleJdbcCall testMsg = new SimpleJdbcCall(dataSource). withSchemaName(schema). withCatalogName(catalog). withProcedureName("test_msg"); public void testMessage(Long n) { testMsg.execute(n, n, n.toString()); } // PL_SQL procedure test_msg( i integer, n number, v varchar2 ) is log_prfx log_pkg.t_log_prfx := 'test_msg: '; begin g_log.log_debug(log_prfx||'i='||to_char(i)); g_log.log_debug(log_prfx||'n='||to_char(n)); g_log.log_debug(log_prfx||'v='||v); end test_msg; 

Call now

 testMessage(10000000000000005L); testMessage(10000000000000007L); testMessage(10000000000000009L); 

Complete work with magazines such as

 test_msg: i=10000000000000005 test_msg: n=10000000000000005 test_msg: v=10000000000000005 test_msg: i=10000000000000008 test_msg: n=10000000000000008 test_msg: v=10000000000000007 test_msg: i=10000000000000008 test_msg: n=10000000000000008 test_msg: v=10000000000000009 

The versions we use.

  • Spring 3.2.11
  • Oracle driver ojdbc7_g-12.1.0.2 (we also tested with 11.2.0.4)
  • Oracle DB is version 12.1.0.1.0
  • Jetty 9.2.2 and JBoss 7 (the same behavior appeared in both)
+5
source share
2 answers

So, in the end I went with passing to BigDecimal from Java and using NUMBER in PLSQL (although an integer would work too).

Thanks Ivan for this advice!

0
source

The number you pass is greater than the maximum value for the oracle, so unpredictable results may occur. The maximum int value in oracle is 2147483647. Use the correct type of your number as described in oracle docs

0
source

Source: https://habr.com/ru/post/1203191/


All Articles