oracle-DML-2

1.update 语句

   update  table set  [column,column......] where  column =''

   示例: update   customers

            set   cust_credit_limit = 20000

           where   cust_id = 2789;

2.delete 语句

   delete from table where  条件

   示例; delete from customers

           where cust_state_province = 'QT';

  备注;truncate customers 也可以删除该表的所有记录,但是它在出错不允许回滚的

3.数据排序

  order by

  示例: select cust_id,cust_state_province, cust_credit_limit

         from customers

         where cust_credit_limit = 15000

         and cust_state_province  in ('QT','CT')

         order by cust_state_province ,cust_id ;

  备注:oracle 默认的是按照升序排序,如果需要降序就 要在排序字段后面添加desc

  示例:select cust_id ,cust_state_province,cust_credit_limit

          from  customers

          where cust_credit_limit =15000

          and cust_state_province in  ('UT','CT')

          order by cust_state_province ,cust_id desc

4.group by

    group by 主要是分组 来进行求和 或者其它运算

    示例:select prod_subcategory,avg(amout_sold)

            from sales s ,products p

            where s.prod_id = p.prod_id

            and prod_category = 'Electronics'

            group by prod_subcategory ;

5.having

   在对group by 操作的使用having 字句可以限制返回的组

   示例:select prod_subcategory,avg(amout_sold)

            from sales s ,products p

            where s.prod_id = p.prod_id

            and prod_category = 'Electronics'

            group by prod_subcategory

            having avg(amout_sold) > 300;

6.子查询

   sql 一个强大功能就是创建子查询,即查询中嵌套查询。这一功能使得基于另一结果或者其他结果集进行查询成为可能

   示例:

      select prod_id ,prod_name ,prod_category

      from products

     where  prod_list_price  =

     (

         select  max(prod_list_price) from products

     );

7:集合操作

    union 返回两表中无任何重复的所有行

     示例:select * from x

             union

              select *from y

      union all 返回两表中所以行(包含重复)

     示例:select * from x

             union all

             select *from y

     intersect 返回两表中都存在的行

     示例:select * from x

             intersect

             select *from y

   

原文地址:https://www.cnblogs.com/linsu/p/orace.html