【问题标题】:regarding converting sql to hql关于将sql转换为hql
【发布时间】:2010-12-21 12:03:44
【问题描述】:

如何在hql中选择列的值为null?

例如:在 sql 中

 select null as empname from emp; in sql

   In hql   

ex: select emp.empname as col1 from Employee emp;

我想将 empname 的值选择为 null,如上述 sql 查询中所述

【问题讨论】:

    标签: hibernate


    【解决方案1】:

    您可以使用强制转换功能。像这样,

    select cast(null as char) as hede from emp e 
    

    或者使用引号并将您的控件更改为空支票。

    select '' as hede from emp e 
    

    【讨论】:

    • 感谢您的回复,我在 hql 中需要它
    • sreelatha 你可以在你的 hql 中使用 cast。就像 select cast(null as char) as col1, emp.otherColumn ... from Employee emp;
    • 我尝试如下所述,它给出了 org.hibernate.QueryException select cast(null as char) as emp.col1, emp.otherColumn ... from Employee emp;你能告诉我怎么了.....?
    • 您正在尝试将转换后的值设为“emp.col1”。就是这样。此处只能有列名。
    • 好的,谢谢。我忘了告诉 select cast(null as char) as D_LOC,e.empname from (select d.location,e.empno from Employee e,Dept d where d.empno= e.empno 和 e.empno='1');请问这是正确的吗?
    猜你喜欢
    • 1970-01-01
    • 2011-05-26
    • 1970-01-01
    • 1970-01-01
    • 2011-09-24
    • 1970-01-01
    • 2013-07-02
    • 2014-06-26
    • 1970-01-01
    相关资源
    最近更新 更多