Oracle to_char()和to_date()函数的用法
to_char()函数是我们经常使用的函数,下面就为您详细介绍Oracle to_date()函数的用法
1.to_char()函数分析
1)SQL中不区分大小写,MM和mm被认为是相同的格式代码
先看以下3个sql语句:
select to_char(sysdate,'yyyy-MM-dd HH24:mm:ss') from dual; select to_char(sysdate,'yyyy-mm-dd HH24:mm:ss') from dual; select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') from dual;
查询结果:
2017-02-22 13:02:42 2017-02-22 13:02:42 2017-02-22 13:14:42
从上面2个sql语句可以看出,mm和MM的是一样的,都是月份,SQL中不区分大小写,MM和mm被认为是相同的格式代码,所以Oracle的SQL要采用了mi代替分钟
2)显示格式有24小时制和12小时制
select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') from dual; select to_char(sysdate,'yyyy-MM-dd hh:mi:ss') from dual;
查询结果:
2017-02-22 13:14:42 2017-02-22 1:14:42
2.to_char()的其他用法
select to_char(sysdate,'yyyy') as nowYear from dual; --获取时间的年 2016
select to_char(sysdate,'mm') as nowMonth from dual; --获取时间的月 09
select to_char(sysdate,'dd') as nowDay from dual; --获取时间的日 07
select to_char(sysdate,'hh24') as nowHour from dual; --获取时间的时 10
select to_char(sysdate,'mi') as nowMinute from dual; --获取时间的分 33
select to_char(sysdate,'ss') as nowSecond from dual; --获取时间的秒 11
select to_char(sysdate,'day') as nowDay from dual; --获取当天是星期几 星期三
select to_char(sysdate,'D') as nowDay from dual; --获取当天是星期几 4
select floor(sysdate - to_date('2016-08-05','yyyy-mm-dd')) from dual; --取两个日期间的天数 33
3.to_date()函数
select to_date('2017-02-22 13:14:20','yyyy-MM-dd HH24:mi:ss') from dual;
Oracle to_char()和to_date()函数的用法的更多相关文章
- oracle to_char()及to_date()函数使用
to_char(x[,format]) :将x转换成字符串,可以使用format参数来格式化字符串输出. to_date(x[,format]) :将字符串x转换成日期,可以使用format匹配要转换 ...
- Oracle to_date()函数的用法
Oracle to_date()函数的用法 to_date()是Oracle数据库函数的代表函数之一,下文对Oracle to_date()函数的几种用法作了详细的介绍说明,供您参考学习. 在Orac ...
- Oracle to_date()函数的用法介绍
to_date()是Oracle数据库函数的代表函数之一,下文对Oracle to_date()函数的几种用法作了详细的介绍说明,需要的朋友可以参考下 在Oracle数据库中,Oracle t ...
- Oracle to_date()函数的用法《转载》
to_date()是Oracle数据库函数的代表函数之一,下文对Oracle to_date()函数的几种用法作了详细的介绍说明, 原文地址:http://database.51cto.com/art ...
- TO_CHAR 和 TO_DATE的一些用法总结
对于初学者来说,日期处理那快一向是问题的集中地.今天刚刚看了个案例,将的就是ORACLE日期处理中的错误,其关键原因,就是TO_CHAR 和TO_DATE的用法不清晰,,事实上,这两个东西也特别容易混 ...
- oracle 中 to_date 函数的用法
常犯错的使用方法. to_date('2019-08-12 22:05:','yyyy-MM-dd HH24:mm:ss') Oracle中会引起错误:"ORA 01810 格式代码出现两次 ...
- Oracle的字符替换函数translate用法
参考文档如下:http://www.banping.com/2009/05/18/oracle_function_translate/ Oracle提供了一个字符替换函数translate,不同于re ...
- ORACLE——NVL()、NVL2() 函数的用法
NVL和NVL2两个函数虽然不经常用,但是偶尔也会用到,所以了解一下. 语法: --如果表达式1为空则显示表达式2的值,如果表达式1不为空,则显示表达式1的值 NVL(表达式1,表达式2); --如果 ...
- oracle to_date函数和mysql DATE_FORMAT函数用法
一.在Oracle中,当想把字符串为‘2011-09-20 08:30:45’的格式转化为日期格式,我们可以使用oracle提供的to_date函数. sql语句为: SELECT to_date(' ...
随机推荐
- velocity #parse抽象重用部分组件
在某些时候,处于重用的目的,我们会选择将可以重用的部分内容剥离在单独的模板文件中,比如对于查询页面的表格部分,因为现在很多的条件可能是通过弹出查询框的方式来实现,而作为普通页面的时候,他们会有更多的功 ...
- Unix/Linux系统编程
一,开发工具 编译器 GCC 调试工具 GDB 代码编辑 Vim 1. 编译命令 gcc hello.c -o hello # 第二个hello为新生成的可执行文件名 -o 为生成的可执行文件指定名称 ...
- C++11 正则表达式——实例系统(转载)
一.用正则表达式判断邮箱格式是否正确 1 #include <regex> #include <iostream> #include <string> bool i ...
- git如何列出分支之间的差异commit
答:使用git log master..diff_master 这样就可以列出在diff_master分支中包含的commit而在master分支中不包含的commit
- Mybatis配置映射文件中parameterType的用法小结
原创: 在mybatis映射接口的配置中,有select,insert,update,delete等元素都提到了parameterType的用法,parameterType为输入参数,在配置的时候,配 ...
- DFS回溯-函数递归-xiaoz triangles
题目:小z 的三角形 ★实验任务 三角形的第1 行有n 个由"+"和"-"组成的符号,以后每行符 号比上行少1 个,2 个同号下面是"+", ...
- HDU 2586 How far away ?(LCA在线算法实现)
http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:给出一棵树,求出树上任意两点之间的距离. 思路: 这道题可以利用LCA来做,记录好每个点距离根结点的 ...
- neu 1694 Primorial vs LCM 数论
1694: Primorial vs LCM 时间限制: 4 Sec 内存限制: 128 MB[提交][状态][讨论版] 题目描述 Given N (2<=N<=10^14), what ...
- codeforces 350 div2 C. Cinema map标记
C. Cinema time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- python 集合的比较
setx = set(["apple", "mango"]) sety = set(["mango", "orange" ...