您的位置:首页 > 数据库 > Oracle

Oracle常用操作与函数

2012-07-17 14:37 411 查看
sysdate: 获取系统时间,如
select sysdate from dual;
to_char(date, ‘format’): 将日期转换为想要的格式,如:
select to_char(sysdate, ‘yyyy-mm-dd day’) from dual;
to_date(string, ‘format’): 将字符串转换为想要的格式,如:
select to_date(‘20120615’, ‘yyyy-mm-dd’) from dual;
last_day(date): 获取date所在的月份的最后一天,如:
select last_day(sysdate) from dual;
to_number(‘string’): 将字符串类型转换成数字,如:
select to_number(‘2000’) from dual;
vsize(‘string’): 计算string的长度(所占的字符),如:
select vsize(‘abcdef’) from dual;
group by: 通常group by要与sum一起用:
select col_name, sum(col_name) from table group by col_name;
like: 用于在where子句中搜索列中的指定模式,%可用于定义通配符(模式中缺少的字母):
select * from table where col_name like ‘N%’; (选取col_name以N开头的行)
select * from table where col_name like ‘%g’; (选取col_name以g结尾的行)
select * from table where col_name like ‘%ab%’; (选取col_name含有ab的行)
select * from table where col_name not like ‘%ab%’; (选取col_name不含ab的行)
通配符% _
%匹配一个或多个字符
_匹配一个字符
in: 用于在where子句中搜索列中包含在in内的值:
select * from table where col_name in (value1, value2……);
between and(between start and end:用于搜索介于start(包含)跟end(不包含)之间的行:
select * from table where col_name between start and end;
order by: 根据指定的列对结果集进行排序,默认按升序排序,desc按降序排列:
select * from table t order by t.amount;
distinct: 用于去除重复行:
select distinct col_name from table;

本文出自 “sunmoon小筑” 博客,请务必保留此出处http://sunmoonrili.blog.51cto.com/5265851/933415
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: