SQL查詢語句

2021-04-19 22:14:26 字數 4424 閱讀 1763

create or replace procedure imms_pk_reportsend(fromdate varchar2,todate varchar2)

as/*

function:系統效能統計

author: qja

功能:將imms_statusreport 表和imms_report_send 表中的資料統計到imms_report_send表中。

date: 2008.08.19

*/v_drsuccess   number;

v_d***il      number;

v_updatesum   number;

v_failsum     number;

v_datdeal     varchar2(20);

begin

execute immediate 'truncate table imms_report_send';

--dbms_output.put_line(fromdate||' '||todate);

for comuser in

(select distinct rs.vc2campaignid,rs.vc2source,rs.vc2servicecode

from imms_realsend rs,imms_realsendstatus iss

where iss.numrealsendguid=rs.numrealsendguid

and trunc(rs.datcreate) >= to_date(fromdate,'yyyy-mm-dd')

and trunc(rs.datcreate) <=to_date(todate,'yyyy-mm-dd'))

loop

begin

--jiqu update 20080819

v_drsuccess := 0;

select to_char(ir.datcreate, 'yyyymmdd') ,

count(*)

into v_datdeal,v_drsuccess

from imms_realsendstatus iss,imms_realsend ir

where iss.numrealsendguid=ir.numrealsendguid

and trunc(ir.datcreate) >= to_date(fromdate,'yyyy-mm-dd')

and trunc(ir.datcreate) <=to_date(todate,'yyyy-mm-dd')

and iss.vc2reportstatus='s'--dr回覆筆數

group by to_char(ir.datcreate, 'yyyymmdd');

--jiaqu update 20080819

exception

when no_data_found then

v_drsuccess   := 0;

end;

begin

v_d***il := 0;

select to_char(ir.datcreate, 'yyyymmdd') ,

count(*)

into v_datdeal,v_d***il

from imms_realsendstatus iss,imms_realsend ir

where iss.numrealsendguid=ir.numrealsendguid

and trunc(ir.datcreate) >= to_date(fromdate,'yyyy-mm-dd')

and trunc(ir.datcreate) <=to_date(todate,'yyyy-mm-dd')

and iss.vc2reportstatus='f'--dr未回覆筆數

group by to_char(ir.datcreate, 'yyyymmdd');

exception

when no_data_found then

v_d***il := 0;

end;

begin

v_updatesum :=0;

select to_char(rs.datcreate, 'yyyymmdd') ,

count(*)

into v_datdeal,v_updatesum

from imms_realsendstatus iss,imms_realsend rs

where iss.numrealsendguid=rs.numrealsendguid

and trunc(rs.datcreate) >= to_date(fromdate,'yyyy-mm-dd')

and trunc(rs.datcreate) <=to_date(todate,'yyyy-mm-dd')

group by to_char(rs.datcreate, 'yyyymmdd');--report update總筆數

exception

when no_data_found then

v_updatesum :=0;

end;

begin

v_failsum :=0;

select to_char(rs.datcreate, 'yyyymmdd') ,

count(*)

into v_datdeal,v_failsum

from imms_realsend rs,imms_realsendstatus iss

where iss.numrealsendguid=rs.numrealsendguid

and trunc(rs.datcreate)>= to_date(fromdate,'yyyy-mm-dd')

and trunc(rs.datcreate)<=to_date(todate,'yyyy-mm-dd')

and iss.vc2reportstatus='f'

group by to_char(rs.datcreate, 'yyyymmdd');--失敗總筆數

exception

when no_data_found then

v_failsum :=0;

end;

insert into imms_report_send

(numrsguid, vc2campaignid, datcreate, numsuccesssum, numfailsum,numtotalsum, vc2source,numcontentfailed,numreportupdate,vc2servicecode)

values

(seq_reportsend.nextval,comuser.vc2campaignid, to_date(v_datdeal,'yyyymmdd'),v_drsuccess,v_d***il,v_drsuccess+v_d***il ,comuser.vc2source, v_updatesum,v_failsum+v_d***il,comuser.vc2servicecode);

commit;

end loop;

end;

/上面是我的的儲存過程。

高手一條sql就搞定了。

sql語句還是很強大的。

努力學習....

我是笨鳥...

select seq_report_send.nextval, a.*

from

(select rs.vc2campaignid,

trunc(rs.datcreate) as datdeal,

sum(decode(iss.vc2reportstatus,'s',1,0)) as drsuccess,

sum(decode(iss.vc2reportstatus,'f',1,0)) as d***il,

sum(decode(iss.vc2reportstatus,'s',1,'f',1,0)) as total,

rs.vc2source,

count(rs.vc2campaignid) as updatesum,

sum(decode(iss.vc2reportstatus,'f',1,0))+sum(decode(rs.vc2status,'2',1,0)) as failsum,

rs.vc2servicecode

from imms_realsend rs,imms_realsendstatus iss

where iss.numrealsendguid=rs.numrealsendguid

and rs.datcreate >= to_date('2008-02-02','yyyy-mm-dd')

and rs.datcreate <=to_date('2008-08-29','yyyy-mm-dd')

group by rs.vc2campaignid, rs.vc2source, rs.vc2servicecode, trunc(rs.datcreate)) a

sql 語句 查詢

例11 1 1 use xk gocreate trigger test1 on student for update as print 記錄已修改!go 2 update student set pwd 11111111 where stuno 00000001 例11 3 1 use xk go...

sql查詢語句

條件查詢 select 列名列表 from 表名 where 條件 where 條件 用來篩選滿足條件的記錄 行 條件有6種形式 1.比較大小 列名 比較運算子 值 查詢圖書 超過30元的圖書資訊 select from book where price 30 查詢清華大學出版社出版的圖書資訊 se...

SQL查詢語句

sql查詢語句 select from film order by year limit 10 select from film order by year desc limit 10 select count from film select from film where starring li...