带易失性表和输入参数的存储过程

时间:2018-08-23 18:38:27

标签: teradata

我正在尝试创建一个存储过程,该过程将一些数据收集到各种(2)易失性表中,然后根据来自这些易失性表的查询输出结果集。

我认为我已经正确编写了语法,但是当我调用该过程(调用msn_test('2018-05-01','510001'))时,它返回0个结果。我认为这与解析变量的方式有关。

这是我表结构的一个示例

create VOLATILE TABLE  customer_count  (
cust_no varchar(10)
,ordercount int
,rpt_mth date
)  on commit preserve rows;

INSERT INTO customer_count VALUES ('510001', '502','2018-05-01');
INSERT INTO customer_count VALUES ('510002', '2','2018-05-01');
INSERT INTO customer_count VALUES ('510003', '100','2018-05-01');

create VOLATILE TABLE  customer_sales  (
cust_no varchar(10)
,revenue decimal(15,2)
,rpt_mth date
)  on commit preserve rows;

INSERT INTO customer_sales VALUES ('510001', '12500','2018-05-01');
INSERT INTO customer_sales VALUES ('510002', '5000','2018-05-01');
INSERT INTO customer_sales VALUES ('510003', '1400','2018-05-01');

这是我的存储过程正在执行-

create VOLATILE TABLE tmp_one (cust_no varchar(30), ordercount int)  on commit preserve rows;
create VOLATILE TABLE tmp_two (cust_no varchar(30),revenue decimal(18,2)) on commit preserve rows;

replace procedure msn_test (
IN mth date,
IN cust varchar(30))
dynamic result sets 1

begin

declare rslt cursor with return only for

select
a.cust_no, a.ordercount, b.revenue
from tmp_one a
join tmp_two b
    on a.cust_no = b.cust_no
    ;


call dbc.SysExecSQL('create VOLATILE TABLE tmp_one as (select cust_no, sum(ordercount) ordercount   from customer_count where cust_no = ''' || cust || ''' and rpt_mth = cast(''' || mth ||''' as date)    group by 1) with data on commit preserve rows');
call dbc.SysExecSQL('create VOLATILE TABLE tmp_two as (select cust_no, sum(revenue) revenue             from customer_sales  where cust_no = ''' || cust || ''' and rpt_mth = cast(''' || mth ||''' as date)    group by 1) with data on commit preserve rows');


open rslt;
 drop table tmp_one;
 drop table tmp_two;
end;
  drop table tmp_one;
drop table tmp_two;

最后,这是我的电话,但没有结果。

call msn_test ('2018-05-01','510001')

这是我想要的结果-

    cust_no ordercount  revenue
 1  510001  502         12,500.00

我想念什么?预先谢谢你。

0 个答案:

没有答案