ora-01722

Force Oracle error on fetch

老子叫甜甜 提交于 2019-12-11 02:24:34
问题 I am trying to debug a strange behavior in my application. In order to do so, I need to reproduce a scenario where an SQL SELECT query will throw an error, but only while actually fetching from the cursor, not while executing the query itself. Can this be done? Any error will do, but ORA-01722: invalid number seems like the obvious one to try. I created a table with the follwing: KEYCOL INTEGER PRIMARY KEY OTHERCOL VARCHAR2(100) I then created a few hundred rows with unique values for the

sqlplus - using a bind variable in “IN” clause

谁都会走 提交于 2019-12-10 19:05:42
问题 I am setting a bind variable in a PL/SQL block, and I'm trying to use it in another query's IN expression. Something like this: variable x varchar2(255) declare x varchar2(100); begin for r in (select id from other_table where abc in ('&val1','&val2','&val3') ) loop x := x||''''||r.id||''','; end loop; --get rid of the trailing ',' x:= substr(x,1,length(x)-1); select x into :bind_var from dual; end; / print :bind_var; select * from some_table where id in (:bind_var); And I get an error (ORA

Invalid Number Error! Can't seem to get around it

二次信任 提交于 2019-12-07 08:19:05
问题 Oracle 10g DB. I have a table called s_contact . This table has a field called person_uid . This person_uid field is a varchar2 but contains valid numbers for some rows and in-valid numbers for other rows. For instance, one row might have a person_uid of '2-lkjsdf' and another might be 1234567890. I want to return just the rows with valid numbers in person_uid. The SQL I am trying is... select person_uid from s_contact where decode(trim(translate(person_uid, '1234567890', ' ')), null, 'n', 'c

Invalid Number Error! Can't seem to get around it

不羁的心 提交于 2019-12-05 14:06:48
Oracle 10g DB. I have a table called s_contact . This table has a field called person_uid . This person_uid field is a varchar2 but contains valid numbers for some rows and in-valid numbers for other rows. For instance, one row might have a person_uid of '2-lkjsdf' and another might be 1234567890. I want to return just the rows with valid numbers in person_uid. The SQL I am trying is... select person_uid from s_contact where decode(trim(translate(person_uid, '1234567890', ' ')), null, 'n', 'c') = 'n' The translate replaces all numbers with spaces so that a trim will result in null if the field

Oracle number and varchar join

一世执手 提交于 2019-12-04 00:13:46
I have a query that joins two tables. One table has a column that is of type varchar, and the other table has type of number. I have executed my query on 3 oracle databases, and am seeing some strange results I hope can be explained. On two of the databases something like the following works. select a.col1, b.somecol from tableA a inner join tableB b on b.col2=a.col1; In this query tableA.col1 is of type number and tableB.col2 is of type varchar. This works fine in two of the databases but not in the third. In the third I get (ORA-01722) error. In the third I need to do something like...

Why am I getting an ORA-01722 (invalid number)?

送分小仙女□ 提交于 2019-12-03 13:11:46
I've been using a parameterized query to insert values into an Oracle table, like so: var q = "insert into MyTable(Field1, Field2...) values(:Field1, :Field2...)"; var cmd = new OracleCommand(q, conn); // conn is a pre-existing connection cmd.Parameters.Add("Field1", field1Val); cmd.Parameters.Add("Field2", field2Val); // etc... cmd.ExecuteNonQuery(); This has been working fine, but suddenly this has stopped working, and I am getting Oracle error ORA-01722 (invalid number). I have checked the parameters, and all numbers are unquestionably valid numbers. I even substituted dummy values for any

Getting weird issue with TO_NUMBER function in Oracle

半腔热情 提交于 2019-12-01 20:51:48
I have been getting an intermittent issue when executing to_number function in the where clause on a varchar2 column if number of records exceed a certain number n. I used n as there is no exact number of records on which it happens. On one DB it happens after n was 1 million on another when it was 0.1. million. E.g. I have a table with 10 million records say Table Country which has field1 varchar2 containing numberic data and Id If I do a query as an example select * from country where to_number(field1) = 23 and id >1 and id < 100000 This works But if I do the query select * from country

Getting weird issue with TO_NUMBER function in Oracle

删除回忆录丶 提交于 2019-12-01 19:08:44
问题 I have been getting an intermittent issue when executing to_number function in the where clause on a varchar2 column if number of records exceed a certain number n. I used n as there is no exact number of records on which it happens. On one DB it happens after n was 1 million on another when it was 0.1. million. E.g. I have a table with 10 million records say Table Country which has field1 varchar2 containing numberic data and Id If I do a query as an example select * from country where to

.nextval JDBC insert problem

六月ゝ 毕业季﹏ 提交于 2019-12-01 15:50:32
问题 I try to insert into table with sequence .nextval as primary key, the sql in Java is sql = "INSERT INTO USER (USER_PK, ACCOUNTNUMBER, FIRSTNAME, LASTNAME, EMAIL ) VALUES (?,?,?,?,?)"; ps = conn.prepareStatement(sql); ps.setString(1, "User.nextval"); ps.setString(2, accountNumber); ps.setString(3, firstName); ps.setString(4, lastName); ps.setString(5, email); However, the error is ORA-01722: invalid number All the other fields are correct, I think it is the problem of sequence, is this correct

Can I pass a number for varchar2 in Oracle?

☆樱花仙子☆ 提交于 2019-12-01 06:24:27
I have an Oracle table and a column ( col1 ) has type varchar2(12 byte) . It has one row and value of col1 is 1234 When I say select * from table where col1 = 1234 Oracle says invalid number. Why is that? Why I cannot pass a number when it is varchar2 ? EDIT: All the responses are great. Thank you. But I am not able to understand why it does not take 1234 when 1234 is a valid varchar2 datatype. JAQFrost The problem is that you expect that Oracle will implicitly cast 1234 to a character type. To the contrary, Oracle is implicitly casting the column to a number. There is a non-numeric value in