【问题标题】:"Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query." error“不允许从数据类型 varchar 到 varbinary 的隐式转换。使用 CONVERT 函数运行此查询。”错误
【发布时间】:2018-03-22 20:45:37
【问题描述】:

当我尝试使用 Hibernate 执行以下查询时,我遇到了以下错误:

从数据类型 varchar 到 varbinary 的隐式转换不是 允许。使用 CONVERT 函数运行此查询。

String sql = "select distinct t.titleNo  from Ties t ,Titles se,TieType TT ,Net NTT "  
                        +" where t.seriesNo  = se.titleNo and t.titleType=TT.titleType and TT.titleTypeNo = NTT.titleTypeNo  "
                        +" and  ((((t.titleName LIKE '%'+:titleName+'%')  OR (:titleName LIKE '%'+ t.titleName+'%')) AND (ISNULL(TT.titleBaseType,'') ='')  "
                        +" And Isnull(:titleBaseType,'') <> 'N')  "     
                        +"   OR (((t.titleName LIKE :titleName)  OR (:titleName LIKE t.titleName)) AND (ISNULL(TT.titleBaseType,'') ='N')))   "
                        +"   AND (IsNull(se.titleName,'%') like CASE WHEN (:seriesNo>0) THEN  (SUBSTRING(LTRIM(:seriesName),1,6)+'%') ELSE '%' END)";

                Query qry = session.createSQLQuery(sql);
                qry.setParameter("titleName", titleName); //String
                qry.setParameter("seriesNo", seriesNo); //Integer
                qry.setParameter("titleBaseType", titleBaseType); //String
                qry.setParameter("seriesName", seriesName); //String
qry.list();

我怎样才能避免这个错误?

【问题讨论】:

标签: implicit-conversion varbinary


【解决方案1】:

发生这种情况是因为您的数据类型与数据库列的数据类型不匹配。正确检查数据类型。你可以找到映射here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-07
    • 2018-04-30
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多