怎么可能?
sql语句有位操作吗?

解决方案 »

  1.   

    hsql中估计没有位运算,但你可这样:
      int stat=1;
      stat <<= 2;   // 先用JAVA的位运算将条件算好
      String x;
      x="select * from test where stat="+stat;
      Query q = sess.createQuery(x);
      ...
      

  2.   

    2楼的方法也不行,因为不能相等,可能有一条记录即使激活又是锁定,那么状态位是0011,这样就不适合了。sql server 中是支持位运算的
    用 & 和 | 来进行 与运算 和 或运算不过hql好像是没有办法
    大家再出出主意,没有就结贴了。
      

  3.   

    如果数据量不大,不考虑效率,试试
    select * from test where substr(cast(stat/4 as String),length(cast(stat/4 as String))-1,1)='1'  
    其中cast及substr都应该是hql支持的函数
    4 为左移2们,即从右第3位(状态为100的)
      

  4.   

    还有一个方法,在数据库中用SQL SERVER建一view
    create view test1 as select *,(stat & 1) stat1,(stat /2 &1) stat2,(stat /4 &1 ) stat3 ...
       from test1
    这样用hql查询时,查"锁定"的,只要
     select * from test1 where stat1=1
    这样用hql查询时,查"激活"的,只要
     select * from test1 where stat1=2
    当然,最好的方法是建表时直接将每一状态建成一个字段
    或直接用SQL而非hql
      

  5.   

    写错了,hql查询时,查"激活"的,只要
     select * from test1 where stat2=1