08 fonction à sens unique et le groupe de fonctions

Ce document présentera à la fonction entre linux. Linux fonction qui est divisée en fonction à sens unique et de fonctions, les fonctions de chaîne en fonction à sens unique, le numéro de fonction, fonction de date et d'autres fonctions, fonctions divisées en groupes MAX, MIN, AVG, somme, compte.

1 système, l'environnement et la prémisse de retenue

2 opération

  • 1 pour démarrer l'administrateur du système de ligne de commande cmd
    Pour démarrer l'administrateur système cmd

2, la fonction à sens unique

  • Fonctions de chaîne
# 在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;
  • fonction numérique
# 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;
  • Fonctions de date
# 获取当前日期
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;
  • autres fonctions
# 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, l'ensemble des fonctions

#查询公司的最高工资,最低工资,平均工资,总人数,工资总额
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);

Ceux-ci sont fonction à sens unique et un ensemble de fonctions entre l'oracle.

Je suppose que tu aimes

Origine www.cnblogs.com/alichengxuyuan/p/12577027.html
conseillé
Classement