转换函数

转换函数
SQL关键字:to_char(日期,指定格式)
日期转换为指定格式的字符串。
示例:
SQL语句:select to_char(2019,'yyy') from dual;

字符串转为日期
SQL关键字:to_date(字符串,日期格式)

示例:
1、SQL语句创建表X:
create table x
(
rzdate date
);

2、SQL:查询select *from x;

1、 SQL语句插入日期:
SQL语句:insert into x(rzdate) values( to_date('20190822','yyyymmdd'));

注意:
1、 年为:yyyy
2、 月为:MM
3、 日为:DD

如下图所示:

单行函数

1、 NVL(x,value)
如果x为空,返回value,否则返回x。

select ename,sal,comm from emp where sal=(select sal from emp where ename='SCOTT')and comm=(select comm from emp where ename='SCOTT');

select ename,sal,comm from emp where sal=(select sal from emp where ename='SCOTT') and nvl(comm,0)=(select nvl(comm,0) from emp where ename='SCOTT');

posted @ 2020-11-21 19:38  ErShiXiong  阅读(251)  评论(0编辑  收藏  举报