• Oracle 数据库基本操作——表操作:查询


    目录:

    1、基本查询

    2、多表查询

    3、多行查询

    4、集合查询

    2、连接

    3、嵌套查询


    1、基本查询

    语法:

    select column|others{,columnName|others}

      from tablename
        where condition
          [group by 分组的条件
            having 分组以后的条件
              order by 排序显示  ]

    起别名: select columnName [ [as] otherName ] {,columnName [ [as] otherName ] }
          from ......


    例子:

    别名:select employ_id 员工编号, first_name||' '||last_name 姓名, to_char(hire_date,'YY-MM') 雇佣日期
        from employee where salary >=10000;

    between:        ... where salary between NUMBER and NUMBER;
    like:         ... where first_name like  'Sa%';
    upper()/lower(): ... where upper(first_name) like upper('p%');

    &窗口录入查询:  ... where upper(first_name) like upper('&录入的字段%');

    null :       .... where memo is [not] null; 

    nvl(columnName,Num):      如果columnName为非null的值,得到原来的值; 如果为null ,得到 Num;

    nvl2(columnName,Num1,Num2):  如果columnName为非null的值,得到Num1, 如果为null ,得到 Num2;


         select salary+commision_pct*salary 实际工资 from employee; // 如果commision_pct为null 结果为null
         select salary+nvl(commision_pct,0)*salary 实际工资 from employee; //结果正常

    substr(str,start_index,length):  取子字符串

    decode(variable,case_1,'code_1',case_2,'code_2','default'):对变量variable的各种情况编码,case_1=》'code_1' 等;

        select to_date(substr('445281199509192110',7,8),'YYYYMMDD'),

             decode(mode(to_number(substr('445281199509192110')),2),0,'女',1,'男') from dual;

    注意:Select * from .... 中 * 最好不用,花费代价太大(当数据量巨大时)

    2、连接

    3、嵌套查询:


    4、集合查询

  • 相关阅读:
    【SDOI2019】—世界地图(虚树+Kruscal)
    【SDOI2019】—世界地图(虚树+Kruscal)
    【SDOI2019】—热闹的聚会与尴尬的聚会(图论)
    【SDOI2019】—热闹的聚会与尴尬的聚会(图论)
    【BZOJ3153】—Sone1(Top-Tree)
    【BZOJ3153】—Sone1(Top-Tree)
    【UOJ #284】— 快乐游戏鸡(长链剖分+线段树)
    【UOJ #284】— 快乐游戏鸡(长链剖分+线段树)
    【BZOJ4372】—烁烁的游戏(动态点分治)
    【BZOJ4372】—烁烁的游戏(动态点分治)
  • 原文地址:https://www.cnblogs.com/BensonLaur/p/5650263.html
Copyright © 2020-2023  润新知