Discussions
Categories
- 196.9K All Categories
- 2.2K Data
- 239 Big Data Appliance
- 1.9K Data Science
- 450.3K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 545 SQLcl
- 4K SQL Developer Data Modeler
- 187K SQL & PL/SQL
- 21.3K SQL Developer
- 295.9K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.6K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 440 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
Lost scale value when insert NUMBER(15,2) type

683536
Member Posts: 3
Hi,
I'm trying to insert a value 253.65 in a NUMBER(15,2) collum table. Below is my code:
{color:#3366ff}
cmd.Parameters.Add(BuildOracleParam("vNF", OracleDbType.Decimal, "253.65",15,2));{color}
where BuildOracleParam(name, type, value, precision, scale) is simple a method that create and return a OracleParamenter.
but when select the colllum I get the value 253.00.
How to resolve this situation? some advice?
tnks
I'm trying to insert a value 253.65 in a NUMBER(15,2) collum table. Below is my code:
{color:#3366ff}
cmd.Parameters.Add(BuildOracleParam("vNF", OracleDbType.Decimal, "253.65",15,2));{color}
where BuildOracleParam(name, type, value, precision, scale) is simple a method that create and return a OracleParamenter.
but when select the colllum I get the value 253.00.
How to resolve this situation? some advice?
tnks
Best Answer
-
Hi,
I'm assuming you're actually using ODP.NET and not OLEDB, since you're using OracleDbType?
Do you have a small complete testcase? This worked fine for me. Does it fail for you?
What version of provider, client, database are you using? I'm testing 11.1.0.7.
Cheers,
Greg//create table numtab1(col1 number(15,2)); using System; using System.Data; using Oracle.DataAccess.Client; class Program { static void Main(string[] args) { using (OracleConnection con = new OracleConnection("user id=scott;password=tiger;data source=orcl")) { con.Open(); using (OracleCommand cmd = new OracleCommand("", con)) { cmd.CommandText = "insert into numtab1 values(:1)"; OracleParameter p1 = new OracleParameter("", OracleDbType.Decimal); p1.Precision = 15; p1.Scale = 2; p1.Value = 253.65; cmd.Parameters.Add(p1); cmd.ExecuteNonQuery(); } } } }
Answers
-
Hi,
I'm assuming you're actually using ODP.NET and not OLEDB, since you're using OracleDbType?
Do you have a small complete testcase? This worked fine for me. Does it fail for you?
What version of provider, client, database are you using? I'm testing 11.1.0.7.
Cheers,
Greg//create table numtab1(col1 number(15,2)); using System; using System.Data; using Oracle.DataAccess.Client; class Program { static void Main(string[] args) { using (OracleConnection con = new OracleConnection("user id=scott;password=tiger;data source=orcl")) { con.Open(); using (OracleCommand cmd = new OracleCommand("", con)) { cmd.CommandText = "insert into numtab1 values(:1)"; OracleParameter p1 = new OracleParameter("", OracleDbType.Decimal); p1.Precision = 15; p1.Scale = 2; p1.Value = 253.65; cmd.Parameters.Add(p1); cmd.ExecuteNonQuery(); } } } }
-
thks gdarling !
the problem was that 'im inserting a string instead of decimal value.
i'm getting the value from xml document.
i'll try to correct it.
--
Frederico Pranto -
Hi Frederico,
For the record, it works fine for me still even when I supply value as a string.
Since you're relying on implicit conversion, perhaps this probably has somethign to do with the NLS settings on the client or database.
However, if you're saying it works with the above code when you supply a number instead of a string, I'd think the better solution is simply to use explicit conversion anyway instead of relying on implicit conversion (remember y2k!)
Hope it helps,
Greg -
Hi,
It's already works for me.
I think the problem was the culture configuration of data base or/and the input data format.
Probably, the oracle is configurated for "pt-BR" format, so the convertion will work if the input data was 465,45.
But I get 456.45. So, in .Net code I do the folow:
Decimal.Parse(pValor.ToString(), new CultureInfo("en-US").NumberFormat);
and works!
thks for the help! -
gdarling wrote:Your effort is appreciated! Here is also the same case, Finally learn how to solve it.
Hi,
I'm assuming you're actually using ODP.NET and not OLEDB, since you're using OracleDbType?
Do you have a small complete testcase? This worked fine for me. Does it fail for you?
What <font face="tahoma,verdana,sans-serif" size="1" color="#000">version</font> of provider, client, database are you using? I'm testing 11.1.0.7.
Cheers,
Greg
<p>
</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="darkgreen">//create table numtab1(col1 number(15,2));</font>
using System;
using System.Data;
using Oracle.DataAccess.Client;
<font color="navy"><b>class</b></font> Program
<font color="navy">{</font>
<font color="navy"><b>static</b></font> <font color="navy"><b>void</b></font> Main(string[] args)
<font color="navy">{</font>
using (OracleConnection con = <font color="navy"><b>new</b></font> OracleConnection(<font color="red">"user id=scott;password=tiger;data source=orcl"</font>))
<font color="navy">{</font>
con.Open();
using (OracleCommand cmd = <font color="navy"><b>new</b></font> OracleCommand(<font color="red">""</font>, con))
<font color="navy">{</font>
cmd.CommandText = <font color="red">"insert into numtab1 values(:1)"</font>;
OracleParameter p1 = <font color="navy"><b>new</b></font> OracleParameter(<font color="red">""</font>, OracleDbType.Decimal);
p1.Precision = 15;
p1.Scale = 2;
p1.Value = 253.65;
cmd.Parameters.Add(p1);
cmd.ExecuteNonQuery();
<font color="navy">}</font>
<font color="navy">}</font>
<font color="navy">}</font>
<font color="navy">}</font>
</code></pre>
This discussion has been closed.