create or replace procedure find_difference(db_link in varchar2) is
/*
比对两套环境建表脚本差异,以224环境为主
当前环境,dblink环境
中间表middle记录当前环境比224环境少的表字段,及差异字段
create table middle as select table_name,column_name,data_type,data_length,nullable ,' ' as note
from user_tab_columns where 1 = 2 ;
create table logs(id number , table_name varchar2(80)) ;
*/

j number default 0;
v_count number default 0;
v_count_local number default 0;
v_sql varchar2(4000);
v_table1 number default 0;
v_table2 number default 0;
begin
-- 创建中间表/清楚上次数据
select count(1) into v_table1 from user_tables where table_name = 'MIDDLE';
if v_table1 = 0 then
execute immediate ' create table middle as select table_name,column_name,data_type,
data_length,nullable ,'' '' as note from user_tab_columns where 1 = 2 ';
else
delete from middle;
commit;
end if;

select count(1) into v_table2 from user_tables where table_name = 'LOGS';
if v_table2 = 0 then
execute immediate 'create table logs(id number , table_name varchar2(80))';
else
delete from logs;
commit;
end if;

declare
TYPE middle_type IS TABLE OF middle%rowtype INDEX BY BINARY_INTEGER;
v_middles middle_type;
v_211 middle_type;
v_middles_local middle_type;
begin
--比对dblink环境多的,以及差异字段
execute immediate ' select table_name,
column_name,
data_type,
data_length,
nullable,
''_''
from user_tab_columns@'||db_link||'
order by table_name, column_name' bulk collect into v_middles;

for i in v_middles.first .. v_middles.last loop

j := j + 1;
insert into logs values (j, v_middles(i).table_name);
commit;

select count(1)
into v_count
from user_tab_columns
where table_name = v_middles(i).table_name
and column_name = v_middles(i).column_name;

if v_count = 0 then
insert into middle
values
(v_middles(i).table_name,
v_middles(i).column_name,
v_middles(i).data_type,
v_middles(i).data_length,
v_middles(i).nullable,
'当前环境无');
commit;
continue;
end if;
--比对差异字段
select table_name,
column_name,
data_type,
data_length,
nullable,
'' bulk collect
into v_211
from user_tab_columns
where table_name = v_middles(i).table_name
and column_name = v_middles(i).column_name;

if v_211(v_211.first).data_type <> v_middles(i).data_type or v_211(v_211.first)
.data_length <> v_middles(i).data_length or v_211(v_211.first)
.nullable <> v_middles(i).nullable then
insert into middle
values
(v_middles (i).table_name,
v_middles (i).column_name,
v_middles (i).data_type,
v_middles (i).data_length,
v_middles (i).nullable,
'difference');
commit;
continue;
end if;
end loop;

--比对当前环境多出字段
select table_name,
column_name,
data_type,
data_length,
nullable,
'' bulk collect into v_middles_local
from user_tab_columns
order by table_name, column_name;

for i in v_middles_local.first .. v_middles_local.last loop

j := j + 1;
insert into logs values (j, v_middles_local(i).table_name);
commit;
execute immediate 'select count(1) from user_tab_columns@'||db_link||' where table_name = :1 and column_name = :2 '
into v_count_local
using in v_middles_local(i).table_name , in v_middles_local(i).column_name ;

if v_count_local = 0 then
insert into middle
values
(v_middles_local(i).table_name,
v_middles_local(i).column_name,
v_middles_local(i).data_type,
v_middles_local(i).data_length,
v_middles_local(i).nullable,
db_link||'环境无');
commit;
continue;
end if;
end loop;

end;

end find_difference;

