oracle中字符串与时间的转换
2015-04-15 14:15
363 查看
Oracle的Replace函数与translate函数详解与比较:
Replace:字符串级别的代替
SELECT REPLACE('2016年01月01日','年','-') from dual --> 2016-01月01日
translate:字符级别的代替
SELECT translate('2016年01月01日','年月日','--') from dual --> 2016-01-01
Oracle SQL中实现indexOf和lastIndexOf功能:
这里是substr和instr的综合使用。
substr(stirng1,strat,length);截取功能;
解析一下:string1是你要截取的字符串,strat是要开始截取的位置,length是你要截取多少个字符串。
instr(string1,string2,end);是检索功能,
解析一下:string1是你要检索的字符串,string2是你在string1中要查找的字符串,end的意思1代表从字符串的开始检索,-1代表中字符串的末尾开始检索。
例如:现在想要把字符串‘'2016年01月01日 星期一'’,转化为‘2016-01-01’ 类型的,你就可以如下写:
SELECT translate(substr('2016年01月01日 星期一',0,instr('2016年01月01日 星期一',' ',1) ) ,'年月日','--') from dual --> 2016-01-01
SELECT to_date( translate(substr('2016年01月01日 星期一',0,instr('2016年01月01日 星期一',' ',1) ) ,'年月日','--'),'yyyy-mm-dd hh24:mi:ss') from dual --> 2016/1/1(时间类型)
//我的示例代码:
select t.*,d.* from CRM_ttt t inner join CRM_ddd d
on t.companyid = d.companyid
WHERE to_date(to_char(SYSDATE+to_number(startdatas),'yyyy-mm-dd'),'yyyy-mm-dd')>=to_date(translate(substr(startdate,0,instr(startdate,' ',1)),'年月日','--'),'yyyy-mm-dd')
AND to_date(to_char(SYSDATE ,'yyyy-mm-dd'),'yyyy-mm-dd')<=to_date(translate(substr(startdate,0,instr(startdate,' ',1)),'年月日','--'),'yyyy-mm-dd')
AND d.remindtype = '循环提醒'
Replace:字符串级别的代替
SELECT REPLACE('2016年01月01日','年','-') from dual --> 2016-01月01日
translate:字符级别的代替
SELECT translate('2016年01月01日','年月日','--') from dual --> 2016-01-01
Oracle SQL中实现indexOf和lastIndexOf功能:
这里是substr和instr的综合使用。
substr(stirng1,strat,length);截取功能;
解析一下:string1是你要截取的字符串,strat是要开始截取的位置,length是你要截取多少个字符串。
instr(string1,string2,end);是检索功能,
解析一下:string1是你要检索的字符串,string2是你在string1中要查找的字符串,end的意思1代表从字符串的开始检索,-1代表中字符串的末尾开始检索。
例如:现在想要把字符串‘'2016年01月01日 星期一'’,转化为‘2016-01-01’ 类型的,你就可以如下写:
SELECT translate(substr('2016年01月01日 星期一',0,instr('2016年01月01日 星期一',' ',1) ) ,'年月日','--') from dual --> 2016-01-01
SELECT to_date( translate(substr('2016年01月01日 星期一',0,instr('2016年01月01日 星期一',' ',1) ) ,'年月日','--'),'yyyy-mm-dd hh24:mi:ss') from dual --> 2016/1/1(时间类型)
//我的示例代码:
select t.*,d.* from CRM_ttt t inner join CRM_ddd d
on t.companyid = d.companyid
WHERE to_date(to_char(SYSDATE+to_number(startdatas),'yyyy-mm-dd'),'yyyy-mm-dd')>=to_date(translate(substr(startdate,0,instr(startdate,' ',1)),'年月日','--'),'yyyy-mm-dd')
AND to_date(to_char(SYSDATE ,'yyyy-mm-dd'),'yyyy-mm-dd')<=to_date(translate(substr(startdate,0,instr(startdate,' ',1)),'年月日','--'),'yyyy-mm-dd')
AND d.remindtype = '循环提醒'
相关文章推荐
- oracle 时间和字符串之间的互相转换
- Oracle修改时间报:ORA-01830: 日期格式图片在转换整个输入字符串之前结束的解决办法
- Oracle时间转换成字符串
- Oracle将number类型的时间值转换成时间格式的字符串
- Oracle修改时间报:ORA-01830: 日期格式图片在转换整个输入字符串之前结束的解决办法
- Oracle修改时间报:ORA-01830: 日期格式图片在转换整个输入字符串之前结束的解决办法
- Oracle修改时间报:ORA-01830: 日期格式图片在转换整个输入字符串之前结束的解决办法
- Oracle时间与字符串的转换
- oracle 时间与字符串相互转换
- Oracle修改时间报:ORA-01830: 日期格式图片在转换整个输入字符串之前结束的解决办法
- Oracle时间转换成字符串
- Oracle修改时间报:ORA-01830: 日期格式图片在转换整个输入字符串之前结束的解决办法
- Oracle时间转换成字符串
- Oracle修改时间报:ORA-01830: 日期格式图片在转换整个输入字符串之前结束的解决办法
- js时间加减与时间对象与字符串之间的转换
- java--时间字符串类型转换为可存入数据库时间类型的方法
- oracle时间戳-日期转换
- 字符串与时间的转换
- js把字符串格式的时间转换成几秒前、几分钟前、几小时前、几天前等格式
- Swift3 时间戳转换成整型字符串 Double value cannot be converted to Int because the result would be greater than