我的例子:

数据准备:

  1. create table custinfo(custid integer,callingcnt integer);
  2. insert into custoinfo valuse(1,10),(2,6),(3,8);

函数生成:

  1. CREATE OR REPLACE FUNCTION get_callingcnt(custid int)
  2. RETURNS TABLE (
  3. custid int
  4. ,callingcnt int
  5. ) AS
  6. $$
  7. BEGIN
  8.  
  9. RETURN QUERY
  10. SELECT t.custid
  11. ,t.callingcnt
  12. FROM custinfo t
  13. WHERE t.custid = custid;
  14.  
  15. END;
  16. $$ LANGUAGE plpgsql;

执行结果:

  1. [pgsql@localhost bin]$ ./psql
  2. psql (9.1.2)
  3. Type "help" for help.
  4.  
  5. pgsql=# select get_callcnt(1);
  6. get_callcnt
  7. -------------
  8. (1,10)
  9. (1 row)
  10.  
  11. pgsql=# select get_callcnt(2);
  12. get_callcnt
  13. -------------
  14. (2,6)
  15. (1 row)
  16.  
  17. pgsql=# \q
  18. [pgsql@localhost bin]$

PL/pgSQL的RETURN QUERY例子的更多相关文章

  1. PL/pgSQL的 RETURN NEXT例子

    从网上找到例子: 可以说,RETURN NEXT要用在循环中: 例子一: 数据准备: CREATE TABLE foo (fooid INT, foosubid INT, fooname TEXT); ...

  2. PL/pgSQL多输出参数例子

    例子一,不带returns: postgres=# CREATE FUNCTION sum_n_product(x int, y int, OUT sum int, OUT prod int) AS ...

  3. PL/pgSQL RETURNS TABLE 例子

    实验如下: RETURNS TABLE 中的变量名和SQL文中的变量名同名时,执行时会出错: pgsql=# create table sales(itemno integer,quantity in ...

  4. PL/pgSQL学习笔记之八

    http://www.postgresql.org/docs/9.1/static/plpgsql-declarations.html 另外一种声明 PL/pgSQL 函数的方法是使用 returns ...

  5. PL/pgSQL学习笔记之三

    http://www.postgresql.org/docs/9.1/static/plpgsql-overview.html 39.1.2. Supported Argument and Resul ...

  6. 用PL/pgSQL写postgreSQL的存储过程[转]

    http://blog.chinaunix.net/uid-7591044-id-1742967.html 今天学会了用 PL/pgSQL 写 postgreSQL 的存储过程,网上资料实在少得可怜, ...

  7. PL/pgSQL学习笔记之七

    http://www.postgresql.org/docs/9.1/static/plpgsql-declarations.html 如果一个PL/pgSQL函数声明了输出参数,输出参数被赋予$n名 ...

  8. PL/pgSQL学习笔记之五

    http://www.postgresql.org/docs/9.1/static/plpgsql-declarations.html 39.3. 声明 块中使用的所有的变量必须在块的声明节中进行声明 ...

  9. PL/pgSQL学习笔记之四

    http://www.postgresql.org/docs/9.1/static/plpgsql-structure.html 39.2. PL/pgSQL 的结构 PL/pgSQL是一种块式结构的 ...

随机推荐

  1. 【转】eclipse中egit插件使用

    原文网址:http://my.oschina.net/songxinqiang/blog/192567 eclipse和git这个两个工具的使用人数都是相当多的,在eclipse里面也有egit插件来 ...

  2. Android-给另一个Activity传递HashMap

    I have a HashMap which I would pass to another Activity class. I simply use this code: Intent intent ...

  3. MyBatis 如何接收参数

    MyBatis的mapper接口不需要自己实现,框架会自动帮我们实现,到时候直接调用就可以了.定义的mapper接口中的方法可以有多个参数吗?答案是肯定.在Ibatis时代是自己通过代码实现如何调用x ...

  4. 头痛的ASCII和preg_replace()

    说这个之前,大家先看下这条语句: preg_replace("/\<\?\=(\\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\[\]\"\'\$\x7f- ...

  5. [转] c#中 多线程访问winform控件

    原文 c#中多线程访问winform控件的若干问题小结 我们在做winform应用的时候,大部分情况下都会碰到使用多线程控制界面上控件信息的问题.然而我们并不能用传统方法来解决这个问题,下面我将详细的 ...

  6. [Everyday Mathematics]20150109

    设 $A$ 是 $n$ 阶复方阵, 其特征多项式为 $$\bex f(\lm)=(\lm-\lm_1)^{n_1}\cdots(x-\lm_s)^{n_s}, \eex$$ 其中 $\lm_i$ 互不 ...

  7. 【LeetCode 209】Minimum Size Subarray Sum

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  8. 【LeetCode 213】House Robber II

    This is an extension of House Robber. After robbing those houses on that street, the thief has found ...

  9. bzoj 2818 Gcd(欧拉函数 | 莫比乌斯反演)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2818 [题意] 问(x,y)为质数的有序点对的数目. [思路一] 定义f[i]表示i之 ...

  10. CentOS下编译安装hping3

    安装hping之前,先装上libpcap-dev和tcl-dev 1.获取源码包 wget http://www.hping.org/hping3-20051105.tar.gz 2.解压,得到 hp ...