CREATE OR REPLACE PROCEDURE BJ_G.zj_msisdn_to_file_whq IS
handle utl_file.file_type;
TYPE ref_cursor_type IS REF CURSOR;
ref_cursor ref_cursor_type;
v_msisdn VARCHAR2(15);
FILE_NAME VARCHAR2(40);
v_sql varchar2(2000);
tk_id varchar2(20);
cc varchar2(20);
cursor user_name is
select * from temp_whq1;
type tablename is ref cursor;
tablenamel tablename;
BEGIN
for i in user_name loop
select i.taskid into tk_id from dual;
select i.prov_sh into cc from dual;
FILE_NAME := cc||'.txt';
handle := UTL_FILE.FOPEN('AA', FILE_NAME, 'w');
v_sql:='select c_msisdn from (select c_msisdn,count(*) c1,c_smscount c2 from '||cc||'.t_batch_mt
where C_taskid = '||tk_id||' and C_actiontype = 3 and C_status = ''0''
group by c_msisdn,c_smscount) where c1>=c2 intersect
select c_msisdn from '||cc||'.t_batch_mt where C_taskid = '||tk_id||' and C_actiontype = 9 and C_status = ''0''';
open ref_cursor for v_sql;
LOOP
FETCH ref_cursor
INTO v_msisdn ;
EXIT WHEN ref_cursor%NOTFOUND;
UTL_FILE.put_line(handle,
v_msisdn );
END LOOP;
UTL_FILE.fclose(handle);
close ref_cursor;
end loop;
end;
/

declare
cursor user_name is select prov_name,prov_sh from t_province;
aa varchar2(15);
bb varchar2(15);
begin
for i in user_name loop
select i.prov_name into aa from dual;
select i.prov_sh into bb from dual;
execute immediate 'insert into mytemp33 select '||''''||aa||''''||
',count(case when a.c_regtime>=to_date(''20150101'',''yyyymmdd'') and a.c_regtime<to_date(''20150201'',''yyyymmdd'') then a.c_msisdn else null end) 一月,
count(case when a.c_regtime>=to_date(''20150201'',''yyyymmdd'') and a.c_regtime<to_date(''20150301'',''yyyymmdd'') then a.c_msisdn else null end) 二月,
count(case when a.c_regtime>=to_date(''20150301'',''yyyymmdd'') and a.c_regtime<to_date(''20150401'',''yyyymmdd'') then a.c_msisdn else null end) 三月,
count(case when a.c_regtime>=to_date(''20150401'',''yyyymmdd'') and a.c_regtime<to_date(''20150501'',''yyyymmdd'') then a.c_msisdn else null end) 四月,
count(case when a.c_regtime>=to_date(''20150501'',''yyyymmdd'') and a.c_regtime<to_date(''20150601'',''yyyymmdd'') then a.c_msisdn else null end) 五月,
count(case when a.c_regtime>=to_date(''20150601'',''yyyymmdd'') and a.c_regtime<to_date(''20150701'',''yyyymmdd'') then a.c_msisdn else null end) 六月,
count(case when a.c_regtime>=to_date(''20150701'',''yyyymmdd'') and a.c_regtime<to_date(''20150801'',''yyyymmdd'') then a.c_msisdn else null end) 七月,
count(case when a.c_regtime>=to_date(''20150801'',''yyyymmdd'') and a.c_regtime<to_date(''20150901'',''yyyymmdd'') then a.c_msisdn else null end) 八月,
count(case when a.c_regtime>=to_date(''20150901'',''yyyymmdd'') and a.c_regtime<to_date(''20151001'',''yyyymmdd'') then a.c_msisdn else null end) 九月,
count(case when a.c_regtime>=to_date(''20151001'',''yyyymmdd'') and a.c_regtime<to_date(''20151101'',''yyyymmdd'') then a.c_msisdn else null end) 十月
from '||bb||'.alluserinfo a';
commit;
end loop;
end;

CREATE OR REPLACE PROCEDURE BJ_G.wu_msisdn_to_file_HP IS
handle utl_file.file_type;
TYPE ref_cursor_type IS REF CURSOR;
ref_cursor ref_cursor_type;
v_msisdn VARCHAR2(15);
FILE_NAME VARCHAR2(40);
v_sql varchar2(2000);
cursor user_name is select * from t_province where prov_sh in (select prov_sh from temp_08);
aa varchar2(10);
bb varchar2(10);
cc varchar2(10);
begin
for i in user_name loop
select i.prov_id into aa from dual;
select i.prov_name into bb from dual;
select i.prov_sh into cc from dual;
FILE_NAME := bb||'.txt';
handle := UTL_FILE.FOPEN('AA', FILE_NAME, 'w');
if cc not in ('HN_G','HEB_G','HUBEI_G','JL_G','YN_G','SHAN_G','ZJ_G','CQ_G','FJ_G','GZ_G','HLJ_G','XJ_G') then
v_sql :='select distinct c_msisdn from '||cc||'.t_batch_mt where (c_status!=''0'' or c_status is null)
and c_taskid in (select taskid from temp_08 where prov_sh='||''''||cc||''''||')';
else
v_sql :='select distinct c_msisdn from '||cc||'.t_batch_mt where (c_status!=''0'' or c_status is null)
and c_taskid in (select taskid from temp_08 where prov_sh='||''''||cc||''''||')
and c_msisdn not in (select c_msisdn from '||cc||'.t_batch_mt where c_status in
(select taskid from temp_07 where prov_sh='||''''||cc||''''||'))';
end if;
open ref_cursor for v_sql;
LOOP
FETCH ref_cursor
INTO v_msisdn ;
EXIT WHEN ref_cursor%NOTFOUND;
UTL_FILE.put_line(handle,
v_msisdn );
END LOOP;
UTL_FILE.fclose(handle);
end loop;
end;
/

--按日统计
CREATE OR REPLACE PROCEDURE LLTH.APP_DAY_JFTJ IS
handle utl_file.file_type;
TYPE ref_cursor_type IS REF CURSOR;
ref_cursor ref_cursor_type;
tb varchar2(20);
v_msisdn VARCHAR2(15);
FILE_NAME VARCHAR2(40);
v_date VARCHAR2(10);
v_sql VARCHAR2(2000);
v_text VARCHAR2(1000);
v_appkey VARCHAR2(100);
begin
select to_char(sysdate,'yyyymmdd') into v_date from dual;
FILE_NAME :='bill_'||v_date||'.txt';
handle := UTL_FILE.FOPEN('JFTJ', FILE_NAME, 'w');
v_sql :='select distinct o.msisdn||''|''||s.WO_APP_KEY||''|''||trunc(s.service_fee,2)||''|''||o.order_id
from t_order o, t_service s
where to_char(o.order_time,''yyyymmdd'') = to_char(trunc(sysdate)-3,''yyyymmdd'')
and sysdate-3 >= trunc(sysdate,''month'')
and o.order_status in (1, 6, 9)
and s.service_id = o.service_id
and o.is_fee=1
and o.province_id not in (select prov_id from t_cardproduct_auth t where t.prov_isfee=1)';
open ref_cursor for v_sql;
LOOP
fetch ref_cursor into v_text;
exit when ref_cursor%NOTFOUND;
UTL_FILE.put_line(handle,v_text);
END LOOP;
UTL_FILE.fclose(handle);
close ref_cursor;
FILE_NAME :='msisdn_'||v_date||'.txt';
handle := UTL_FILE.FOPEN('JFTJ', FILE_NAME, 'w');
v_sql :='select distinct o.msisdn
from t_order o, t_service s
where to_char(o.order_time,''yyyymmdd'') = to_char(trunc(sysdate)-3,''yyyymmdd'')
and sysdate-3 >= trunc(sysdate,''month'')
and o.order_status in (1, 6, 9)
and s.service_id = o.service_id
and o.is_fee=1
and o.province_id not in (select prov_id from t_cardproduct_auth t where t.prov_isfee=1)';

open ref_cursor for v_sql;
LOOP
fetch ref_cursor into v_msisdn;
exit when ref_cursor%NOTFOUND;
UTL_FILE.put_line(handle,v_msisdn);
END LOOP;
UTL_FILE.fclose(handle);
close ref_cursor;
FILE_NAME :='app_'||v_date||'.csv';
handle := UTL_FILE.FOPEN('JFTJ', FILE_NAME, 'w');
v_sql :='select distinct appkey from t_service
where to_char(update_time,''yyyymmdd'')=to_char(sysdate,''yyyymmdd'')
and appkey not in (select appkey from t_service where update_time<trunc(sysdate))';
open ref_cursor for v_sql;
LOOP
fetch ref_cursor into v_appkey;
exit when ref_cursor%NOTFOUND;
UTL_FILE.put_line(handle,v_appkey);
END LOOP;
UTL_FILE.fclose(handle);
close ref_cursor;
end;
/

--按月统计
CREATE OR REPLACE PROCEDURE LLTH.APP_MON_JFTJ IS
handle utl_file.file_type;
TYPE ref_cursor_type IS REF CURSOR;
ref_cursor ref_cursor_type;
tb varchar2(20);
v_msisdn VARCHAR2(15);
FILE_NAME VARCHAR2(40);
v_date VARCHAR2(10);
v_sql VARCHAR2(2000);
v_text VARCHAR2(1000);
v_appkey VARCHAR2(100);
begin
select to_char(sysdate,'yyyymmdd') into v_date from dual;
FILE_NAME :='bill_'||v_date||'.txt';
handle := UTL_FILE.FOPEN('JFTJ', FILE_NAME, 'w');
v_sql :='select distinct o.msisdn||''|''||s.WO_APP_KEY||''|''||trunc(s.service_fee,2)||''|''||o.order_id
from t_order o, t_service s
where o.order_time < trunc(sysdate)
and o.order_status in (1, 6, 9)
and s.service_id = o.service_id
and o.is_fee=1
and o.province_id not in (select prov_id from t_cardproduct_auth t where t.prov_isfee=1)';
open ref_cursor for v_sql;
LOOP
fetch ref_cursor into v_text;
exit when ref_cursor%NOTFOUND;
UTL_FILE.put_line(handle,v_text);
END LOOP;
UTL_FILE.fclose(handle);
close ref_cursor;
FILE_NAME :='msisdn_'||v_date||'.txt';
handle := UTL_FILE.FOPEN('JFTJ', FILE_NAME, 'w');
v_sql :='select distinct o.msisdn
from t_order o, t_service s
where o.order_time < trunc(sysdate)
and o.order_status in (1, 6, 9)
and s.service_id = o.service_id
and o.is_fee=1
and o.province_id not in (select prov_id from t_cardproduct_auth t where t.prov_isfee=1)';

open ref_cursor for v_sql;
LOOP
fetch ref_cursor into v_msisdn;
exit when ref_cursor%NOTFOUND;
UTL_FILE.put_line(handle,v_msisdn);
END LOOP;
UTL_FILE.fclose(handle);
close ref_cursor;
FILE_NAME :='app_'||v_date||'.csv';
handle := UTL_FILE.FOPEN('JFTJ', FILE_NAME, 'w');
v_sql :='select distinct appkey from t_service';
open ref_cursor for v_sql;
LOOP
fetch ref_cursor into v_appkey;
exit when ref_cursor%NOTFOUND;
UTL_FILE.put_line(handle,v_appkey);
END LOOP;
UTL_FILE.fclose(handle);
close ref_cursor;
end;
/

CREATE OR REPLACE PROCEDURE BJ_G.zj_msisdn_to_file_whq IS
handle utl_file.file_type;
TYPE ref_cursor_type IS REF CURSOR;
ref_cursor ref_cursor_type;
v_msisdn VARCHAR2(15);
FILE_NAME VARCHAR2(40);
v_sql varchar2(2000);
tk_id varchar2(20);
cc varchar2(20);
cursor user_name is
select * from temp_whq1;
type tablename is ref cursor;
tablenamel tablename;
BEGIN
for i in user_name loop
select i.taskid into tk_id from dual;
select i.prov_sh into cc from dual;
FILE_NAME := cc||'.txt';
handle := UTL_FILE.FOPEN('AA', FILE_NAME, 'w');
v_sql:='select c_msisdn from (select c_msisdn,count(*) c1,c_smscount c2 from '||cc||'.t_batch_mt
where C_taskid = '||tk_id||' and C_actiontype = 3 and C_status = ''0''
group by c_msisdn,c_smscount) where c1>=c2 intersect
select c_msisdn from '||cc||'.t_batch_mt where C_taskid = '||tk_id||' and C_actiontype = 9 and C_status = ''0''';
open ref_cursor for v_sql;
LOOP
FETCH ref_cursor
INTO v_msisdn ;
EXIT WHEN ref_cursor%NOTFOUND;
UTL_FILE.put_line(handle,
v_msisdn );
END LOOP;
UTL_FILE.fclose(handle);
close ref_cursor;
end loop;
end;
/

