trunc() instr() substr()
来源:互联网 发布:电影特效知乎 编辑:程序博客网 时间:2024/06/05 17:40
trunc(): 截取的意思
1、截取时间 最终的显示形式都是:年月日时分秒 2016-12-15 00:00:00
select trunc(sysdate ,'yyyy') from dual ;今年第一天,零点
select trunc(sysdate ,'yy') from dual ; 今年第一天,零点
select trunc(sysdate ,'mm') from dual ;这个月第一天,零点
select trunc(sysdate ,'dd') from dual ;今天,零点
select trunc(sysdate ) from dual ;今天,零点
select trunc(sysdate ,'d') from dual ;这个星期第一天,零点
select trunc(sysdate ,'hh') from dual ;当前时间,精确到小时
select trunc(sysdate ,'mi') from dual ;当前时间,精确到分钟
2、截取数字
trunc(a,b); a:表示要操作的数 b:表示要保留的小数位数
如下给出一个例子
计算得到相差的天数
instr(): 一般有两种用法:
1、从一个字符串中查找指定子串的位置
select instr('abcdeab','a') position from dual;
显示结果为1 (说明是从1开始查找a的位置的)
select instr('abcdeab','a',2) position from dual;
显示结果为6 从第二个位置开始查找a
select instr('abcdeab','b',2,2) position from dual;
显示结果为7 从第二个位置开始查找第二次出现b的位置
select instr('abcdeab','f') position from dual;
显示结果为0 找f在字符串中的位置,如果找不到返回结果为0
2、如下格式时有 like 的作用
select * from tableA where instr(NAME,'张三')>0;
等同于
select * from tableA where name like '%张三%';
--------------------------------------------------------------
select * from tableA where instr(NAME,'张三')=1;
等同于
select * from tableA where name like '张三%';
---------------------------------------------------------------
select * from tableA where instr(NAME,'张三')=0;
等同于
select * from tableA where name not like '%张三%';
---------------------------------------------------------------
select * from tableA where instr('张三, 李四', name) > 0;
等同于
select * from tableA where name like '%张三%' or name like '%李四%';
3、instr()和like 两者效率问题
简单的检索两者效率相当,复杂的检索instr()效率比like高,所以可以选择instr()函数来替换like使用
substr():用来截取字符串
select substr('abcdeab',0,2 ) from dual;
结果为:ab 表示从第一位开始截取2位,此处第一位也是从1开始
select substr('abcdeab',1,2 ) from dual;
结果为:ab 表示从第一位开始截取2位,此处第一位也是从1开始
select substr('abcdeab',3,10 ) from dual;
结果为:cdeab 从第三位开始截取,如果超出范围,那么到最后一位截止
nvl():判断是否为空
nvl(table.money, 0): 表示如果表中的money字段如果为空,则赋值为0,如果不为空则为本身的值
- trunc() instr() substr()
- SUBSTR,INSTR
- oracle substr(),instr(),length()
- oracle substr instr translate
- instr和substr函数
- oracle : instr, substr
- orcle substr和instr
- DB2 substr,instr使用
- substr和instr用法
- instr 和 substr
- substr和instr
- oracle substr instr
- ORACLE 截断字符串(Instr,subStr)
- oracle中的instr()substr()
- Oracle中INSTR,SUBSTR方法
- substr和instr的用法
- ORACL instr 函數 substr函數
- DBMS_LOB的instr与substr
- 关于数据库与LoaderManager的联合使用,节流???。。。。。
- Android平滑图片加载和缓存库 Glide 使用详解
- 使用bootstrap进行页面设计第一步
- hibernate的基本保存操作
- 第十四周 项目1验证算法
- trunc() instr() substr()
- RxJava2 vs RxJava1
- java将淘宝客链接转换为正常商品链接
- 第十四周项目1 - 验证二叉排序树相关算法
- Android逆向之旅---运行时修改内存中的Dalvik指令来改变代码逻辑
- 单文件上传
- 第十四周项目一(验证各算法)
- (第十四周项目1)验证算法(3)二叉排序树相关算法
- Java泛型中K T V E ? object等的含义