Oracle语句总结

1,开始之前先看张图

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

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

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

②. 使用not in ;

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

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

2,操作数据的时候难免会遇到根据查询到的表数据来操作其他数据的需求,oracle满足了有根据sql语句直接创建表的需要。

create table 表名 as 查询语句

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

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);

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

评论

暂无评论