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是一种块式结构的 ...
随机推荐
- NPAIRS框架的理解
<The NPAIRS Computational Statistics Framework for Data Analysis in Neuroimaging> Strother. pe ...
- 《C++ Primer 4th》读书笔记 第6章-语句
原创文章,转载请注明出处: http://www.cnblogs.com/DayByDay/p/3912407.html
- Liunx系统学习一,liunx系统的目录结构及含义
LIUNX系统目录结构: “/” ===>这是linux文件系统的入口,也是整个linux文件系统的根目录,linux不同于windows,没有所谓的C,D,E盘,整个liunx只有一个根分区 ...
- JavaScript在IE和Firefox(火狐)的不兼容问题解决方法小结 【转】http://blog.csdn.net/uniqer/article/details/7789104
1.兼容firefox的 outerHTML,FF中没有outerHtml的方法. 代码如下: if (window.HTMLElement) { HTMLElement.prototype.__de ...
- Android-AnimationDrawable(三)运行的几种方式
项目开发用到了AnimationDrawable,调用start后没有运行,很纳闷.google搜了下.记录一下. 这个AnimationDrawable.start不能直接写在onClick,onS ...
- ECSHOP seo修改建议
ECSHOP是一个非常优秀的商城程序,以丰富的模板.稳定开源.非常快的执行速度赢得广大网店主的青眯.可是新建站30多天,目前百度只收录了首页,而google收录正常.我检查了他的网站一切正常,没有任何 ...
- 开启Ubuntu Linux下VirtualBox访问USB功能
解决方法如下: 1.增加用户组usbfs sudo groupadd usbfs 2.查看usbfs用户组的gid cat /etc/group | grep usbfs usbfs:x:1002: ...
- mybatis中的变量#与$
ibatis中使用select top #num# * from tableName出现错误.由于初次用ibatis还不知道在它里边拼写SQL语句的一些规则,导致一些自认为很平常的SQL语句,在它这里 ...
- Filezilla 多目录的访问设置
[转:http://hi.baidu.com/yangjie312/blog/item/125a8405423d896d03088171.html] 设置好主目录之后,点击“Add”按钮可以把其余的目 ...
- 【剑指offer 面试题14】调整数组顺序使奇数位于偶数前面
思路: 头尾指针,向中间遍历,依据条件交换元素. #include <iostream> using namespace std; void reOrder(int *pData, uns ...