aaa: 输入参数
bbb: 输出参数,一个表对象,或者一个结果集
包
produce getMySqlDate(aaa IN varchar2,
bbb OUT tmpTable%ROWTYPE) IS
本体
produce getMySqlDate(aaa IN varchar2,
bbb OUT tmpTable%ROWTYPE)
begin
--查询数据
CURSOR curCc is
select a,b from tab1
type typeCurCc of table curCc%ROWTYPE
typeCurCc tabCurCc-- 定义游标类型
--打开游标把查询处理的数据,赋值到bbb的输出参数就行了。
open 游标
....
bbb.a = 游标.a
close 游标
--存储过程终了
END getMysql;
select sum(money) as money, idfrom recharge
where time between xxx and xxx
group by id
余额可以单独用一个余额记录表,这样如果要查询每次消费记录的时候,也能查出来每次消费后还有多少余额。余额记录表里面主要是三个字段:用户账号、每次消费后的余额、时间点。CREATE TABLE account
(
id integer NOT NULL DEFAULT nextval('trade_id_seq'::regclass),
no character varying(10) NOT NULL, -- 账号
balance money NOT NULL DEFAULT 0.00, -- 余额
datetime timestamp without time zone NOT NULL DEFAULT (now())::timestamp(0) without time zone,
CONSTRAINT account_pkey PRIMARY KEY (id)
)
通过每次的余额变化就知道每次消费后的余额情况
select acc.*, (select sum(balance)+acc.balance from account as ac where ac.id <acc.id) as profit from account as acc
id | no | balance | datetime | profit
----+------+----------+---------------------+---------
1 | 1000 |$0.00 | 2013-10-09 10:51:10 |
2 | 1000 | $12.60 | 2013-10-09 10:51:22 | $12.60
4 | 1000 | $16.80 | 2013-10-09 10:51:42 | $29.40
5 | 1000 | $100.00 | 2013-10-09 10:51:49 | $129.40
6 | 1000 | $200.00 | 2013-10-09 10:56:35 | $329.40
7 | 1000 | $50.45 | 2013-10-09 10:57:23 | $379.85
8 | 1000 | $75.50 | 2013-10-09 10:57:31 | $455.35
9 | 1000 | -$55.30 | 2013-10-09 10:59:28 | $400.05
10 | 1000 | -$200.00 | 2013-10-09 10:59:44 | $200.05
(9 rows)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)