zoukankan      html  css  js  c++  java
  • Oracle基本功能练习

    --选取整个表的列
    select * from emp;
    --选取指定列的内容
    select job from emp;
    select ename,sal from emp;
    --条件判断 
    select sal from emp
      where sal=800;
    --between and 方法
    select * from emp
      where  sal between 2000 and 3000;
    --嵌套的使用
    select job from 
      (select * from emp
         where  sal between 2000 and 3000);
    --单列数据的改变     
    select sal+25 from emp;
    --用like(模糊)概念  (-一个字符) (% 0个或多个字符)
     select job from emp
       where job like '%LE%';
    --从in()里面的数据选出   
     select * from emp
       where comm in(300,500);
    select sal,sal+25.00 AS saly from emp;
    --字符串的连接   AS别名   将job换成ta
    select empno,empno+25||'is a '||job AS ta from emp;
    --删除重复行 关键词DISTINCT
     select DISTINCT comm from emp;
    --用IS NULL 关键字判断为空的情况
     select * from emp
       where comm IS NULL;
     select comm from emp
       where comm IS NULL;
     
      
    select sal,sal AS saly from emp;
    --求某列的平均值
    select * from emp;
    --
    select sal AS nb from emp;
    --排序  默认升序 asc   就近原则
    select * from emp  order by empno,sal;
    --降序  desc
    select * from emp  order by sal desc;
    --concat 连接 ||
    select concat('hello','nihao')  from dual;
    select empno,empno+25||'  is a '||job AS ta from emp;
    --把该字段全部变为小写
    select lower(ename) from emp; 
    --首字母大写
    select initcap(ename) from emp;
    --全部大写
    select upper(ename) from emp;
    --substr  选取指定位置  dual 虚表
    select substr('hello',2,5)  from dual;
    --instr 指定字母的位置
    select instr('hkjhdkk','j') from dual;
    --替换指定的字母
    select replace('jlkdj','j','') from dual;
    --trim 去掉前后空格
    select trim('  derf   ')  from dual;
    --取余 mod  ; round 四舍五入  round(222.325,2)  数字,保留位数
    
    select mod(254,12) from dual;
    --截断 trunc  负数表示整数部分
    select trunc(5125.2545,-2) from dual;
    --获取当前日期
    select sysdate from dual;
    select * from emp;
    --日期可以相加减
    select round((sysdate-hiredate)/7,1) from emp;
    --选择日期在之间的数值 以降序排出
    select * from emp
       where  hiredate  between '02-1月-81' and '02-1月-91' order by  hiredate desc;
     --用每个* 东西在前面补够8位    lpan  前面补; rpan 后面补
    select lpad(ename,8,'*')ename  from emp;
    --用现在的日期减去所选日期    日期只能减
    select (sysdate-hiredate)/365 from emp;
    --两个日期相差的月数
    select months_between(hiredate,sysdate)  from emp;
    --向指定日期加上若干个月
    select add_months(hiredate,34) from emp;
    --last_day 本月的最后一天
    select last_day(hiredate) from emp;
    --系统日期 四舍五入年 、月   不能日
    select round(sysdate,'year') from dual;
    select round(sysdate,'month') from dual;
    --截取年、月     不能日   
    select hiredate,trunc(hiredate,'year') from emp;
    select hiredate,trunc(hiredate,'month') from emp;
    select hiredate,add_months(hiredate,7) from emp;
    --替换
    select sal,replace(sal,'1','5')  from emp;
    --next_day 指定日期的下一天   
    select next_day(sysdate,'星期一') from dual;
    --以固定格式输出
    select to_char(sysdate,'yyyy') from dual; 
    select to_char(sysdate,'yyyy-mm-dd') from dual; 
    --输出数字以固定格式
    select to_char(sal,'999,999,999') from emp; 
    --返回日期     周天是1
    select sysdate,to_char(sysdate,'d') from dual;
    --返回数字
    select to_number(12*12+25) from dual;
    --以固定格式输出指定的日期
    Select to_date('2015126','yyyyMMdd') from dual;
    --返回表的行数(元组)  如果表没有数据则返回为null 而不是0
    select count(*) from emp;
    select count(*) from dept;
    select * from emp;
    --找出每月倒数第几天
    select * from emp where last_day(hiredate)-2=hiredate;
    --排序sal  降序
    select * from emp order by (sal) desc;
    

      

  • 相关阅读:
    使用hadoop平台进行小型网站日志分析
    flume分布式日志收集系统操作
    map-reduce任务的执行流程
    linux设置定制器自动执行任务
    pig笔记
    hive操作记录
    hbase集群安装和shell操作
    Spark Streaming揭秘 Day24 Transformation和action图解
    Spark Streaming揭秘 Day23 启动关闭源码图解
    Spark Streaming揭秘 Day22 架构源码图解
  • 原文地址:https://www.cnblogs.com/xuekai/p/7162133.html
Copyright © 2011-2022 走看看