PL/pgSQL的RETURN QUERY例子
我的例子:
数据准备:
- create table custinfo(custid integer,callingcnt integer);
- insert into custoinfo valuse(1,10),(2,6),(3,8);
函数生成:
- CREATE OR REPLACE FUNCTION get_callingcnt(custid int)
- RETURNS TABLE (
- custid int
- ,callingcnt int
- ) AS
- $$
- BEGIN
- RETURN QUERY
- SELECT t.custid
- ,t.callingcnt
- FROM custinfo t
- WHERE t.custid = custid;
- END;
- $$ LANGUAGE plpgsql;
执行结果:
- [pgsql@localhost bin]$ ./psql
- psql (9.1.2)
- Type "help" for help.
- pgsql=# select get_callcnt(1);
- get_callcnt
- -------------
- (1,10)
- (1 row)
- pgsql=# select get_callcnt(2);
- get_callcnt
- -------------
- (2,6)
- (1 row)
- pgsql=# \q
- [pgsql@localhost bin]$
PL/pgSQL的RETURN QUERY例子的更多相关文章
- PL/pgSQL的 RETURN NEXT例子
从网上找到例子: 可以说,RETURN NEXT要用在循环中: 例子一: 数据准备: CREATE TABLE foo (fooid INT, foosubid INT, fooname TEXT); ...
- PL/pgSQL多输出参数例子
例子一,不带returns: postgres=# CREATE FUNCTION sum_n_product(x int, y int, OUT sum int, OUT prod int) AS ...
- PL/pgSQL RETURNS TABLE 例子
实验如下: RETURNS TABLE 中的变量名和SQL文中的变量名同名时,执行时会出错: pgsql=# create table sales(itemno integer,quantity in ...
- PL/pgSQL学习笔记之八
http://www.postgresql.org/docs/9.1/static/plpgsql-declarations.html 另外一种声明 PL/pgSQL 函数的方法是使用 returns ...
- PL/pgSQL学习笔记之三
http://www.postgresql.org/docs/9.1/static/plpgsql-overview.html 39.1.2. Supported Argument and Resul ...
- 用PL/pgSQL写postgreSQL的存储过程[转]
http://blog.chinaunix.net/uid-7591044-id-1742967.html 今天学会了用 PL/pgSQL 写 postgreSQL 的存储过程,网上资料实在少得可怜, ...
- PL/pgSQL学习笔记之七
http://www.postgresql.org/docs/9.1/static/plpgsql-declarations.html 如果一个PL/pgSQL函数声明了输出参数,输出参数被赋予$n名 ...
- PL/pgSQL学习笔记之五
http://www.postgresql.org/docs/9.1/static/plpgsql-declarations.html 39.3. 声明 块中使用的所有的变量必须在块的声明节中进行声明 ...
- PL/pgSQL学习笔记之四
http://www.postgresql.org/docs/9.1/static/plpgsql-structure.html 39.2. PL/pgSQL 的结构 PL/pgSQL是一种块式结构的 ...
随机推荐
- 【转】eclipse中egit插件使用
原文网址:http://my.oschina.net/songxinqiang/blog/192567 eclipse和git这个两个工具的使用人数都是相当多的,在eclipse里面也有egit插件来 ...
- Android-给另一个Activity传递HashMap
I have a HashMap which I would pass to another Activity class. I simply use this code: Intent intent ...
- MyBatis 如何接收参数
MyBatis的mapper接口不需要自己实现,框架会自动帮我们实现,到时候直接调用就可以了.定义的mapper接口中的方法可以有多个参数吗?答案是肯定.在Ibatis时代是自己通过代码实现如何调用x ...
- 头痛的ASCII和preg_replace()
说这个之前,大家先看下这条语句: preg_replace("/\<\?\=(\\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\[\]\"\'\$\x7f- ...
- [转] c#中 多线程访问winform控件
原文 c#中多线程访问winform控件的若干问题小结 我们在做winform应用的时候,大部分情况下都会碰到使用多线程控制界面上控件信息的问题.然而我们并不能用传统方法来解决这个问题,下面我将详细的 ...
- [Everyday Mathematics]20150109
设 $A$ 是 $n$ 阶复方阵, 其特征多项式为 $$\bex f(\lm)=(\lm-\lm_1)^{n_1}\cdots(x-\lm_s)^{n_s}, \eex$$ 其中 $\lm_i$ 互不 ...
- 【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 ...
- 【LeetCode 213】House Robber II
This is an extension of House Robber. After robbing those houses on that street, the thief has found ...
- bzoj 2818 Gcd(欧拉函数 | 莫比乌斯反演)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2818 [题意] 问(x,y)为质数的有序点对的数目. [思路一] 定义f[i]表示i之 ...
- CentOS下编译安装hping3
安装hping之前,先装上libpcap-dev和tcl-dev 1.获取源码包 wget http://www.hping.org/hping3-20051105.tar.gz 2.解压,得到 hp ...