2.1以指定的次序返回查询结果[order by....ASC(升序)...DESC(降序)]
select * from table order by date ASC -->根据时间升序排列
2.2按多个字段排序
select column1,column2,column3 from order by column2 ASC,column3 DESC -->先按column2升序排列,在按column3降序 排列
2.3按子串排序[截取电话号码的末4位 substr()函数]
select column1,phone,substr(phone,-4) as "末四位" from table -->取末4位[-4 < 0,表示从右边起开始截取4为]
select column1,phone,substr(phone,7) as "末四位" from table -->取末4位[截取第七位及后面所有的字符串]
select column1,phone,substr(phone,7,4) as "末四位" from table -->取末4位[从第七位开始截,截取的长度为4]
2.4Translate[ translate(str,from_string,to_string) 根据from_string与to_string对应法则,生成新的str]
select translate('132',''123,'abc') as new_str from dual; -->acb
select translate('132',''123,' ') as new_str from dual; -->null
2.5按数字和字母混合字符串中的字母排序[利用translate函数,将数字替换为空,再使用order by进行排序]
select data,translate(data,'- 0123456789','-') as newData from table order by newData;
2.6处理排序空值[nulls first 空值在前 nulls last 空值在后]
select column1,column2,column3 from order by column2 nulls first;
select column1,column2,column3 from order by column2 nulls last;
内置函数
①、substr(String str,int a,int b) 表示 从字符串第a位开始截,截取的长度为b
select substr('abcdefgh',4,3) from dual; -->def
select substr('abcdefgh',-4,3) from dual; -->efg
②、sunstr(string str,int a) a > 0 表示从字符串str第a位开始截及后面的字符串
a < 0 表示从字符串右边起截取长度为a的字符串
select substr('abcdefgh',4) from dual; -->defgh
select substr('abcdefgh',-4) from dual; -->efgh
名称解释
视图(view):基于一个表或多个表的逻辑表,本身不包含数据,通过视图可以对表里面的数据进行查询和修改。视图基于的表则
称为基表。视图是储存在数据字典里的一条select语句,通过创建视图可以提取数据的逻辑上的集合或组合。
注意:所有对视图的操作都会影响视图的基表,为了防止 用户通过视图间接的修改表的数据,可以将视图创建为只读视图(带上 with read only)