08 one-way function and the function group

This paper will present at the function among linux. linux function which is divided into one-way function and group functions, string functions into one-way function, the function number, date function and other functions, functions divided into groups max, min, avg, sum, count.

1 system, the environment and the premise of restraint

2 operation

  • 1 to start the system administrator cmd command line
    To start the system administrator cmd

2, one-way function

  • String Functions
# 在windows命令行下连接scott
sqlplus scott/tiger
# length 求字符串长度,其中dual是伪表
select length('zhangli') from dual;
# instr 找子串的下标
select instr('zhangli','ang') from dual;
# initCap 首字符变大写
select initCap('zhangli') from dual;
# lower 变小写
select lower('ZHangli') from dual;
# upper 变大写
select upper('zhangli') from dual;
# replace 替换
select replace('zhangli','ang','ANG') from dual;
# trim 去前后空格
select trim('  zhangli  ') from dual;
# concat 拼接
select concat('zhang','li') from dual;
# lpad 左拼接
select lpad('zhangli',10,'#') from dual;
# rpad 右拼接
select rpad('zhangli',10,'#') from dual;
  • Digital function
# round 四舍五入
select round(3.141592,4) from dual;
# trunc 截断
select trunc(3.1415,2) from dual;
# 向下取整
select floor(3.14) from dual;
# 向上取整
select ceil(3.14) from dual;
# 取模[取余数]
select mod(10,3) from dual;
  • Date Functions
# 获取当前日期
select sysdate from dual;
# 将日期转化为字符串
select to_char(sysdate,'yyyy-mm-dd') from dual;
# 将字符串转化为日期
select to_date('2008-08-08' , 'yyyy-mm-dd') from dual;
# 求两个日期的差
select sysdate-to_date('2008-08-08' , 'yyyy-mm-dd') from dual;
# 求本月的最后一天
select last_day(sysdate) from dual;
  • Other functions
# nvl  只有两个参数,取最左边不为空的
select nvl(null,'ali') from dual;--打印ali
select nvl('zhangl','xiaoli') from dual;--打印zhangli
# nvl2 三个参数,第一个参数是表达式,如果第一个参数为空则取第二个参数,否则取第三个参数
select nvl2('zhangli','hello','world') from dual; --打印hello
select nvl2(null,'hello','world') from dual; --打印world
# coalesce 两个以上参数,取第一个不为空的
select coalesce (null,null,null, 123) from dual; --取123
select coalesce ('zhangli',null) from dual; --取zhangli
# decode 判断
select decode('zhangli','zhangli',4,'xiaoli',5) from dual;--获得4
select decode('xiaoli','zhangli',4,'xiaoli',5) from dual;--获得45
# case when then end 判断
select case sal 
  when 3000 then '叁仟'
  when 5000 then '伍仟'
  end from emp;

3, the set of functions

#查询公司的最高工资,最低工资,平均工资,总人数,工资总额
select max(sal), min(sal),avg(sal),count(1),sum(sal) from emp;
#查询公司每个部门的最高工资,最低工资,平均工资,总人数,工资总额
select deptno, max(sal), min(sal),avg(sal),count(1),sum(sal) from emp group by deptno;
# 查询公司30部门的最高工资,最低工资,平均工资,总人数,工资总额
select deptno, max(sal), min(sal),avg(sal),count(1),sum(sal) from emp group by deptno having deptno=30;
#打印工资最高的员工的信息
select * from emp where sal >=(select max(sal) from emp);

These are one-way function and a set of functions among the oracle.

Guess you like

Origin www.cnblogs.com/alichengxuyuan/p/12577027.html