oracle经常使用函数(2)
1、TRIM([ { { LEADING | TRAILING | BOTH }[ trim_character ]| trim_character} FROM ]trim_source) 函数
參数:leading 假设指定leading參数,oracle数据库将去除不论什么等于trim_character的开头字符。
參数:trailing 假设指定traling參数,oracle将去除不论什么等于trim_character的结尾字符。
參数:both 假设指定了both參数或者三个參数都未指定。oracle将去除不论什么等于trim_character的开头和结尾字符。
參数:trim_character 假设没有指定trim_character參数。默认去除的值为空格。
參数:trim_source 假设仅仅指定修剪源(trim_source),oracle将去除trim_source的开头和结尾的空格。
注意:a、trim函数返回一个varchar2类型值。该值最大的长度等于trim_source的长度。
b、假设trim_source和trim_character有一个为null。则trim函数返回null。
c、trim_character和trim_source都能够为下面随意一种数据类型:CHAR, VARCHAR2。 NCHAR, NVARCHAR2, CLOB, OR NCLOB。
d、返回值的类型与trim_source的数据类型一致。
select trim(leading 'B' from 'BBoat is good') "test_trim" from dual;--oat is good
select trim(trailing 'd' from 'BBoat is good') "test_trim" from dual;--BBoat is goo
select trim(both 'd' from 'd--Boat is handsome--d') from dual t;----Boat is handsome--
select trim('d' from 'd--Boat is handsome--d') from dual t;----Boat is handsome--
select length(trim(leading from ' d--Boat is handsome--d ')) from dual t;--23
select length(trim(' d--Boat is handsome--d ')) from dual t;--22
select trim(trailing null from 'boat ') nulltrim from dual;
select trim(both 'b' from null) nulltrim from dual;
2、abs函数
用途:返回指定值的绝对值
select abs(100),abs(-100) from dual;--100 100
select abs(null) from dual t;
select abs('') from dual t;
3、ceil函数
用途:返回大于或等于给出数字的最小整数
select ceil(-7.09) from dual t;-- -7
select ceil(7.09) from dual t;-- 8
4、floor函数
用途:返回小于或等于给定数字的最大整数
select floor(-7.09) from dual;-- -8
select floor(7.09) from dual;-- 7
5、mod(a,b)函数
用途:返回一个a除以b的余数
select mod(2,3) from dual;--2
select mod(-2,3) from dual;-- -2
6、power(a,b)函数
用途:返回a的b次方函数
select power(2,3) from dual;
7、round(number)函数
用途:四舍五入的方式取给定数字的整数值
select round(1.4) from dual;--1
round(带小时分秒的日期,參数)
參数:秒SS,精确到秒。
參数:分MI,到分。秒数30是分界线,相当于四舍五入的5,假设秒超过30,向前进1分钟
參数:时HH,假设分超过30分钟,向前进1个小时
參数:日DD, 假设小时超过12点,向前进1个小时
參数:月MM,16号是临界,相当于四舍五入的5,假设超过16号,向前进1天
參数:年YY。超过7月。向前进1年
參数:day。星期三是分界线 大于星期三即显示日期所在星期的下一个星期日。小于等于则显示所在星期的星期日
select round(to_date('2014-06-30','yyyy-mm-dd'),'yyyy') nian from dual;--2014/1/1
select round(to_date('2014-07-01','yyyy-mm-dd'), 'yyyy') nian from dual;--2015/1/1
select round(to_date('2014-06-16','yyyy-mm-dd'), 'mm') yue from dual;--2014/7/1
select round(to_date('2014-06-15','yyyy-mm-dd'), 'mm') yue from dual;--2014/6/1
select round(to_date('2014-07-15 12:00:01','yyyy-mm-dd hh24:mi:ss'), 'dd') ri from dual;--2014/7/16
select round(to_date('2014-07-15 11:59:59','yyyy-mm-dd hh24:mi:ss'), 'dd') ri from dual;--2014/7/15
select round(to_date('2014-07-30 10:30:01','yyyy-mm-dd hh24:mi:ss'), 'hh') shi from dual;--2014/7/30 11:00:00
select round(to_date('2014-07-30 10:29:59','yyyy-mm-dd hh24:mi:ss'), 'hh') shi from dual;--2014/7/30 10:00:00
select round(to_date('2014-07-15 13:30:01','yyyy-mm-dd hh24:mi:ss'), 'mi') fen from dual;--2014/7/15 13:30:00
select round(to_date('2014-07-15 14:30:31','yyyy-mm-dd hh24:mi:ss'), 'mi') fen from dual;--2014/7/15 1:31:00
select sysdate,round(sysdate-1, 'day'),round(sysdate, 'day'),round(sysdate+1,'day') from dual;
8、ADD_MONTHS函数
用途:添加或减去指定月份
select add_months(to_date('2014-7-30','yyyy-mm-dd'),2) from dual;--2014/9/30
select add_months(to_date('2014-7-30','yyyy-mm-dd'),-2) from dual;--2014/5/30
9、LAST_DAY函数
用途:返回日期的最后一天
select to_char(last_day(sysdate-21),'yyyy.mm.dd') from dual;--2014.07.31
10、MONTHS_BETWEEN(date2,date1)函数
用途:返回date2-date1的月份差值
select months_between('16-9月-2014','16-7月-2014') mon_between from dual;--2
select months_between('01-9月-2014','15-7月-2014') mon_between from dual;--1.54838709677419
select months_between(to_date('2014-07-01','yyyy-mm-dd'),to_date('2014-09-01','yyyy-mm-dd')) mon_between from dual;--2
11、NEXT_DAY(date,x)函数
用途:给出日期date和星期x之后计算下一个星期x的日期
select next_day(sysdate,to_char(sysdate,'day')) next_day from dual;--2014/8/6 11:09:55
select to_char(sysdate,'day') from dual;--星期三
12、SYSDATE函数
用途:用来给出当前系统的时间(注意是系统的时间,假设远程调用server上的数据库,则是数据库所在server的时间)
select sysdate from dual;--2014/7/30 11:33:49
select systimestamp from dual;--30-7月 -14 11.33.56.450391 上午 +08:00
oracle经常使用函数(2)的更多相关文章
- Oracle 中 decode 函数用法
Oracle 中 decode 函数用法 含义解释:decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值) 该函数的含义如下:IF 条件=值1 THEN RETURN(翻译 ...
- 重写Oracle的wm_concat函数,自定义分隔符、排序
oracle中,wm_concat函数是一个聚合函数,和mysql中的group_concat函数类似,不过group_concat函数比较强大,可以定义分隔符和排序,当然所谓强大是相对的,这里假使我 ...
- Oracle日期时间函数大全
ORACLE日期时间函数大全 TO_DATE格式(以时间:2007-11-02 13:45:25为例) Year: yy two digits 两位年 显示值:07 yyy three digits ...
- Oracle过程及函数的参数模式,In、out、in out模式
Oracle过程及函数的参数模式 In.out.in out模式 在Oracle中过程与函数都可以有参数,参数的类型可以指定为in.out.in out三种模式. 三种参数的具体说明,如下图所示: ( ...
- oracle的substr函数的用法
oracle的substr函数的用法 取得字符串中指定起始位置和长度的字符串 substr( string, start_position, [ length ] ) 如: substr( ...
- Oracle nvl(),nvl2()函数介绍
NVL函数 Oracle/PLSQL中的一个函数. 格式为: NVL( string1, replace_with) 功能:如果string1为NULL,则NVL函数返回replace_with的值, ...
- Oracle LPAD/RPAD函数在处理中文时的注意事项
首先看下Oracle官方对函数的定义: The RPAD function returns an expression, right-padded to a specified length with ...
- oracle wm_concat(column)函数的使用
oracle wm_concat(column)函数使我们经常会使用到的,下面就教您如何使用oraclewm_concat(column)函数实现字段合并,如果您对oracle wm_concat(c ...
- Oracle之自定义函数
数据库中函数包含四个部分:声明.返回值.函数体和异常处理. --没有参数的函数 create or replace function get_user return varchar2 is v_use ...
- oracle 自定义 聚合函数
Oracle自定义聚合函数实现字符串连接的聚合 create or replace type string_sum_obj as object ( --聚合函数的实质就是一个对象 sum ...
随机推荐
- javascript中变量命名冲突的问题
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 详解sqlserver查询表索引
SELECT 索引名称=a.name ,表名=c.name ,索引字段名=d.name ,索引字段位置=d.colid ? 1 2 3 4 5 6 7 8 FROM sysindexes a ...
- Win10 BackgroundTask
1.这里面详细的说明了后台任务的搭建 调用等 提示: 1.BackgroundTaskRegistration 里面有这两个事件 OnCompleted/Progress 主要用来UpdateUI 这 ...
- open source project for recommendation system
原文链接:http://blog.csdn.net/cserchen/article/details/14231153 目前互联网上所能找到的知名开源推荐系统(open source project ...
- Spring boot application.properties 配置
原文链接: http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.ht ...
- (转)基于MVC4+EasyUI的Web开发框架形成之旅--框架总体界面介绍
http://www.cnblogs.com/wuhuacong/p/3344096.html 在前面介绍了一些关于最新基于MVC4+EasyUI的Web开发框架文章,虽然Web开发框架的相关技术文章 ...
- gcc和g++的区别和联系
gcc和g++都是GNU(一个组织)的编译器. 1.对于.c后缀的文件,gcc把它当做是C程序:g++当做是C++程序: 2.对于.cpp后缀的文件,gcc和g++都会当做c++程序. 3.编译阶段, ...
- Linux终端 Tab 补全命令
1. vi编辑器打开 /etc/bash.bashrc文件 vi /etc/bash.bashrc 2.找到文件中的下列代码 3.将注释符号#去掉,即改成 4.最后 source一下 /etc/bas ...
- Python代码块缓存、小数据池
引子 前几天遇到了这样一道Python题目:a='123',b='123',下列哪个是正确的? A. a != b B. a is b C. a==123 D. a + b =246 正确答案是B 是 ...
- Linux 命令查询系统负载信息
linux uptime命令主要用于获取主机运行时间和查询linux系统负载等信息.uptime命令过去只显示系统运行多久.现在,可以显示系统已经运行了多长 时间,信息显示依次为:现在时间.系统已经运 ...