CREATE OR REPLACE PROCEDURE bj_g.p_update_otakey as

l_sql1 varchar2(1000);
l_sql2 varchar2(1000);
l_sql3 varchar2(1000);
l_sql4 varchar2(1000);
l_sql5 varchar2(1000);
l_sql6 varchar2(1000);
l_sql7 varchar2(1000);
l_sql8 varchar2(1000);
l_sql9 varchar2(1000);
l_sql10 varchar2(1000);
uname varchar2(20);
cursor user_name is select prov_sh from bj_g.t_province where prov_sh NOT IN ('BJ_G');

begin
for user_name_l in user_name loop
select user_name_l.prov_sh into uname from dual ;
l_sql1 :='update '||uname||'.t_otakey set c_keydata=''CB6631B9337088F74EAC5555CD8CC101'' where c_batchno =''31'' and c_cvendorid=''0B'' and c_functionid= ''0'' and c_index=''0''';
execute immediate l_sql1;
l_sql2 :='update '||uname||'.t_otakey set c_keydata=''DDB5B0D5CC15B5E7ABD7FF4FCAEE7D09'' where c_batchno =''31'' and c_cvendorid=''0B'' and c_functionid= ''0'' and c_index=''1''';
execute immediate l_sql2;
l_sql3 :='update '||uname||'.t_otakey set c_keydata=''0D89C4DE52085A5FEE026D7A9B94F63D'' where c_batchno =''31'' and c_cvendorid=''0B'' and c_functionid= ''0'' and c_index=''2''';
execute immediate l_sql3;
l_sql4 :='update '||uname||'.t_otakey set c_keydata=''F7F17FCEAF49EB4A1F1804D92539C707'' where c_batchno =''31'' and c_cvendorid=''0B'' and c_functionid= ''0'' and c_index=''3''';
execute immediate l_sql4;
l_sql5 :='update '||uname||'.t_otakey set c_keydata=''869966FC9925A12CC0A9004F432417D2'' where c_batchno =''31'' and c_cvendorid=''0B'' and c_functionid= ''0'' and c_index=''4''';
execute immediate l_sql5;
l_sql6 :='update '||uname||'.t_otakey set c_keydata=''25081515B242B1888988F48DFC031B08'' where c_batchno =''31'' and c_cvendorid=''0B'' and c_functionid= ''1'' and c_index=''0''';
execute immediate l_sql6;
l_sql7 :='update '||uname||'.t_otakey set c_keydata=''391EA43E194CBBF200B89D5D56C004E9'' where c_batchno =''31'' and c_cvendorid=''0B'' and c_functionid= ''1'' and c_index=''1''';
execute immediate l_sql7;
l_sql8 :='update '||uname||'.t_otakey set c_keydata=''F5801E5AF9538E07BDF9152CD880E658'' where c_batchno =''31'' and c_cvendorid=''0B'' and c_functionid= ''1'' and c_index=''2''';
execute immediate l_sql8;
l_sql9 :='update '||uname||'.t_otakey set c_keydata=''7D1B82F39C9BEE94CA5CADE8658623C7'' where c_batchno =''31'' and c_cvendorid=''0B'' and c_functionid= ''1'' and c_index=''3''';
execute immediate l_sql9;
l_sql10 :='update '||uname||'.t_otakey set c_keydata=''2F1283032CEBF9DEB0741C6CB3781C78'' where c_batchno =''31'' and c_cvendorid=''0B'' and c_functionid= ''1'' and c_index=''4''';
execute immediate l_sql10;
commit;
end loop;
commit;
end;

