1、例如以 user表为例,有password字段,login字段,那么我们如何筛选出数据库表中,登陆ID最长的用户呢?
2、select * from USER t order by nvl(length(trim(t.login_id)),0) desc
3、nvl(coloum,defaultValue) 当属性值为空时就将其值设默认值 ;此处设为0,如果login字段长度为空的话
4、trim(t.login_id) 去空格
5、length(trim(t.login_id) 获取去除前后空格后的login_Id的长度
6、如此,获得按照login_id 长度从长到短 倒序排列的数据:
7、当然,如果要获得最短的,需要升序获得:select * from USER t order by nvl(length(trim(t.login_id)),0) asc