tags:

views:

52

answers:

2

I run the below code in my C# .Net application, but I keep getting error ORA-01722: invalid number. When running the same SQL directly in PL/SQL Developer it does exactly what I ask it to without complaining.

What could be causing this?

OracleCommand command = connection.CreateCommand();
command.CommandType = CommandType.Text;
command.CommandText = "insert into my_table ( select i.*, null from my_view i where i.usr_id is not null )";
command.ExecuteNonQuery();

Note: I am using Oracle.DataAccess.Client

+1  A: 

I'm not sure whether this could cause different behaviour between Developer and your client, but you're making an assumption that the column order is the same in the view and the table. It's possible, though unlikely, that it's trying to insert char data from a column in the view into a number field in the table just from sequencing them differently. Try specifying the column names in both the insert and select and see if it helps. I also wondered if there was a date format mismatch but I don't see how that would cause a problem within one statement. If this is a simplified version, does the real one have any parameters?

Alex Poole
The only thing simplified is the table and view names. I tested specifying all column names, and I still receive the error. I only have varchar2 and number column types in my table, and all numbers can convert to number with to_number() while in PL/SQL.
tkalve
Is there a possibility of a schema clash - are you connected as the same user in both situations? Are there any triggers firing on insert?
Alex Poole
+2  A: 

I found the problem. One of the number columns in the view used a comma (,) as a decimal seperator, while the table expected a point (.).

Thanks for the help people. :)

tkalve