oracle 数据库基本操作

1.1 查询select
1.2 插入insert  
    insert into table(column1,column2......) values (value1,value2......)
    插入中的字查询,不使用values子句,子查询中的列必须匹配insert语句中的列
    insert into table1(column1,column2......) select column1,column2...... from table2 where 条件
1.3 删除delete / truncate
        delete from table where 条件; truncate table;区别见oracle优化
1.4 修改update
    update table set column1 = value1,column2 = value2 ..... where 条件
1.5 合并merge
    把一个表中数据合并到另一个表中去,如果数据在原表中存在,则update,否则insert
    merge into tale1(目的表) table1_alias(目的表别名) using table2(数据来源) table2_alis(数据来源表别名)on (连接条件)
    when matched then update set (修改目的表) table1_alias.column = table2_alis.column
    when not matched then insert into  table1_alias values table2_alias.column
    eg:merge into products p using newproducts np on (p.product_id = np.product_id) when matched then update set p.product_name =              np.product_name when not matched then insert values(np.product_id, np.product_name, np.category)
       例子的含义是,是用两个表的product_id进行关联,然后根性product_name,其余如果源表数据不存在的话就直接插入到目的表中

1.6 提交commit 回滚rollback 与savepoint存储点配合使用,否则回滚到最初起始点
    eg:savepoint save_a; rollback to savepoint save_a;
1.7 创建表create 删除表drop
1.8 修改表alter
    增加列 alter table table_name add (column1_name datatype,column2_name datatype...)
    删除列 alter table table_name drop (column1,column2...)
    修改多列 alter table table_name modify (column1_name dataype,column2_name datatype...)
             alter table table_name rename column column1_name to column2_name
1.9 添加注释 comment
    comment on table tablename is '注释内容'  对表进行注释
    comment on column tablename.column_name is '注释内容' 对列进行注释
1.10 索引 index
    创建一个索引:create index index_name on table_name(column_name)
    删除一个索引:drop index index_name
1.11 集合 union
    union 使用两个表的并集,不显示重复行
    union all 使用两个表的并集,但是显示重复行
1.12 排序 order by
    只能放在整个集合的最后出现
1.13 分组查询 group by
    对将查询对象按一定条件分组,然后对每个组进行聚合分析


posted @ 2018-07-04 10:23  MoonSky007  阅读(96)  评论(0编辑  收藏  举报