zoukankan      html  css  js  c++  java
  • Oracle 常用操作

    一、表的常用操作

    1、全表插入,指定字段插入

    --全表插入
    insert into 表名  values(值1,值2,值3...);
    
    --指定字段插入
    insert into 表名(字段名1,字段名2,字段名3...)values(值1,值2,值3...);

    2、全表检索、指定字段检索

    --全表检索
    select * from 表名;
    
    --指定字段检索
    select * from 表名 where  条件;

    3、全表修改、加条件修改

    --全表修改
    update  表名 set 字段名 = 值;
    
    --加条件修改
    update  表名 set 字段名 =where 条件;

    4、全表删除、指定列删除

    --全表删除
    delete  表名;
    
    --指定列删除
    delete  表名 where 条件; 

    5、where 子句

      在表的常用操作中,通常是用来筛选的

    6、比较运算符

      >  大于

      <  小于

      =  等于

      <>(!=)  不等于

      >=  大于等于

      <=  小于等于

    7、and、or

    --and
    select * from 表名 where  条件1  and  条件2;
    
    --or
    select * from 表名 where  条件1  or  条件2;

    8、and or 配套使用

    --and or 配套使用
    select * from 表名 where  (条件1 and 条件2)  or  (条件3 and 条件4);

    9、between  and  在什么什么之间

    --between and    (在什么什么之间)
    select * from 表名  where  字段名 between  值1  and  值2;  

    10、Like  通常用来查找值里面是否包含什么元素

    --Like  
    select * from 表名 where 字段名  like '%元素%';

    11、In  通常用来判断值是否在列表中

    --In
    select * from 表名  wherein 字段名;

    12、Distinct  去重(除去字段中重复的值)

    --Distinct
    select distinct(要去重的字段名) from 表名;

    13、is null  /  is  not  null   (判断一个字段中的值是否为空)

    --is null    是为空
    select * from  表名  where  字段名  is null;
    
    --is not null  不为空
    select * from  表名  where  字段名  is not null;

    14、order by  子句   ( 排序 )

    --order  by  desc   单列降序
    select * from 表名 order by 字段名 desc;
    
    --order by  asc    升序
    select * from 表名 order by 字段名 asc;

    二、聚合函数

    1、max:取最大值

    2、min:取最小值

    3、avg:取平均值

    4、sum:取总和

    5、count:总条数

    6、group by :分组

    7、Having  :与where用法类似

    8、嵌套查询(子句查询)

    三、表连接

    1、inner join .....on

    内连接,结果为两个连接表中的匹配行的连接

    --join  on  (内联接,通常省去inner)
    
    select * from 表1 join 表2  on 表1中与表2连接的键 = 表2中与表1连接的键;

    2、left join.....on

    左连接:结果包括左表中的所有行,不包括右表中的不匹配行。

    -- left join ... on
    select * from 表1 left join 表2  on 表1中与表2连接的键 = 表2中与表1连接的键;

    3、right join ......on

    右连接:结果包括右表中的所有行,不包括左表中的不匹配的行。

    -- right join ... on
    select * from 表1 right join 表2  on 表1中与表2连接的键 = 表2中与表1连接的键;

    4、full join

    完全连接:结果包括所有连接中的所有行,不论他们是否匹配。

    5、cross join 

    交叉连接:结果包括两个联表中的所有可能的行组合。交叉联接返回的是两个表的笛卡尔积。

    6、natural join 

    自然连接时在两张表中寻找那些数据类型和列名都相等的字段,然后自动地将他们连接起来。

    四、外连接操作符

    (+)Oracle独占

    对与外连接,在Oracle中可以使用(+)来表示,使用的方式:

    1、(+)操作符只可以出项在where子句中,并且不可以和outer join语法同时使用。

    2、当使用(+)操作符执行外连接时,如果在where子句中包含多个条件,则必须在所有的条件中都包含(+)操作符。

    3、(+)操作符只能适用于列,而不能用在表达式上。

    4、(+)操作符不能与or和in操作符一起使用。

    5、(+)操作符只能用于现实左连接和右外连接,而不能用于实现外连接。

    --left join ...on    左连接    用(+)同样操作
    select * from 表1 = 表2(+);
    
    --right join ...on    右连接  用(+)同样操作
    select * from 表1(+= 表2;
  • 相关阅读:
    HDU 1800 Flying to the Mars 字典树,STL中的map ,哈希树
    字典树 HDU 1075 What Are You Talking About
    字典树 HDU 1251 统计难题
    最小生成树prim算法 POJ2031
    POJ 1287 Networking 最小生成树
    次小生成树 POJ 2728
    最短路N题Tram SPFA
    poj2236 并查集
    POJ 1611并查集
    Number Sequence
  • 原文地址:https://www.cnblogs.com/sloth-007/p/10707108.html
Copyright © 2011-2022 走看看