最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PostgreSQL中調(diào)用存儲過程并返回數(shù)據(jù)集實例

 更新時間:2015年01月19日 11:19:12   投稿:junjie  
這篇文章主要介紹了PostgreSQL中調(diào)用存儲過程并返回數(shù)據(jù)集實例,本文給出一創(chuàng)建數(shù)據(jù)表、插入測試數(shù)據(jù)、創(chuàng)建存儲過程、調(diào)用創(chuàng)建存儲過程和運(yùn)行效果完整例子,需要的朋友可以參考下

這里用一個實例來演示PostgreSQL存儲過程如何返回數(shù)據(jù)集。

1、首先準(zhǔn)備數(shù)據(jù)表

復(fù)制代碼 代碼如下:

//member_category
create table member_category(id serial, name text, discount_rate real, base_integral integer);
alter table member_category add primary key(id);
alter table member_category add check(name<>'');

//member
create table member(id serial, member_num text, name text, category_id integer, account numeric(16,2), integral integer, phone text, birthday date, qq integer, email text, status integer, address text, tip text, start_date date, valid_date integer, password text, creator integer, store_name text);
alter table member add primary key(id);
alter table member add foreign key(creator) references employee;
alter table member add foreign key(category_id) references member_category;
alter table member add  onaccount int;

alter table member add &nbsp;onaccount int;
alter table member add &nbsp;store_name text;


2、插入測試數(shù)據(jù)
復(fù)制代碼 代碼如下:

insert into member_category(name, discount_rate, base_integral) values('白金會員', 6.5, 10000);
insert into member_category(name, discount_rate, base_integral) values('高級會員', 7.5, 1000);
insert into member_category(name, discount_rate, base_integral) values('中級會員', 8.5, 100);
insert into member_category(name, discount_rate, base_integral) values('普通會員', 9.5, 10);

insert into member(member_num, name, category_id, account, integral, phone, birthday, qq, email, onaccount, status, address, tip, start_date, valid_date, password, store_name) values('1000001', 'wuyilun', 1, 100000.00, 100000, 18814117777, '1990-12-12', 12345678, '123456@qq.com', 0, 1, 'B3-440', '超白金會員,一切免單', '2014-01-15', 1000000, 12345, '華南理工門店');
insert into member(member_num, name, category_id, account, integral, phone, birthday, qq, email, onaccount, status, address, tip, start_date, valid_date, password, store_name) values('1000002', '李小路', 2, 1000.00, 100000, 188141177234, '1990-12-12', 12345678, '123456@qq.com', 0, 1, 'B3-444', '...', '2014-01-15', 1000000, 12345, '華南理工門店');
insert into member(member_num, name, category_id, account, integral, phone, birthday, qq, email, onaccount, status, address, tip, start_date, valid_date, password, store_name) values('1000003', '洪金包', 3, 1000.00, 100000, 18814117234, '1990-12-12', 12345678, '123456@qq.com', 0, 1, 'B3-443', '...', '2014-01-15', 1000000, 12345, '華南理工門店');
insert into member(member_num, name, category_id, account, integral, phone, birthday, qq, email, onaccount, status, address, tip, start_date, valid_date, password, store_name) values('1000004', '成龍', 4, 100.00, 100000, 18814117723, '1990-12-12', 12345678, '123456@qq.com', 0, 1, 'B3-442', '...', '2014-01-15', 1000000, 12345, '華南理工門店');
insert into member(member_num, name, category_id, account, integral, phone, birthday, qq, email, onaccount, status, address, tip, start_date, valid_date, password, store_name) values('1000005', '范兵兵', 4, 100.00, 100000, 18814117327, '1990-12-12', 12345678, '123456@qq.com', 0, 1, 'B3-441', '...', '2014-01-15', 1000000, 12345, '華南理工門店');


3、創(chuàng)建存儲過程
復(fù)制代碼 代碼如下:

--調(diào)用存儲過程f_get_member_info, 返回會員的所有信息
--memberType:會員類型 status:會員狀態(tài)  findCondition:查詢條件(卡號/電話/姓名)  store_name:商店名稱  
create or replace function f_get_member_info(memberType int, status int, findCondition text, store_name text) returns setof record as
$$
declare
rec record;
begin
  for rec in EXECUTE 'select m.member_num, m.name, m_t.name, m_t.discount_rate, m.account,  m.integral, m.phone, m.birthday, m.qq, m.email, m.onAccount, m.status, m.address, m.tip, m.start_date, m.valid_date, m.store_name from member m, member_category m_t where m.category_id = m_t.id and m_t.id = '|| memberType ||' and m.status = '|| status ||' and m.store_name = '''|| store_name ||''' and (m.member_num like ''%'|| findCondition ||'%'' or m.name like ''%'|| findCondition ||'%'' or m.phone like ''%'|| findCondition ||'%'');' loop
    return next rec;
  end loop;
return;
end
$$
language 'plpgsql';

4、調(diào)用存儲過程
復(fù)制代碼 代碼如下:

--調(diào)用存儲過程f_get_member_info示例
select * from f_get_member_info(4, 1, '', '華南理工門店') as member(member_num text,mname text,name text,discount_rate real,account numeric(16,2),integral int,phone text,birthday date,qq int,email text,onAccount int,status int,address text,tip text,start_date date,valid_date int,store_nam text);

5、測試結(jié)果

相關(guān)文章

最新評論

大渡口区| 铜川市| 绿春县| 安宁市| 浦东新区| 西藏| 和平区| 牙克石市| 道孚县| 闽侯县| 苗栗县| 灵丘县| 民县| 菏泽市| 宜阳县| 威远县| 祥云县| 红原县| 成都市| 扶沟县| 舒兰市| 呈贡县| 睢宁县| 西安市| 新蔡县| 兴隆县| 许昌县| 石景山区| 罗平县| 永和县| 石嘴山市| 瑞金市| 清新县| 柞水县| 金华市| 景谷| 昌平区| 淳安县| 砀山县| 白山市| 浦东新区|