TABLE student:name(名字),stuno(学号-全数字,7位)需求,在两个文本框中输入查询范围,如0011,3001,点击查询,得到这两个号范围内的数据,注:得到的范围数据是字符串类型,取学号后四位做比较问题:新手,不知道sql语句该怎么写,我的是  
select * from student where right(stuno,4)>0011 and right(stuno,4)<3001;在查询分析器中查时,貌似是出来了数据,但好像比较的是第一位,问题一:怎么先取得学号的后四位然后把他们转成整型做比较呢,(要sql语句)
问题二:我写的HQL语句sql="from Student where right(stuno,4)>"+daharry[0]+" and right(stuno,4)<"+daharry[1];
报错Caused by: line 1:112: unexpected token: right,是怎么回事,HQL和SQL的还不一样吗?那HQL语句该怎么写呢先行谢过!

解决方案 »

  1.   

    如果是Oracle的话,有一个函数TO_NUMBER的函数,可以把字符串转换成函数
    Hibernate的用法不清楚另外需要说明的是,象截取字符串之类的函数是会破坏索引的
    如果数据量太大,这样检索是很耗时的~~
      

  2.   

    好像是sql server吧,试试吧
    select * from student where cint(right(stuno,4))>0011 and cint(right(stuno,4))<3001;hibernate里加了dialect吗? 如果hql实在不行,就用sql吧
      

  3.   

    用sql报:
    org.hibernate.MappingException: No Dialect mapping for JDBC type: 3配置了dialect,
    <property name="dialect">
    org.hibernate.dialect.SQLServerDialect
    </property>
    这样不对吗