zoukankan      html  css  js  c++  java
  • oralce入门学习

    oracle的认识

    1.database数据库
    2.数据文件 :
       数据库的数据是存储在表空间中的,有多个文件组成
    3.表空间
        一个库被分为多个表空间,一个数据文件只能属于一个表空间

     sql数据库语言

    1.DML(数据库操作语言)
    其中包括insert,update,delete
    2.DDL(数据定义语言)
    数据操作语言,其语句包括create,drop,
    3.DCL(数据库控制语言)grant 或者 revoke来获得许可
    4.数据查询语言
    

    关键字distinct

    1.若是单行,就是单行不重复
    2.若是多行就是要多行都不重复才可以
    

    关键字null

    is not null
    is null
    

    连接符 | |

    比较运算符

    =  (等于不是== )
    >=
    <=
    <> 不等于(也可以是 !=)
    //其他的比较运算符
    between ...and 
    in
    like '%%'
    is null
    and 
    or 
    not 逻辑否
    

    排序

    1.在sql中可以使用 order by 或者order by desc
    2.对于排序中我们可能会遇到null值的问题
    --放到最前边
     SELECT * FROM emp order by sal nulls first;
     --放到最后边
     SELECT * FROM emp order by sal nulls last;
    

    单行函数

    1.字符
    2.通用
    3.转换
    4.日期
    5.数值
    

    字符函数 

    1.concat 也可以使用||
    2.substr
    select substr('hello',1,3) from dual;  --截取hel
    3.length()
    SELECT length('hel') FROM dual;
    4.字符串替换
    SELECT replace('hello','l','x') FROM  dual;
    

    数值函数

    5.数值函数
    1.ROUND 四舍五入 ROUND(45.926,2)
    2.TRUNC 截断 TRUNC(45.926,2)   45.92
    3.MOD 求余 MOD(1600,300) 100
    

    日期函数

    //1.获取两个时间段的月数
    select months_between(sysdate,hiredate) from emp;
    
    //2.获取几个月后的日期
    select add_months(sysdate,3) from dual;
    

    转换函数

    to_char(date,'YYYY-MM-DD')
    SELECT to_char(hiredate,'yyyy-mm-dd') from emp;
    SELECT to_char(hiredate,'fmyyyy-mm-dd') from emp; --可以去掉前导零
    
    to_char(number,'format_model')
    
    to_number
    select to_number('10')+to_number('10') from dual;
    
    to_date()
    select to_date('1985-04-22','yyyy-mm-dd') from dual;
    

    通用函数

    常用的通用函数
    NVL(expr1,expr2) -表示如实第一个值为空,就去第二个值
    NVL2(expr1,expr2,expr3) -- 如第一个值不为空,取第一个值,否则取第二个值
    
    -- nullif 表示如果第一个参数和第二个参数相等返回第一个值,否则返回第二个值
     select nullif(1,2) from dual;
    -- 遇到第一个非空值就返回
     select COALESCE(null,2,null,null,3,5) from dual;
    

    条件表达式

     select case ename 
            when 'SMITH' then '史密斯'
             when 'ALLEN' then '艾伦'
             else '张三'
      end            
    from emp          
    select decode(ename,'SMITH','史密斯','ALLEN','艾伦','张三') from emp; 
    

    多行函数

    什么是多行函数
    分组函数是作用于一组函数,并对于一组数据返回一个值
    AVG
    SUM
    MAX
    MIN
    COUNT
    --------------------------------------------
    分组函数 group by 
     SELECT deptno,count(ename),count(comm),avg(sal),max(sal) FROM emp group by deptno; 
    注意:
    1.如果使用分组函数,SQL只可以把group by 分组条件字段和分组函数查询出来
    2.如果使用分组函数,不使用GROUP BY 只可以查询出来分组函数的值
    
    where 和 having使用
    SELECT  SUM(sal) 
    FROM emp
     where sal>'2000'
    GROUP BY deptno
    HAVING SUM(sal)>8000  order by sum(sal) desc 
    
    -- 查询出工资在2000以上的分组求和 并且分组后要大于8000
    

      

      

     

     

     

  • 相关阅读:
    Using Resource File on DotNet
    C++/CLI VS CSharp
    JIT VS NGen
    [Tip: disable vc intellisense]VS2008 VC Intelisense issue
    UVa 10891 Game of Sum(经典博弈区间DP)
    UVa 10723 Cyborg Genes(LCS变种)
    UVa 607 Scheduling Lectures(简单DP)
    UVa 10401 Injured Queen Problem(简单DP)
    UVa 10313 Pay the Price(类似数字分解DP)
    UVa 10635 Prince and Princess(LCS N*logN)
  • 原文地址:https://www.cnblogs.com/liushisaonian/p/9652708.html
Copyright © 2011-2022 走看看