CREATE OR REPLACE PROCEDURE otas.p_create_molog AUTHID current_user as

l_month varchar2(6);
l_nextmonth varchar2(6);
l_sql varchar2(1000);
l_sql1 varchar2(1000);
l_sql2 varchar2(1000);
l_sql3 varchar2(1000);
l_sql4 varchar2(1000);
uname varchar2(20);
cursor user_name is select sf from otas.t_province where sf NOT in('LN');

v_i varchar2(20);

begin
for user_name_l in user_name loop
select user_name_l.sf into uname from dual ;

for i in 1..12 loop
select lpad(i,2,'0') into v_i from dual;
l_month:='2017'||v_i;
select to_char(add_months(to_date(l_month,'yyyymm'),+1),'YYYYMM') into l_nextmonth from dual;

l_sql :='CREATE TABLE '||uname||'.T_MOLOG'||l_nextmonth||' as select * from ' ||uname||'.t_molog'||l_month||' where 1<>1' ;
execute immediate l_sql;

l_sql1 :='CREATE UNIQUE INDEX '||uname||'.T_MOLOG'||l_nextmonth||'_PK ON '||uname||'.T_MOLOG'||l_nextmonth||'(C_AUTONO)';
execute immediate l_sql1;
l_sql2 :='ALTER TABLE ' ||uname||'.T_MOLOG'||l_nextmonth||' ADD CONSTRAINT T_MOLOG'||l_nextmonth||'_PK PRIMARY KEY (c_autono) using index '||uname||'.T_MOLOG'||l_nextmonth||'_PK';
execute immediate l_sql2;
l_sql3 :='CREATE SEQUENCE '||uname||'.SEQUENCE_MOLOG'||l_nextmonth||' START WITH 1 MAXVALUE 99999999999 MINVALUE 1 NOCYCLE CACHE 20 NOORDER';
execute immediate l_sql3;
l_sql4 :='CREATE OR REPLACE TRIGGER '||uname||'.TRG_SEQNO_MOLOG'||l_nextmonth||' BEFORE INSERT ON '||uname||'.T_MOLOG'||l_nextmonth||' FOR EACH ROW BEGIN
SELECT '||uname||'.SEQUENCE_MOLOG'||l_nextmonth||'.NEXTVAL INTO :NEW.c_autono FROM DUAL;END;';
execute immediate l_sql4;
end loop;
DBMS_OUTPUT.PUT_LINE(UNAME);
end loop;
end;

