Oracle语句总结

1,开始以前先看张图sql

A表和B表是数据有重复部分的表,如今若是想获取A表中B表不存在的数据语句有两种:oracle

①. 使用left join ;[假设俩张表中都有共同字段id]spa

select a.id,b.id from A a left join B b on a.id = b.id where b.id is null table

②. 使用not in ;test

select a.id,b.id from a where a.id not in (select b.id from B b)效率

    综合两种的效率,第一种较快些,数据多的可选第一种,数据少就无所谓。date

2,操做数据的时候不免会遇到根据查询到的表数据来操做其余数据的需求,oracle知足了有根据sql语句直接建立表的须要。select

create table 表名 as 查询语句sql语句

egg:  create table student  as select * from test where id >10im

3,若是说表中的某一列数据有特殊的符号,而这些符号你不想要,好的,oracle知足你。

update 表名 set 列名=replace(列名,符号);

egg: 来个更新的语句【假设student表的id数据包含符号 '-'】:

update student set id = replace ( id , '-' );

4,数据多了,不免数字的一列有空值【注意这里的空值不是0】这时候若是把空值变为0,oracle也帮你想到办法啦。

update 表名 set 列名= nvl(列名,0);

egg: update student set money = nvl(money,0);

先这些吧,之后慢慢整理!

相关文章
相关标签/搜索