赞
踩
sql结构化查询语言,希望初学者共勉基础
数学函数
--1. abs 取绝对值
select abs(-99) from dual; -- 99
--2. ceil 向上取整
select ceil(3.14) from dual; -- 4
--3. floor 向下取整
select floor(9.98) from dual; -- 9
--4. power 求幂
select power(2,3) from dual; -- 8
--5. mod 取模(取余)
select mod(13,3) from dual; --1
--6. round 四舍五入
select round(3.5) from dual; -- 4
--7. trunc 截取小数位数
select trunc(3.1415926,2) from dual; -- 3.14
日期函数
1.查询当前的系统日期 select sysdate from 表名; 2.查询两个日期之间的月份间隔数 MONTHS_BETWEEN() select floor(MONTHS_BETWEEN(sysdate,'08-6月-18')) from 表名; --从2018年6月18号到现在过了多少个月 3.返回在指定的日期上加或减指定的月份数 add_months() select add_months(sysdate,-6) from 表名; -- 返回6个月前的日期 4.返回指定日期后的指定星期数的日期 next_day() select next_day(sysdate,'星期日') from 表名; -- 查下一个星期日是几月几号 5.返回指定日期所在的月份的最后一天的日期 last_day() select last_day(sysdate) from 表名; 6.将日期转换为字符串格式 to_char() select to_char(sysdate) from 表名; 7.将字符串转换为日期格式 to_date() 8.按指定格式对日期进行四舍五入 round()
聚合统计函数
max() 求最大值
min() 求最小值
avg() 求平均值
sum() 求总和
count() 求记录数(即多少条数据)
转换函数
1.to_number()
字符串转换为数字 (现版本支持字符串隐式转换为数字)
select '3.14'+5.26 from dual;
select to_number('3.14')+5.26 from dual;
2.to_char
数字转换字符number--->char
-- 使用9作用占位符,例如转换格式为$999,999,999
select to_char(156146512,'$999,999,999,999') from dual;
-- L表示人民币符号,$表示美元符号
select to_char(156146512,'L999,999,999') from dual; -- ¥$ shift+4
-- 填充0, 不足的部分依然显示为0
3. nvl()对null 值进行转换 注意:有的数据库不支持
增、删、改
insert into 表名(字段名) values(...,'','');
delete from 表名 where 字段名;
update 表名 set dname='设计部' where deptno=50 ;
数学函数
--1. abs 取绝对值
select abs(-99) from dual; -- 99
--2. ceil 向上取整
select ceil(3.14) from dual; -- 4
--3. floor 向下取整
select floor(9.98) from dual; -- 9
--4. power 求幂
select power(2,3) from dual; -- 8
--5. mod 取模(取余)
select mod(13,3) from dual; --1
--6. round 四舍五入
select round(3.5) from dual; -- 4
--7. trunc 截取小数位数
select trunc(3.1415926,2) from dual; -- 3.14
日期函数
1.查询当前的系统日期 select sysdate from 表名; 2.查询两个日期之间的月份间隔数 MONTHS_BETWEEN() select floor(MONTHS_BETWEEN(sysdate,'08-6月-18')) from 表名; --从2018年6月18号到现在过了多少个月 3.返回在指定的日期上加或减指定的月份数 add_months() select add_months(sysdate,-6) from 表名; -- 返回6个月前的日期 4.返回指定日期后的指定星期数的日期 next_day() select next_day(sysdate,'星期日') from 表名; -- 查下一个星期日是几月几号 5.返回指定日期所在的月份的最后一天的日期 last_day() select last_day(sysdate) from 表名; 6.将日期转换为字符串格式 to_char() select to_char(sysdate) from 表名; 7.将字符串转换为日期格式 to_date() 8.按指定格式对日期进行四舍五入 round()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。