n 搜索结果转换为小写
select lower(ename) from emp; //(函数lower() 将ename搜索出来后全部转化为小写);
n 截取子串
select substr(ename, 2, 3) from emp; //(使用函数substr() 将搜素出来的ename字段从第二个字母开始截,一共截3个字符)
n 字符ASC码转换
select chr(65) from dual; //(函数chr() 将数字转化为AscII中相对应的字符)
select ascii('A') from dual; //(函数ascii()与32中的chr()函数是相反的 将相应的字符转化为相应的Ascii编码)
n 四舍五入
select round(23.232) from dual; //(函数round() 进行四舍五入操作)
select round(23.232, 2) from dual; //(四舍五入后保留的小数位数, 0 个位 -1 十位)
select round(23.652,1) from dual; 结果为: 23.7
select round(23.652,-1) from dual; 20
n 货币操作
select to_char(sal, '$99,999.9999')from emp; //(加$符号加入千位分隔符,保留四位小数,没有的补零)
select to_char(sal, 'L99,999.9999')from emp; //(L 将货币转化为本地币种此处将显示¥人民币)
select sal from emp where sal>888.88 无错.但
select sal from emp where sal>$1,250,00;会出现无效字符错误. 改为:select sal from emp where sal>to_number('$1.250.00','$9,999,99');
n 日期操作
select to_char(hiredate, 'yyyy-MM-DD HH:MI:SS') from emp; //(改变日期默认的显示格式)
select to_char(sysdate, 'yyyy-MM-DD HH:MI:SS') from dual; //(用12小时制显示当前的系统时间)
select to_char(sysdate, 'yyyy-MM-DD HH24:MI:SS') from dual; //(用24小时制显示当前的系统时间)
select birthdate from emp;
显示为:
BIRTHDATE
----------------
17-12月-80
----------------
改为:
select to_char(birthdate,'YYYY-MM-DD HH:MI:SS') from emp;
显示:
BIRTHDATE
-------------------
1980-12-17 12:00:00
-------------------
select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') from dual; //也可以改为:HH12
TO_CHAR(SYSDATE,'YY
-------------------
2007-02-25 14:46:14
to_date函数:
select ename,birthdate from emp where birthdate > to_date('1981-2-20 12:34:56','YYYY-MM-DD HH24:MI:SS');
如果直接写 birthdate>'1981-2-20 12:34:56'会出现格式不匹配,因为表中的格式为: DD-MM月-YY.
n 替换空值
select ename,sal*12+nvl(comm,0) from emp; 这样可以防止comm为空时,sal*12相加也为空的情况.