Sybase Error Implicit Conversion from datatype 'VARCHAR' to 'INT' not allowed

匿名 (未验证) 提交于 2019-12-03 00:59:01

问题:

I'm getting this error when trying to run a query in my application and I'm not sure why:

Caused by: com.sybase.jdbc3.jdbc.SybSQLException: Implicit conversion from datatype 'VARCHAR' to 'INT' is not allowed.  Use the CONVERT function to run this query.  at com.sybase.jdbc3.tds.Tds.a(Unknown Source) at com.sybase.jdbc3.tds.Tds.nextResult(Unknown Source) at com.sybase.jdbc3.jdbc.ResultGetter.nextResult(Unknown Source) at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source) at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source) at com.sybase.jdbc3.jdbc.SybStatement.queryLoop(Unknown Source) at com.sybase.jdbc3.jdbc.SybStatement.executeQuery(Unknown Source) at com.sybase.jdbc3.jdbc.SybPreparedStatement.executeQuery(Unknown Source) at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.executeQuery(WSJdbcPreparedStatement.java:678) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1953) at org.hibernate.loader.Loader.doQuery(Loader.java:802) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) at org.hibernate.loader.Loader.doList(Loader.java:2533) ... 79 more 

No where in my code am I trying to convert a VARCHAR into an INT.

Database View Columns --> Java type:

INT --> Integer VARCHAR --> String INT --> Long VARCHAR --> a POJO FLOAT --> Double DATE --> Date 

Is there anything else that may cause this error??

回答1:

Implicit conversion from datatype 'VARCHAR' to 'INT' will occur when you fail to enclose a VARCHAR value in quotes.

Implicit conversion from datatype 'INT' to 'VARCHAR' will occur when you enclose an INT value in quotes.



回答2:

In my case the default values provided for few INT columns in the table definition had VARCHAR values.

Example :

jobCount INT DEFAULT '0'



回答3:

@user1505078 is correct

In this C code, I use DB-Library DBSMALLINT type to search into a VARCHAR column, the return type is also an Integer so I had to wrap %d with single quotes (i.e. '% d'). That was enough to "convert" the value, since whatever it is going between quotes in that query will be CHAR anyway.

DBSMALLINT region_code;    dbbind(dbproc, 1, SMALLBIND, (DBINT)0, (BYTE *)&region_code); /* Integer */  sybase_error = False;     dbfcmd(dbproc, "insert into <table_name> ");     dbfcmd(dbproc, "select * from <another_table> ");     /* With quotes, the query searches for Chars instead */     dbfcmd(dbproc, "where group_code = '%d' ", region_code); /* Quotes in '%d' */     dbsqlexec(dbproc);     while (dbresults(dbproc) != NO_MORE_RESULTS)       continue; 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!