我想查询某个字段中所有"A_"开头的数据。用LIKE的话,会把"A"开头的数据也查出来。但我只想要"A_"开头的数据。 怎么办啊?  除了LIKE还有其他方法么? 请高手指教啊~急

解决方案 »

  1.   

    select * from a where userid like 'A\_%' escape '\'
      

  2.   

    select * 
    from a 
    where 
     substr(userid,1,2)='A_'
      

  3.   

    select * from a where userid like 'A_'||'%'
      

  4.   


    水清  为什么要加 escape 呀?
    我用 \_   为什么不能转义为_?
      

  5.   

    在like子句中"_"下划线是匹配任意单个字符,因为要查询的字符串中包含了下划线,所以这里要用到转义字符,oracle中转义字符是自己定义的,就是escape后面的引号内的字符,下面语句是查询所有以"A_"开头的记录:select * FROM tblUser where userid Like 'A#_%' escape '#';  ---'#_'这里被转义成'_'要查以A%开头的纪录:select * FROM tblUser where userid Like 'A\%%' escape '\';  ---'\%'这里被转义成'%'
      

  6.   

    select * from a where userid like 'A_'||'%'
      

  7.   

    表结构如下:ID(自增长,没有业务含义,主键)
    code       varchar 编号
    name       varchar 名称
    price      float   价格
    create_datetime   date 创建日期删除掉表中 code,name,price,create_datetime 完全相同的重复记录,只留下 ID 最小的一条记录。请问用 SQL 怎么做呢???请问用 Hibernate 怎么做呢???
      

  8.   

    删除重复记录:
    delete from table_name 
     where rowid!=(select max(rowid) from table_name)
         where table_name.col1=d.col1 and table_name.col2=d.col2