Oracle sql常用的查询函数

-- 去重: distinct
--利用当前emp表复制一份新表(包含数据):
create table emp2 as select * form emp;
-- 利用当前emp表复制一份新表(只复制表结构):
create teble emp3 as select * from emp where 1=2;
--表别名,拼接操作  'A'   ||    B   --> 将A拼接到B的前面:
select 'E' || e.empno eno , e.ename myName from emp e;
--replace()  替换操作:
select replace('hello','1','中') from dual; 
--length() 返回长度 :
select length('hellow world') from dual;
 --substr() 截取字符串:
select substr('123456') from fual;
--instr() :
select instr('hello world ','w','1','2') from dual;  (查找hello world 第2次出现w的数字位置)
--round() 不保留小数
select round(1000.1) from dual; -- 1000
--保留小数round ( 参数 , 保留几位小数 ):
select round(998.982, 2) from dual ; -- 998.98
--截取小数: trunc(n) 
--向上取整: cell(n)
--向下取整: floor(n)
--取余: mod(m,n) ==>m对n取余 

-- 日期函数
select sysdate from dual;
-- months_between返回两个日期间的月数
select months_between(sysdate,hiredate) from emp;
select hiredate from emp;
-- add_months() 返回所加月数后的最后日期
select add_months(sysdate,3) from dual;
-- next_day返回下一个星期的星期几
select next_day(sysdate,'星期一') from dual;
-- last_day() 返回日期中的最后一天
select last_day(sysdate)from dual;

/*
转换函数
*/
-- to_char
select to_char(sysdate,'YYYY') from dual;
select to_char(e.hiredate,'YYYY-mm-dd hh24:mi:ss dy') from emp e;
-- 数字转换
select to_char(123456,'999999')from dual;  -- 123456
select to_char(123456,'99')from dual;  -- ###
select to_char(123456,'L999999')from dual; --  ¥123456
select to_char(123456,'$999999')from dual;  --  $123456
select to_char(123456,'0999999')from dual;  --  0123456

-- to_date 将字符转换为日期,多用于更新表
update emp e set e.hiredate=to_date('2008-08-12','yyyy-mm-dd')
-- to_number 将数字的字符串类型转换为数字类型
select to_number('09') + to_number('10') from dual; -- 19
-- nvl() nvl2() coalese

Oracle中的 nvl() ,nvl2(), coalese()函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

咻的一下飞过去

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值