先提炼,然后再问!

来源:互联网 发布:阿里云服务器80端口 编辑:程序博客网 时间:2024/05/16 18:17
在论坛里看到这样的一帖子,看了一会,不明白什么意思,然后想说:楼主,先把你要问的问题提炼一下吧,这样可能会有更多的人回答。
说实话我没弄明白楼主的意思,但后来再看这个问题时,有一个人做了解答,这个回答的人应该是弄懂了楼主的意思,我也不好说什么,就说给自己听听吧: 先提炼,然后再问!

楼主贴出来的是动态的sql,只有where 语句没有select语句不知道怎么 回事,楼主的问题如下:


以下存储过程返回查询结果集,统计结果. 现在的问题是:消费统计/调帐(借记)统计/调帐(贷记)统计/退货统计/充值统计,5项结果不正确,要求从"结果集"中进行统计,现在不是,我该如果做

create or replace package pak_trans as
type trans_cursor is ref cursor;
end pak_trans;
/
CREATE OR REPLACE PROCEDURE "CARD"."TRANS"
(
mcht in varchar, --商户号
sett in varchar, --清算号
startcardno in varchar, --起始卡号
endcardno in varchar, --结束卡号
tx_code in varchar, --交易代码
banlace in varchar, --交易金额
startdate in varchar, --开始日期
enddate in varchar, --结束日期
traceno in varchar, --流水号
batchno in varchar, --批次号
termid in varchar, --终端号
document in varchar, --证件类型
cardhold in varchar, --证件号码
lxname in varchar, --联系人
telphone in varchar, --电话
gkdate in varchar, --购卡时间
pagesize in number, --页尺寸
currpage in number, --当前页
recordcount out number, --记录数

sell out number, --消费笔数
rating_sum out number, --消费金额
rating out number, --充值笔数
init_sum out number, --充值金额
initsell out number, --退货笔数
RSA_sum out number, --退货金额
init out number, --调帐(借记)笔数
TSO_sum out number, --调帐(借记)金额
makeall out number, --调帐(贷记)笔数
TSI_sum out number, --调帐(贷记)金额
poundage out number, --卡激活总量
hstint out number, --卡冻结总量
intbal out number, --卡解冻总量

p_cursor out pak_trans.trans_cursor --返回结果集
)
as
v_startRowNum NUMBER; --分页起始记录编号
v_endRowNum NUMBER; --分页结束记录编号
strsql varchar2(4000); --查询语句
strsql1 varchar2(4000); --查询语句1
str varchar2(4000);
sqlwhere varchar2(4000); --where条件1
sqlwhere1 varchar2(4000); --where条件2
sqlwhere2 varchar2(4000); --where条件3
sqlwhere3 varchar2(4000); --where条件4
sqlwhere4 varchar2(4000); --where条件5
sqlwhere5 varchar2(4000); --where条件6
sqlwhere6 varchar2(100); --where条件7
perstr varchar2(4000); --充值SQL

rej_code varchar2(10); --卡状态变更
txcode varchar(5); --卡状态变更状态码
standby2 varchar2(40); --卡段
tmp_min varchar2(7); --卡段最小值
tmp_max varchar2(7); --卡段最大值

begin
--查询条件
sqlwhere:=' where merch_id='
||mcht
||' and sett_postdate>='''
||startdate
||''' and sett_postdate<='''
||enddate
||''' and exists(select * from merchant where merch_id='
||mcht
--||' and exists(select * from grppou where substr(MERGRP,1,8)='
--||substr(merchant.grp_name,1,8)
--||' and grp_leader='
--||mcht
||')';
if length(startcardno)>0 and length(endcardno)>0 then
sqlwhere:=sqlwhere
||' and cardno>='''
||startcardno
||''' and cardno<='''
||endcardno
||'''';
--||' or (substr(addidata1,1,18)<='
--||startcardno
--||' and substr(addidata1,20,18)>='
--||startcardno
--||' and substr(addidata1,1,18)<='
--||endcardno
--||' and substr(addidata1,20,18)>='
--||endcardno
--||')';
end if;

if to_number(banlace)!=0 then
sqlwhere:=sqlwhere
||' and req_txnamt='
||to_number(banlace)*0.01;
end if;
if length(traceno)>0 then
sqlwhere:=sqlwhere
||' and trace_no='
||traceno;
end if;
if length(batchno)>0 then
sqlwhere:=sqlwhere
||' and batchid='
||batchno;
end if;
if length(termid)>0 then
sqlwhere:=sqlwhere
||' and term_id='
||termid;
end if;
if length(cardhold)>0 then
sqlwhere:=sqlwhere
||' and addidata1 like '''
||'%'
||cardhold
||'%''';
end if;
if length(lxname)>0 then
sqlwhere:=sqlwhere
||' and addidata1 like '''
||'%'
||lxname
||'%''';
end if;
if length(telphone)>0 then
sqlwhere:=sqlwhere
||' and addidata1 like '''
||'%'
||telphone
||'%''';
end if;
if length(gkdate)>0 then
sqlwhere:=sqlwhere
||' and addidata1 like '''
||'%'
||gkdate
||'%''';
end if;

--where 条件2
sqlwhere1:=' and (compl_flag<>04 and compl_flag<>02 or compl_flag is null) and rsp_code=00 and tx_code=''PER''';
sqlwhere2:=' and (compl_flag<>04 and compl_flag<>02 or compl_flag is null) and rsp_code=00 and tx_code=''TSO''';
sqlwhere3:=' and (compl_flag<>04 and compl_flag<>02 or compl_flag is null) and rsp_code=00 and tx_code=''TSI''';
sqlwhere4:=' and (compl_flag<>04 and compl_flag<>02 or compl_flag is null) and rsp_code=00 and (tx_code=''RSA'' or tx_code=''REF'')';
sqlwhere5:=' and (compl_flag<>04 and compl_flag<>02 or compl_flag is null) and rsp_code=00 and (tx_code=''HNT'' or tx_code=''PNT'')';
--sqlwhere6:=' and (tx_code=''CST'' or tx_code=''HSN'' or tx_code=''PSN'')';
if length(tx_code)>0 then
sqlwhere6:=' and tx_code='''
||tx_code
||'''';
end if;


原创粉丝点击