如题:查询列名中以拼音字母a开头的记录
with tt as
(
  select '安' name from dual union all
  select '被' from dual union all
  select '走' from dual union all
  select '神' from dual union all
  select '哎' from dual
)
select * from tt where substr(name,1,1) between '阿' and '澳';SQL> with tt as
  2  (
  3    select '安' name from dual union all
  4    select '被' from dual union all
  5    select '走' from dual union all
  6    select '神' from dual union all
  7    select '哎' from dual
  8  )
  9  select * from tt where substr(name,1,1) between '阿' and '澳'
 10  ;
 
NAME
--------------------------------


现在我的疑问是:
1.为什么是between '阿' and '澳'?
2.为什么结果为“安”和“哎”?望高手帮忙解答下!

解决方案 »

  1.   

    select ascii('安') a,'安' x from dual union all
    select ascii('被') a,'被' x from dual union all
    select ascii('走') a,'走' x from dual union all
    select ascii('神') a,'神' x from dual union all
    select ascii('哎') a,'哎' x from dual union all
    select ascii('澳') a,'澳' x from dual union all
    select ascii('阿') a,'阿' x from dual 
    order by x应该根据ascii排序的。
      

  2.   

    为什么是between '阿' and '澳'?
      

  3.   

    between '阿' and '澳'
    where条件采用的是ascii去判断的 这里不是字符串‘阿’和‘澳’,而是他们的ASCII值,因为是between and ,
      

  4.   

    SQL> select ascii('安') from dual;
     
     ASCII('安')
    -----------
          45234
     
    SQL> select ascii('哎') from dual;
     
     ASCII('哎')
    -----------
          45221
     
    SQL> select ascii('阿') from dual;
     
     ASCII('阿')
    -----------
          45218
     
    SQL> select ascii('澳') from dual;
     
     ASCII('澳')
    -----------
          45252
     
    SQL> 
      

  5.   

    哥们啊,你执行下我的sql呀,就看到效果了。