---
title: "哇哈哈啊 哈哈 哈哈哈 哈哈哈哈 哈哈哈哈哈 O(∩_∩)O哈哈~"
author: "yangy608"
date: "2010-04-27T10:11:05Z"
tags: []
categories: ["企业架构"]
slug: "o-o"
draft: false
lastmod: "2010-06-02T17:51:24Z"
id: 653908
url: "https://yangy608.iteye.com/blog/653908"
---

```
--找出一个表中重复的记录
select t.period_name from icms_recon_tb_check_tmp t group by t.period_name having count(*)>1 ; 
--删除一个表中重复的记录
delete from icms_recon_tb_check_tmp where rowid not in ( 
　　select max(t1.rowid) from icms_recon_tb_check_tmp t1 group by t1.model_type,t1.company_code);
--如果icas_base_company_t的company_code在bas.bas_organizations_t中不存在，
--将临时表icas_bas_organizations_t_tmp的数据更新到icas_base_company_t
update icas_base_company_t t1
   set t1.company_name = (select t2.company_name
                            from icas_bas_organizations_t_tmp t2
                           where t1.company_code = t2.company_code)
   where exists
        (select 1
            from icas_bas_organizations_t_tmp t2
            where t1.company_code = t2.company_code
         )
      
   and t1.company_code in
         (select t1.company_code
             from icas_base_company_t t1
             where not exists
                        (select t3.organization_coa_code
                             from bas.bas_organizations_t t3
                             where t1.company_code = t3.organization_coa_code
                         )
         );
```

```
commit;
```

```
1.不同用户之间的表数据复制 
对于在一个数据库上的两个用户A和B，假如需要把A下表old的数据复制到B下的new，请使用权限足够的用户登入sqlplus： insert into B.new(select * from A.old); 
如果需要加条件限制，比如复制当天的A.old数据 
insert into B.new(select * from A.old where date=GMT); 

2.同用户表之间的数据复制 
用户B下有两个表：B.x和B.y，如果需要从表x转移数据到表y，使用用户B登陆sqlpus即可： 
insert into y select * from x; 

3.B.x中个别字段转移到B.y的相同字段 
insert into y(字段1,字段2) select 字段1,字段2 from 

4.复制表结构 
create table 用户名.表名 as select * from 用户名.表名 where 1=2 

5.复制整个表
create table 用户名.表名 as select * from 用户名.表名
```

       insert into ICAS\_BAS\_ORGANIZATIONS\_T\_TMP (COMPANY\_CODE, COMPANY\_NAME)  
       values ('0441', 'Chengdu Huawei Storage '||chr(38)||' Network Security Co., Ltd.');

        ||chr(38)||为&