免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 13066 | 回复: 2
打印 上一主题 下一主题

求助!postgresql 动态sql执行问题报错! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-06-03 11:32 |只看该作者 |倒序浏览
写了个存储过程。里面嵌入了这么条语句。
execute 'select count(*) from  temp_crm_info_t where searchengine_id = $1' into count
    using in_searchengine_id;
    return count;
-------------------------------------------------------编译的时候报错
ERROR:  syntax error at or near "using"
LINE 21:     using in_searchengine_id;
             ^

********** 错误 **********

ERROR: syntax error at or near "using"
SQL 状态: 42601
字符:1415
---------------------------------------------但是我查参考手册postgresql-9.2-A4.pdf
里面是有类似写法的。
EXECUTE ’SELECT count(*) FROM ’
|| tabname::regclass
|| ’ WHERE inserted_by = $1 AND inserted <= $2’
INTO c
USING checked_user, checked_date;
---------------------------------------------请懂行的帮忙指点一下,谢谢

论坛徽章:
3
数据库技术版块每日发帖之星
日期:2015-06-18 22:20:00数据库技术版块每日发帖之星
日期:2015-06-21 22:20:00数据库技术版块每日发帖之星
日期:2015-08-27 06:20:00
2 [报告]
发表于 2013-06-06 00:17 |只看该作者
本帖最后由 osdba 于 2013-06-06 00:18 编辑

osdba=# CREATE FUNCTION myfunc() RETURNS integer AS $$
osdba$# DECLARE
osdba$#     in_searchengine_id integer;
osdba$#     count integer;
osdba$# BEGIN
osdba$#     in_searchengine_id :=10;
osdba$#     execute 'select count(*) from  temp_crm_info_t where searchengine_id = $1' into count
osdba$#     using in_searchengine_id;
osdba$#     return count;   
osdba$# END;
osdba$# $$ LANGUAGE plpgsql;
CREATE FUNCTION

没有错误啊? 你是否是在"using"前输入了中文啊?

论坛徽章:
0
3 [报告]
发表于 2013-12-17 16:04 |只看该作者
lS正解。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP