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

PostgreSQL中調(diào)用存儲(chǔ)過程并返回?cái)?shù)據(jù)集實(shí)例

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

這里用一個(gè)實(shí)例來演示PostgreSQL存儲(chǔ)過程如何返回?cái)?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('白金會(huì)員', 6.5, 10000);
insert into member_category(name, discount_rate, base_integral) values('高級(jí)會(huì)員', 7.5, 1000);
insert into member_category(name, discount_rate, base_integral) values('中級(jí)會(huì)員', 8.5, 100);
insert into member_category(name, discount_rate, base_integral) values('普通會(huì)員', 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', '超白金會(huì)員,一切免單', '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)建存儲(chǔ)過程
復(fù)制代碼 代碼如下:

--調(diào)用存儲(chǔ)過程f_get_member_info, 返回會(huì)員的所有信息
--memberType:會(huì)員類型 status:會(huì)員狀態(tài)  findCondition:查詢條件(卡號(hào)/電話/姓名)  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)用存儲(chǔ)過程
復(fù)制代碼 代碼如下:

--調(diào)用存儲(chǔ)過程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)文章

  • PostgreSql新手必學(xué)入門命令小結(jié)

    PostgreSql新手必學(xué)入門命令小結(jié)

    這篇文章主要介紹了PostgreSql新手必學(xué)入門命令小結(jié),本文講解了命令行登錄數(shù)據(jù)庫、查看幫助、常用命令等內(nèi)容,需要的朋友可以參考下
    2015-02-02
  • PostgreSQL管理工具phpPgAdmin入門指南

    PostgreSQL管理工具phpPgAdmin入門指南

    phpPgAdmin是用PHP開發(fā)的一個(gè)基于web的PostgreSQL數(shù)據(jù)庫管理工具。和MySql時(shí)代的PHPMyAdmin類似。本文介紹了phpPgAdmin安裝和使用方法,需要的朋友可以參考下
    2014-03-03
  • 常用?PostgreSQL?數(shù)據(jù)恢復(fù)方案及使用示例

    常用?PostgreSQL?數(shù)據(jù)恢復(fù)方案及使用示例

    這篇文章主要介紹了常用?PostgreSQL?數(shù)據(jù)恢復(fù)方案概覽,數(shù)據(jù)丟失通常是由?DDL?與?DML?兩種操作引起,由于在操作系統(tǒng)中表文件已經(jīng)不存在,所以只能采用恢復(fù)磁盤的方法進(jìn)行數(shù)據(jù)恢復(fù),需要的朋友可以參考下
    2022-01-01
  • postgresql13主從搭建Ubuntu

    postgresql13主從搭建Ubuntu

    這篇文章主要為大家介紹了postgresql13主從搭建Ubuntu實(shí)現(xiàn)過程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • postgresql流復(fù)制原理以及流復(fù)制和邏輯復(fù)制的區(qū)別說明

    postgresql流復(fù)制原理以及流復(fù)制和邏輯復(fù)制的區(qū)別說明

    這篇文章主要介紹了postgresql流復(fù)制原理以及流復(fù)制和邏輯復(fù)制的區(qū)別說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • postgresql 數(shù)據(jù)庫 與TimescaleDB 時(shí)序庫 join 在一起

    postgresql 數(shù)據(jù)庫 與TimescaleDB 時(shí)序庫 join 在一起

    這篇文章主要介紹了postgresql 數(shù)據(jù)庫 與TimescaleDB 時(shí)序庫 join 在一起,需要的朋友可以參考下
    2020-12-12
  • postgresql減少wal日志生成量的操作

    postgresql減少wal日志生成量的操作

    這篇文章主要介紹了postgresql減少wal日志生成量的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • postgresql 替換空格 換行和回車的操作

    postgresql 替換空格 換行和回車的操作

    這篇文章主要介紹了postgresql 替換空格 換行和回車的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • postgresql 中的COALESCE()函數(shù)使用小技巧

    postgresql 中的COALESCE()函數(shù)使用小技巧

    這篇文章主要介紹了postgresql 中的COALESCE()函數(shù)使用小技巧,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • PostgreSQL 自動(dòng)Vacuum配置方式

    PostgreSQL 自動(dòng)Vacuum配置方式

    這篇文章主要介紹了PostgreSQL 自動(dòng)Vacuum配置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01

最新評(píng)論

如皋市| 澄城县| 阿勒泰市| 石狮市| 徐闻县| 仪征市| 体育| 四会市| 宁海县| 南木林县| 宣汉县| 福州市| 吴堡县| 扎赉特旗| 达州市| 安顺市| 儋州市| 台南县| 斗六市| 同江市| 肇州县| 潞城市| 房产| 社会| 类乌齐县| 手游| 富阳市| 长春市| 邢台县| 昆明市| 德安县| 朔州市| 全州县| 英德市| 赞皇县| 定结县| 农安县| 大邑县| 香港| 青海省| 东阿县|