之前没有用过Oracle数据库,所以遇到一些困难。请大家来帮忙解决。
   我想要实现查询同一个省的所有用户 
表:USER_PROFILE
主要字段:U_ID,ID_CARD
  我的思路是,通过截取指定用户U_ID的身份证的前两位数字作为参数,来查询数据表里身份证前两位和U_ID的身份证前两位数相同的所有记录。 我的查询语句是:
select t.* from USER_PROFILE t 
where t.ID_CARD like substr(t.id_card,1,2)
and t.U_ID=?
 
 很明显 这样的语句是错误的  有哪位大侠能帮帮忙啊。 给我点提示~~!

解决方案 »

  1.   

    select t.* from USER_PROFILE t  
    where substr(t.id_card,1,2) = '..'
    and t.U_ID=?
      

  2.   

    select t.* from USER_PROFILE t   
    where substr(t.id_card,1,2) = 
        (select substr(t.id_card,1,2) from USER_PROFILE t1 where t1.U_ID=?)
      

  3.   

    select t.* from USER_PROFILE t   
    where substr(t.id_card,1,2) = 
        (select substr(t.id_card,1,2) from USER_PROFILE t1 where t1.U_ID=?)
      

  4.   

    select t.* from USER_PROFILE t   
    where substr(t.id_card,1,2) = '..'
    and t.U_ID=?
      

  5.   

    select t.* from USER_PROFILE t  
    where  substr(t.id_card,1,2) = substr(t.u_id_card,1,2)
     
      

  6.   

    select t.* from USER_PROFILE t  
    where t.ID_CARD >= 'xx00000000000000' and t.ID_CARD < 'xy0000000000000';因为身份证号码长度是相同的,直接使用 >= 10000000 and <1100000000 比较的话就不会阻止数据库使用上索引了。