--推送总数(不去重)
create table temp_pl(prov varchar2(20),count varchar2(20));

CREATE OR REPLACE PROCEDURE bj_g.push_sucesses as

l_sql varchar2(1000);
uname varchar2(20);
cnt1 varchar2(20);
cursor user_name is select prov_sh from bj_g.t_province;

begin
for user_name_l in user_name loop
select user_name_l.prov_sh into uname from dual ;
execute immediate 'insert into temp_pl select '||''''||uname||''''||',count(*) from '||uname||'.t_batch_mt where to_char(c_intime,''yyyymm'')=''201702''';
commit;
end loop;
commit;
end;
/

--推送总数-去重-按手机号去重,要的是用户数
create table temp_pl1(prov varchar2(20),count varchar2(20));

CREATE OR REPLACE PROCEDURE bj_g.push_sucesses_1 as
l_sql varchar2(1000);
uname varchar2(20);
cnt1 varchar2(20);
cursor user_name is select prov_sh from bj_g.t_province;

begin
for user_name_l in user_name loop
select user_name_l.prov_sh into uname from dual ;
execute immediate 'insert into temp_pl1(prov,count) select '||''''||uname||''''||',count(c_msisdn) from (
select c_msisdn,c_intime from(
select c_msisdn,c_intime,row_number() over(partition by c_msisdn order by c_intime desc) rn
from '||uname||'.t_batch_mt where to_char(c_intime,''yyyymm'')=''201702'' ) where rn=1)';
commit;
end loop;
commit;
end;
/

select * from temp_pl1 order by prov;

--应用成功数-不去重

select count(*) from tag.t_information_push where to_char(push_date,'yyyymm')='201702';

--应用成功数-去重

select count(distinct msisdn) from tag.t_information_push where to_char(push_date,'yyyymm')='201702';

--订购数

select count(distinct o.msisdn) from llth.t_order o,tag.t_information_push t
where o.order_time >= to_date('2017-02-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
and o.order_time < to_date('2017-03-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
and (o.cancel_time is null or (o.cancel_time>=to_date('2017-03-01 00:00:00','yyyy-mm-dd hh24:mi:ss')))
and o.order_status in (1,2,3,6,9,12)
and o.order_channel=1
and o.msisdn = t.msisdn
and to_char(t.push_date,'yyyymm')='201702'; --数据不准确,,数量是 185163

--在sms9885提取双计费订购用户--不去重,然后入库到OTA bj_g的临时表中:

select mdn from service_users a,services b where a.service_id=b.id
and service_id in (666,668,688,888)
and sub_date BETWEEN TO_DATE ('2017-02-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
AND TO_DATE ('2017-02-28 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
and (unsub_date >= TO_DATE ('2017-03-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') or unsub_date is null);

create table temp_sjf(mdn varchar2(11));

批量推送订购数:

temp_auto_user:自动更新 parentid值: 参考消息 37 知音 41 特惠礼包35 环球时报 36

declare
uname varchar2(20);
v_prov_id varchar2(10);
cursor user_name is
select * from t_province_bak;
date_a varchar2(20);
date_b varchar2(20);
begin
for user_name_l in user_name loop
select user_name_l.prov_sh into uname from dual;
select user_name_l.prov_id into v_prov_id from dual;
for i in 1..28 loop
if i<10 then
date_a:='2017020'||to_char(i);
else
date_a:='201702'||to_char(i);
end if;
execute immediate 'insert into temp_auto_user(msisdn,exporttime) select c_msisdn,c_sentdate
from (select distinct c_msisdn,c_sentdate from '||uname||'.t_mtlog201702
where C_parentid in (''35'',''36'',''41'',''37'')
and C_menuid=1
and to_char(c_sentdate,''yyyymmdd'') ='||''''||date_a||''''||')';
commit;
end loop;
end loop;
end;
/

temp_batch_update_user: 批量更新

CREATE OR REPLACE procedure LLTH.wu_msisdn_to_file_A3
is
cursor user_name is
select t1.prov_id,t1.prov_sh,t.taskid from temp_07 t,t_province_bak t1 where t.prov_sh=t1.prov_sh;
dt_l date;
date_b varchar2(20);
v_sql varchar2(2000);
aa varchar2(20);
bb varchar2(20);
begin
for i in user_name loop
select i.prov_id into aa from dual;
select i.prov_sh into bb from dual;
execute immediate 'insert into temp_batch_update_user(msisdn,exporttime) select c_msisdn,date_a
from (select c_msisdn,to_char(date_a,''yyyy/mm/dd hh24:mi:ss'') date_a from (
select t.c_msisdn,c_intime as date_a,row_number()over(partition by c_msisdn order by c_intime) rn from '||bb||'.t_batch_mt t
where t.c_taskid in (select taskid from temp_07 where prov_sh='||''''||bb||''''||')
and t.c_status=''0'') where rn=1)';
commit;
end loop;
end;
/

订购数---不去重:

create table tempzj1 as select * from temp_batch_update_user where msisdn not in (select msisdn from temp_auto_user);

select count(o.msisdn) from llth.t_order o --,llth.tempzj1 u
where o.order_time> to_date('2017-02-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
and o.order_time< to_date('2017-03-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
and (o.cancel_time is null or (o.cancel_time>=to_date('2017-03-01 00:00:00','yyyy-mm-dd hh24:mi:ss')))
and o.order_status in (1,2,3,6,9,12)
and o.order_channel=1
and o.msisdn in(select msisdn from llth.tempzj1 u);

------------数量是16010

select count(mdn) from temp_sjf
where mdn in (select msisdn from llth.tempzj1 u);

plsql例子的更多相关文章

  1. Oracle的tnsnames.ora配置(PLSQL Developer)

    首先打开tnsnames.ora的存放目录,一般为D:\app\Administrator\product\11.2.0\client_1\network\admin,就看安装具体位置了. 步骤阅读 ...

  2. 不安装oracle,使用plsql连接oracle

    通常企业开发时,数据库是不会在我们本地安装的(废话),所以使用plsql时,没必要的话,我们尽量不去安装oracle,太大了: 接下来说一下本人plsql,不安装oracle的使用步骤: 1.个人本地 ...

  3. plsql很好用的自定义设置【转载】

    本文是转载的,目的是方便自已随时可以查看.转载地址:http://blog.itpub.net/24496241/viewspace-740917/ 目的:方便自已随时可以查看 1.格式化SQL语句在 ...

  4. plsql常用函数汇总

    在SQLPLUS下,实现中-英字符集转换alter session set nls_language='AMERICAN';alter session set nls_language='SIMPLI ...

  5. PLSQL开发笔记和小结(转载)

    *****************************************   PLSQL基本结构 ***************************************** 基本数据 ...

  6. 在PLSQL中编译复杂的java(转)

    原文地址:在PLSQL中编译复杂的java PLSQL中可以编译运行JAVA程序. 一个简单的例子: create or replace and compile java source named x ...

  7. Oracle PLSQL语句实例

    /** * plsql:某个项目对效率要求比较高的时候用,一般不用,大多数项目写的是夸数据库平台的,用不上. * pssql大多数能做的东西,java都能替代它.在某些特殊的地方要求用plsql的时候 ...

  8. Report_客制化以PLSQL输出XLS标记实现Excel报表(案例)

    2015-02-12 Created By BaoXinjian

  9. PLSQL读取XML的数据

    最近公司做的几个项目,都是通过EBS与外部系统的Web Service进行数据的交互,而调用Web Service的时候,我们所传送的数据,都是按照约定的XML格式来传递,所以EBS接收到数据之后,需 ...

随机推荐

  1. 常州day5

    Task 1 小 W 和小 M 一起玩拼图游戏啦~ 小 M 给小 M 一张 N 个点的图,有 M 条可选无向边,每条边有一个甜蜜值,小 W 要选 K条边,使得任意两点间最多有一条路径,并且选择的 K条 ...

  2. 【BZOJ3028】食物(生成函数)

    [BZOJ3028]食物(生成函数) 题面 一个人要带\(n\)个物品,共有\(8\)种物品,每种的限制分别如下: 偶数个;0/1个;0/1/2个;奇数个; 4的倍数个;0/1/2/3个;0/1个;3 ...

  3. BZOJ4408 [Fjoi 2016]神秘数 【主席树】

    题目链接 BZOJ4408 题解 假如我们已经求出一个集合所能凑出连续数的最大区间\([1,max]\),那么此时答案为\(max + 1\) 那么我们此时加入一个数\(x\),假若\(x > ...

  4. laravel添加日常备份任务

    app/Console/Command/MySqlDump.php <?php namespace App\Console\Commands; use Illuminate\Console\Co ...

  5. rabbitmq常见运维命令和问题总结

    常见运维命令作用: yum安装erlang的环境配置: ERLANG_HOME=/usr/lib64/erlang export PATH=$PATH:$ERLANG_HOME/bin 常见rabbi ...

  6. Codeforces 807 C. Success Rate

    http://codeforces.com/problemset/problem/807/C C. Success Rate time limit per test 2 seconds memory ...

  7. CSS3之伪元素选择器和伪类选择器

    伪类选择器,和一般的DOM中的元素样式不一样,它并不改变任何DOM内容.只是插入了一些修饰类的元素,这些元素对于用户来说是可见的,但是对于DOM来说不可见.伪类的效果可以通过添加一个实际的类来达到. ...

  8. kle 日志收集系统维护之清理索引及索引优化脚本

    logstash每天往es建好索引,按天生成,就目前的需求,需要清理不需要的数据,以保证最新日志的速度展示,哈哈,瞎搞了这个脚本,路过的大神批评. #!/usr/bin/env python # co ...

  9. jQuery技术内幕 深入解析jQuery架构设计与实现原理

    jquery的外衣 jquery是一个轻量级的JS框架 //以下截取自jquery源码片段 (function( window, undefined ) { /* 源码内容 */ })( window ...

  10. Lua的工具资源3

    [LuaSrcDiet] (5.0.2) - 通过删除不必要的空白和注释缩减Lua文件的大小. [LuaProfiler] (5.0) - 一个用来查找Lua应用瓶颈的工具time profiler ...