gongyu

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

1、用非空列 修改 空列

update z_taxidriver 

set  mobile=zzdh

where mobile is null and zzdh is not null

 

2、用全外连接  创建 一个 表格 ,表格的某列中取一定范围的值 

create table c as

select a.1 a.2 b.1 b.2 

from  a  full outer join b

 on    a.3=b.3  and a.1 in (' ',' ');

3、给某字段 增加部分内容

upadte a set a.1=concat('nihao',a.1)  

concat(str1,str2,str3,...)   有文章介绍 oracle 只能连接两个,没有尝试

   删除某部分内容

update a set a.1=replace(a.1,'你好','')

REPLACE ( ''string_replace1'' , ''string_replace2'' , ''string_replace3'' )    
     用第三个表达式替换第一个字符串表达式中出现的所有第二个给定字符串表达式。

 

4、根据一个表格的某个字段 去修改另一个表格的某个字段( 作为依据的表格 ,每行应该是唯一的,要不然标准不能确定) 

update  z_table1

set z_table1.a=(select  z_table2.a from z_table2 where z_table2.b=z_table1.b);

注意 :而不是直接的  set z_table1.a=z_table2.a  from z_table2    oracle 报错 ,不知道别的能不能成功。

 

5、对比两个 表格  找出其中不相同的 项 

select * from a where not exists(select * from b where a.col_a=b.col_a and a.col_b=b.col_b) union select * from b where not exists(select * from a where a.col_a=b.col_a and a.col_b=b.col_b)

以上得出两表中所有不同记录(a表中第三条,b表中3、4条)

 6、删除 某列长度不符合要求的行 ,注意 空格项无法去掉

delete from z_chezhu where  length(z_chezhu.mobile)!=11;      //有的地方也提示说用len  在oracle 中这个是不好用的。

 

7、多张表  合并 为 一张  ,要求具有相同的结构 列 ,union :删除重复的列 ,union all: 保留重复的列

   create table c  as

  select * from table_a  union select * from table_b

 

   insert into  A  select * from B (两者具有相同的结构,不然要表示出转移的列名)(重复列也全部移入)

   insert into  A  select * from B union select * from C (重复列不移入)

    insert into  A  select * from B union  all  select * from C (重复列也全部移入)

8、一个表格修改列名 

  在sqlserver 中 ,exec  sp_name 'table1.oldname','newname','column'   

  在oracle  中 ,alter table table1 rename column oldname to newname

9、查找表格的重复行  

    全部重复的行

   部分重复的行 

   select * from taxiinfo_stqb a
   where a.czcph in( select czcph from taxiinfo_stqb group by czcph having count(czcph)>1)
    order by a.czcph

   

posted on 2014-07-10 08:33  gongyu  阅读(602)  评论(0编辑  收藏  举报