`

存储过程练习_01

阅读更多
---公勉卡

create table c_accnbr_for_free
(
       segment_id number(9),
       segment_desc varchar2(50),
       acc_nbr      number(30),
       billing_mode varchar2(5),
       state        varchar2(5),
       region_id    number(5),
       region_name  varchar2(50),
       latn_id      number(5),
       latn_name    varchar2(50),
       serv_id      number(30),
       acct_id      number(30),
       single_serv_flag   number(1),
       nbr_type           number(1)
)


create table c_accnbr_for_free_bak as

select * from c_accnbr_for_free;


---重复数据
create table temp_20140526
as
select * from c_accnbr_for_free where acc_nbr in (select c.acc_nbr from
(select acc_nbr,count(*) from c_accnbr_for_free group by acc_nbr having count(*)>1) c);


--处理重复数据
1,4重复的取4
3,4重复的取4
1,3重复的取1

select * from temp_20140526 ;    --32- 1 / 2 =15

delete  from temp_20140526 where acc_nbr in(
select acc_nbr from temp_20140526 where nbr_type in(1,4) group by acc_nbr having count(*)>1) and nbr_type=1;       --26 (13)

delete  from temp_20140526 where acc_nbr in(
select acc_nbr from temp_20140526 where nbr_type in(3,4) group by acc_nbr having count(*)>1) and nbr_type=3;       --2  (1)

delete  from temp_20140526 where acc_nbr in(
select acc_nbr from temp_20140526 where nbr_type in(1,3) group by acc_nbr having count(*)>1) and nbr_type=3;       --2  (1)


select distinct acc_nbr from c_accnbr_for_free where acc_nbr in (select c.acc_nbr from
(select acc_nbr,count(*) from c_accnbr_for_free group by acc_nbr having count(*)>1) c);


select * from  temp_20140526 where acc_nbr=17008510004 for update;

select acc_nbr,count(*) from  temp_20140526 group by acc_nbr ;

--2478 - 32 + 15 = 2461


delete  from c_accnbr_for_free where acc_nbr in(select acc_nbr  from temp_20140526);    ---32

insert into c_accnbr_for_free
select * from temp_20140526;


select acc_nbr,count(*) from c_accnbr_for_free group by acc_nbr having count(*)>1;


---去重后备份
create table  c_accnbr_for_free_bak1
as
select * from c_accnbr_for_free;


create or replace procedure p_accnbr_for_free IS
       segmentId         NUMBER;
       segmentDesc       VARCHAR2(50);
       accNbr            NUMBER;
       billingMode       VARCHAR2(5);
       state              VARCHAR2(5);
       regionId           NUMBER;
       regionName         VARCHAR2(50);
       latnId             NUMBER;
       latnName          VARCHAR2(50);
       servId             NUMBER;
       acctId             NUMBER;
       singleServFlag   NUMBER;
       nbrType           NUMBER;
       v_1               NUMBER;
      
       str1 varchar2(500);
    

       cursor str_free is 
              select s.segment_id,c.acc_nbr, s.billing_mode, s.state, s.region_id, s.serv_id,c.nbr_type
               from c_accnbr_for_free c, serv s
               where c.acc_nbr = s.acc_nbr;

begin
     for f in str_free
         loop
               segmentId :=f.segment_id;
               segmentDesc :='';      ---重新提取
               accNbr :=f.acc_nbr;
               billingMode :=f.billing_mode;
               state :=f.state;
               regionId :=f.region_id;
               regionName :='';       --重新提取
               latnId :=0;            --重新提取
               latnName :='';         --重新提取
               servId :=f.serv_id;
               acctId :=0;            --重新提取
               singleServFlag :=-1;   --重新提取
               nbrType :=f.nbr_type;
              
               -- 转售商描述(segmentDesc)
               if segmentId is not null then
                  begin
                      execute immediate ' select partner_desc from emulatory_partner where party_role_id='||segmentId into segmentDesc;
                      exception when no_data_found then
                      segmentDesc :='';
                     
                  end;  
              
               end if;
              
               --地市名称(regionName)
               if regionId is not null then
                  begin
                      execute immediate ' select distinct region_name from region_latn where region_id='||regionId into regionName;
                      exception when no_data_found then
                      regionName :=''; 
                                    
                  end;
               end if;
              
               --省份编码(latnId),省份名称(latnName)
               if regionId is not null then
                  begin
                      execute immediate ' select distinct latn_id,latn_name from region_latn where region_id='||regionId into latnId, latnName;
                      exception when no_data_found then
                      latnId :=0; 
                      latnName :='';
                                    
                  end;
               end if;
               
               --帐户ID (acctId)
              if servId is not null then
                  begin
                      execute immediate ' select acct_id from serv_acct where state=''00A'' and serv_id='||servId into acctId;
                      exception when no_data_found then
                      acctId :=0; 
                                    
                  end;
               end if;
              
              
              --单设备标识( singleServFlag )
               if acctId is not null then
                  begin
                      execute immediate 'select  count(*)  from serv_acct where state=''00A'' and acct_id='||acctId into v_1;
                      if v_1=1 then
                         begin
                             singleServFlag :=1;
                         end;
                      elsif v_1 > 1  then
                         begin
                             singleServFlag :=0;
                         end;
                      else
                          begin
                             singleServFlag :=-1;
                          end; 
                      end if;

                      exception when no_data_found then
                      singleServFlag :=-1; 
                                    
                   end;
               end if;
              
              
               --更新数据
             execute immediate 'update c_accnbr_for_free set SEGMENT_ID='||segmentId||',
                                SEGMENT_DESC=TO_CHAR('''||segmentDesc||'''),
                                BILLING_MODE=TO_CHAR('''||billingMode||'''),
                                STATE=TO_CHAR('''||state||'''),
                                REGION_ID='||regionId||',
                                REGION_NAME=TO_CHAR('''||regionName||'''),
                                LATN_ID='||latnId||',
                                LATN_NAME=TO_CHAR('''||latnName||'''),
                                SERV_ID='||servId||',
                                ACCT_ID='||acctId||',
                                SINGLE_SERV_FLAG='||singleServFlag||'
                                WHERE NBR_TYPE='||nbrType ||'  AND ACC_NBR='||accNbr ;
              commit;
        
         end loop;           

end;           
      
      
      
      
      
       select  count(*)  from serv_acct where state='00A' acct_id=991100110000000183;
      
        select  count(*)  from serv_acct where state='00A' and acct_id=9;
      
       select * from serv_acct where serv_id=993100100000008370;
      
       select acct_id from serv_acct where state='00A' and serv_id=999000220000002914 ;
--------------------------------------------------------------------------

select count(*)  from c_accnbr_for_free where acc_nbr='17008760314';

       select
       acct_id,count(*)
        from serv_acct where serv_id in(
       select serv_id from serv where acc_nbr in(select acc_nbr from c_accnbr_for_free)
       )and state='00A'
       group by acct_id having count(*)>1;   
      
       993100100000008370
       997000630000003024
      
      
      
      

      
      
select *from offer_discount where offer_id in(134016712,134016718);


select * from balance_type




700


select * from c_accnbr_for_free where acc_nbr=17001040711;

select * from serv where acc_nbr=17001040711;


---在serv表不存在的用户
select acc_nbr,nbr_type from c_accnbr_for_free where acc_nbr not in(select acc_nbr from serv);     --1334

select count(*) from c_accnbr_for_free where billing_mode is not null;      --1128
---------------------





select * from staff;
select distinct staff_id from balance_source



--已执行
grant select on mvno_info.c_accnbr_for_free to MVNO_A_SN  ;
grant select on mvno_info.c_accnbr_for_free to MVNO_A_GM  ;
grant select on mvno_info.c_accnbr_for_free to MVNO_A_LY  ;
grant select on mvno_info.c_accnbr_for_free to MVNO_A_DXT ;
grant select on mvno_info.c_accnbr_for_free to MVNO_A_TY  ;
grant select on mvno_info.c_accnbr_for_free to MVNO_A_HJSJ ;
grant select on mvno_info.c_accnbr_for_free to MVNO_A_WWZC ;
grant select on mvno_info.c_accnbr_for_free to MVNO_A_JD  ;
grant select on mvno_info.c_accnbr_for_free to MVNO_A_LM  ;
grant select on mvno_info.c_accnbr_for_free to MVNO_A_LLKJ ;
grant select on mvno_info.c_accnbr_for_free to MVNO_A_CJT ;
grant select on mvno_info.c_accnbr_for_free to MVNO_A_FXZX ;
grant select on mvno_info.c_accnbr_for_free to MVNO_A_SWHL ;
grant select on mvno_info.c_accnbr_for_free to MVNO_A_CJSD ;
grant select on mvno_info.c_accnbr_for_free to MVNO_A_ASD ;


--已执行
create synonym MVNO_A_SN  .c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym MVNO_A_GM  .c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym MVNO_A_LY  .c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym MVNO_A_DXT .c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym MVNO_A_TY  .c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym MVNO_A_HJSJ .c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym MVNO_A_WWZC .c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym MVNO_A_JD  .c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym MVNO_A_LM  .c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym MVNO_A_LLKJ .c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym MVNO_A_CJT .c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym MVNO_A_FXZX .c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym MVNO_A_SWHL .c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym MVNO_A_CJSD .c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym MVNO_A_ASD .c_accnbr_for_free for mvno_info.c_accnbr_for_free;




create synonym   MVNO_A_SN.c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym   MVNO_A_GM.c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym   MVNO_A_LY.c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym   MVNO_A_DXT.c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym   MVNO_A_TY.c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym   MVNO_A_HJSJ.c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym   MVNO_A_WWZC.c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym   MVNO_A_JD.c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym   MVNO_A_LM.c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym   MVNO_A_LLKJ.c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym   MVNO_A_CJT.c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym   MVNO_A_FXZX.c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym   MVNO_A_SWHL.c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym   MVNO_A_CJSD.c_accnbr_for_free for mvno_info.c_accnbr_for_free;
create synonym   MVNO_A_ASD.c_accnbr_for_free for mvno_info.c_accnbr_for_free;



                 2014-06-22 1:08@yuqiaolu.pudongqu.shanghai.
分享到:
评论

相关推荐

    mysql存储过程_游标_项目练习

    通过实践这些练习,你可以深入理解存储过程和游标的用法,提高数据库编程技能。 总之,MySQL的存储过程和游标是数据库开发中的重要工具,它们提供了灵活的数据处理能力,使得我们可以更有效地管理和操作数据。通过...

    SQL Server 2005 存储过程练习

    里面建了十个存储过程,供初学者参考,很有价值

    练习_基于Oracle的存储过程.md

    这是基于Oracle的存储过程的小练习,大家可以参照着练习练习,下载一个Typora即可查看编辑

    PLSQL和存储过程练习

    根据给定的信息,我们可以深入探讨每个PL/SQL和存储过程练习的具体实现方法和技术要点。 ### 练习一:计算EMP表中的平均工资 这个练习的目标是编写一个PL/SQL程序块来计算`EMP`表中所有员工的平均工资。代码如下:...

    oracle存储过程练习题[收集].pdf

    本文档中提供的五个Oracle存储过程练习题,正好能帮助开发者加深对Oracle存储过程应用的理解和实践。 首先,创建用户和分配权限是Oracle数据库管理中的基础工作。通过创建特定的用户并为其分配适当的权限,可以确保...

    趣学8.5.1练习_长颈鹿乱舞_py入门练习_

    列表用于存储有序的数据集合,而字典则用于存储键值对。在练习中,你可能需要创建这些数据结构来模拟长颈鹿的行为模式,比如列表可以用来表示长颈鹿的不同舞步,字典可以用来关联每个舞步的名称和对应的动作。 文件...

    netapp存储配置练习_NFS

    NetApp 存储配置练习_NFS NetApp 存储基础学习汇总第四部分中,重点讲述了 NFS 管理的相关知识。NFS,全称 Network FileSystem,是由 Sun 公司所提出的,旨在让不同的计算机、不同的操作系统彼此分享档案(share ...

    netapp存储配置练习_volcopy

    ### NetApp 存储配置练习_volcopy 知识点详解 #### 一、volcopy 和 aggrcopy 概述 **Volcopy** 和 **Aggrcopy** 是 NetApp 存储系统中的两种重要的数据迁移工具,它们分别用于卷级别和聚合级别数据的复制。 - **...

    Oracle存储过程LP/SQL练习题(含答案)

    Oracle存储过程LP/SQL练习题(含答案) 几个练习题

    PL/SQL 的函数与存储过程练习

    PL/SQL 的函数与存储过程练习 PL/SQL 的函数与存储过程练习

    SQL server存储过程习题,SQL触发器习题.rar

    在SQL Server数据库管理系统中,存储过程和触发器是两种非常重要的数据库编程元素,它们对于数据库设计和数据管理具有深远的影响。下面将详细讲解这两个概念及其相关的知识点。 **SQL存储过程**: 1. **定义**:SQL...

    13.netapp存储配置练习_备份管理

    NetApp 存储配置练习与备份管理是IT领域中针对数据保护的重要环节。NetApp作为一家专注于存储解决方案的公司,其产品广泛应用于企业级数据中心,提供了高效的数据管理和备份功能。本部分将深入探讨如何利用NetApp...

    T-SQL语言存储过程练习题

    存储过程教学资料(含无输入参数、输入参数、输出参数等存储过程教学实例)方便练习!

    netapp存储配置练习_软件架构&网络管理

    NetApp 存储配置练习主要涉及软件架构和网络管理两个方面,其中重点介绍了NetApp存储的基础知识,包括其支持的存储协议、管理服务和软件架构的关键特性。下面将详细阐述这些知识点。 首先,NetApp存储支持多种协议...

    SQL经典练习题_sql练习_

    8. 存储过程(STORED PROCEDURE)和函数:预编译的SQL语句集合,可以提高效率和代码复用。 9. 视图:创建虚拟表,简化复杂查询并保护数据。 通过这些练习题,你可以深入理解SQL的工作原理,提高你的数据库操作技能...

    1-存储过程练习.pptx

    在XSCJ数据库中,我们可以通过以下几个练习来熟悉和掌握存储过程的创建、调用以及使用输出参数。 **练习1** 创建名为`pro_XS`的存储过程,用于查询学号为081101的学生信息。这个过程的创建语句可能如下: ```sql ...

    存储过程练习

    在IT行业中,数据库管理和操作是至关重要的部分,而存储过程是数据库系统中一个非常实用的特性,它允许程序员或数据库管理员预编译一系列SQL语句并封装在一起,以供重复调用,提高效率和代码的可维护性。本题涉及的...

    SQL练习题经典|初中高|含存储过程

    这个压缩包文件“SQL练习题经典|初中高|含存储过程”显然是一个全面的学习资源,适合那些希望从初级到高级逐步提升SQL技能的人。其中包含的练习题覆盖了SQL的核心概念和高级特性,特别是存储过程,这是一种在数据库...

    SQL存储过程试题及答案

    SQL存储过程试题及答案 SQL存储过程是数据库中的一种程序单元,能够完成特定的数据库操作。今天,我们将讨论三道关于SQL存储过程的试题,这些试题涵盖了存储过程的创建、调用和参数传递等方面。 1. 创建分数存储...

Global site tag (gtag.js) - Google Analytics