解决postgresql -- ERROR: 42601: query has no destination for result data
I am learning Npgsql and PostgreSQL. I am unable to define the output parameter correctly. What am I doing wrong?
Here is the function:
CREATE OR REPLACE FUNCTION Insert_Customer_WithOutputParameter(
IN _FirstName character varying DEFAULT NULL::character varying,
IN _LastName character varying DEFAULT NULL::character varying,
OUT _CustomerID integer)
RETURNS integer as
$BODY$
BEGIN
INSERT INTO Customers (FirstName, LastName) VALUES (_FirstName, _LastName); SELECT _CustomerID = lastval(); END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
Here is the code:
[Test]
public void ExecuteNonQuerySproc()
{
NpgsqlConnection conn = new NpgsqlConnection("Host=localhost; Database=postgres; User ID=postgres; Password=password");
conn.Open();
IDbCommand command = conn.CreateCommand();
command.CommandText = "Insert_Customer_WithOutputParameter";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new NpgsqlParameter("@FirstName", "John"));
command.Parameters.Add(new NpgsqlParameter("@LastName", "Smith"));
NpgsqlParameter outParm = new NpgsqlParameter("@CustomerID", NpgsqlDbType.Integer)
{
Direction = ParameterDirection.Output
};
command.Parameters.Add(outParm); command.ExecuteNonQuery();
conn.Close();
Console.WriteLine(outParm.Value);
}
Here is the error message I am getting: Npgsql.NpgsqlException : ERROR: 42601: query has no destination for result data
The following doesn't work:
SELECT _CustomerID = lastval();
Replace it with a simple:
_CustomerID = lastval();
Note that Npgsql currently binds parameters by position only, and not by name. This means that the names you give in the NpgsqlParameter instances mean nothing - their order of addition must correspond to the function's declaration. Npgsql 3.1 will support named binding of function arguments (see this issue).
修改前:
-- Function: sp_updatesecurity(integer, character, character, character, character, integer, integer, character, integer) -- DROP FUNCTION sp_updatesecurity(integer, character, character, character, character, integer, integer, character, integer); CREATE OR REPLACE FUNCTION sp_updatesecurity(
OUT sqlcode_out integer,
IN parastaffid integer,
IN parafunctioncode character,
IN paraviewflag character,
IN paramodifyflag character,
IN paraadvanceflag character,
IN paralocalversion integer,
IN original_staffid integer,
IN original_functioncode character,
IN original_localversion integer)
RETURNS integer AS
$BODY$
DECLARE SQLCODE_OUT_TMP INT DEFAULT 0;
begin
IF (paraVIEWFLAG IS NULL) OR ((paraVIEWFLAG <> '') AND (paraVIEWFLAG <> '')) THEN
set SQLCODE_OUT_TMP = -1;
END IF; IF (paraMODIFYFLAG IS NULL) OR ((paraMODIFYFLAG <> '') AND (paraMODIFYFLAG <> '')) THEN
SET SQLCODE_OUT_TMP = -2;
END IF; IF (paraADVANCEFLAG IS NULL) OR ((paraADVANCEFLAG <> '') AND (paraADVANCEFLAG <> '')) THEN
SET SQLCODE_OUT_TMP = -3;
END IF; IF NOT EXISTS (SELECT *
FROM DMS.CM_STAFF
WHERE STAFFPKID = paraSTAFFID AND STATUS = '' AND (DELETED IS NULL OR DELETED = '')) THEN
SET SQLCODE_OUT_TMP = -4;
END IF; IF NOT EXISTS (SELECT *
FROM DMS.MM_FUNCTION
WHERE FUNCTIONCODE = paraFUNCTIONCODE ) THEN
SET SQLCODE_OUT_TMP = -5;
END IF; UPDATE DMS.MM_SECURITY
SET STAFFID = paraSTAFFID
, FUNCTIONCODE = paraFUNCTIONCODE
, VIEWFLAG = paraVIEWFLAG
, MODIFYFLAG = paraMODIFYFLAG
, ADVANCEFLAG = paraADVANCEFLAG
, INPUTTIME = CURRENT_TIMESTAMP
, LOCALVERSION = LOCALVERSION + 1
WHERE (STAFFID = original_STAFFID) AND (FUNCTIONCODE = original_FUNCTIONCODE) AND (LOCALVERSION = original_LOCALVERSION);
SELECT LOCALVERSION INTO paraLOCALVERSION FROM MM_SECURITY
WHERE (STAFFID = paraSTAFFID) AND (FUNCTIONCODE = paraFUNCTIONCODE);
SELECT SQLCODE_OUT_TMP; end
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION sp_updatesecurity(integer, character, character, character, character, integer, integer, character, integer)
OWNER TO postgres;
修改后:
-- Function: sp_updatesecurity(integer, character, character, character, character, integer, integer, character, integer) -- DROP FUNCTION sp_updatesecurity(integer, character, character, character, character, integer, integer, character, integer); CREATE OR REPLACE FUNCTION sp_updatesecurity(
OUT sqlcode_out integer,
IN parastaffid integer,
IN parafunctioncode character,
IN paraviewflag character,
IN paramodifyflag character,
IN paraadvanceflag character,
IN paralocalversion integer,
IN original_staffid integer,
IN original_functioncode character,
IN original_localversion integer)
RETURNS integer AS
$BODY$
DECLARE SQLCODE_OUT_TMP INT DEFAULT 0;
begin
IF (paraVIEWFLAG IS NULL) OR ((paraVIEWFLAG <> '') AND (paraVIEWFLAG <> '')) THEN
set SQLCODE_OUT_TMP = -1;
END IF; IF (paraMODIFYFLAG IS NULL) OR ((paraMODIFYFLAG <> '') AND (paraMODIFYFLAG <> '')) THEN
SET SQLCODE_OUT_TMP = -2;
END IF; IF (paraADVANCEFLAG IS NULL) OR ((paraADVANCEFLAG <> '') AND (paraADVANCEFLAG <> '')) THEN
SET SQLCODE_OUT_TMP = -3;
END IF; IF NOT EXISTS (SELECT *
FROM DMS.CM_STAFF
WHERE STAFFPKID = paraSTAFFID AND STATUS = '' AND (DELETED IS NULL OR DELETED = '')) THEN
SET SQLCODE_OUT_TMP = -4;
END IF; IF NOT EXISTS (SELECT *
FROM DMS.MM_FUNCTION
WHERE FUNCTIONCODE = paraFUNCTIONCODE ) THEN
SET SQLCODE_OUT_TMP = -5;
END IF; UPDATE DMS.MM_SECURITY
SET STAFFID = paraSTAFFID
, FUNCTIONCODE = paraFUNCTIONCODE
, VIEWFLAG = paraVIEWFLAG
, MODIFYFLAG = paraMODIFYFLAG
, ADVANCEFLAG = paraADVANCEFLAG
, INPUTTIME = CURRENT_TIMESTAMP
, LOCALVERSION = LOCALVERSION + 1
WHERE (STAFFID = original_STAFFID) AND (FUNCTIONCODE = original_FUNCTIONCODE) AND (LOCALVERSION = original_LOCALVERSION);
SELECT LOCALVERSION INTO paraLOCALVERSION FROM MM_SECURITY
WHERE (STAFFID = paraSTAFFID) AND (FUNCTIONCODE = paraFUNCTIONCODE);
sqlcode_out = SQLCODE_OUT_TMP; end
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION sp_updatesecurity(integer, character, character, character, character, integer, integer, character, integer)
OWNER TO postgres;
解决postgresql -- ERROR: 42601: query has no destination for result data的更多相关文章
- POSTGRESQL中ERROR: recursive query "t" column 2 has type character varying(150) in non-recursive term but type character varying overall
最近在做项目的时候有个需求是需要查到当前登录的用户下辖所有区域的数据,并将查询出来的部门信息以如下格式展示 最高人民法院>江苏省高级人民法院>南通市中级人民法院最高人民法院>江苏省高 ...
- ERROR: No query specified
mysql中执行show命令的时候,提示以下信息: mysql> show variables like 'datadir'\G; *************************** 1. ...
- 工作日志,error parsing query: unable to find time zone
工作日志,error parsing query: unable to find time zone 坑 Windows 系统使用influxdb数据库,在执行查询语句时提示 ERR: error p ...
- influxdb ERR: error parsing query: found -, expected
ERR: error parsing query: found -, expected 使用时遇到这个问题,执行语句: select * FROM test10-cc-core01 本来以为和sql语 ...
- MySQL查询报错 ERROR: No query specified
今天1网友,查询报错ERROR: No query specified,随后它发来截图. root case:查询语法错误 \G后面不能再加分号;,由于\G在功能上等同于;,假设加了分号,那么就是;; ...
- 解决Unknown error: Unable to build: the file dx.jar was not loaded from the SDK folder!
解决Unknown error: to the dx.jar the SDK folder!最近渐渐迁移到Android Studio来了,更新过Android SDK Manager里的东西后,打开 ...
- presto——java.sql.SQLException: Error executing query与javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?异常问题
使用presto的时候以mysql为presto的数据源 安装的presto是0.95版本:使用的presto-jdbc是0.202的,这里使用jdbc去访问时候,connection可以链接成功,但 ...
- ubuntu 16.04 + eigen3 安装(解决 fatal error: Eigen/Core: No such file or directory)
1.安装 sudo apt-get install libeigen3-dev 2. 解决 fatal error: Eigen/Core: No such file or directory 当调用 ...
- ArcGIS Server 地图服务,查询出错 Error performing query operation
Error: Error performing query operation Error Message Querying a layer from a Map Service that retur ...
随机推荐
- 11.2---字符串数组排序,删除变位词(CC150)
这道题主义的就是,要利用数组自带的sort函数. 此外,注意,利用hash来判断是否出现了. public static ArrayList<String> sortStrings(Str ...
- Js 的 this 是什么
this指的是调用函数的那个对象,谁调用函数,谁就是this 更多: http://www.cnblogs.com/justany/archive/2012/11/01/the_keyword_thi ...
- 关闭EXCEL进程
//导入Windows类库,可以获得进程ID [DllImport("User32.dll", CharSet = CharSet.Auto)] pub ...
- 使用SharePoint 2010 母版页
SharePoint 2010母版页所用的还是ASP.NET 2.0中的技术.通过该功能,实现了页面框架布局与实际内容的分离.虽然在本质上自定义母版页的过程和以前版本的SharePoint大致相同,但 ...
- poj 2524 (并查集)
http://poj.org/problem?id=2524 题意:在一所学校里面的人,都有宗教信仰,不过他们的宗教信仰有可能相同有可能不同,但你又不能直接去问他们,但你可以问他们和谁是同一个宗教.通 ...
- iOS 关于AFNetworking ssl 待完成
先普及下基本知识,都是从网上搜到的,感谢原作者的辛勤付出! 原文链接 http://m.blog.csdn.net/blog/bytxl/8586830 x509是数字证书的规范,P7和P12是两种封 ...
- cxGrid 增加序号 (非数据库绑定模式) (测试通过)
cxGrid 增加序号 (非数据库绑定模式) ----------------------------------- 1. 选在 adoQuery 控件 , 鼠标右键菜单中 选择 Fields Edi ...
- Java中的Comparable接口和Comparator接口
Comparator位于包java.util下,比较器,是在集合外部定义排序.Comparable位于包java.lang下,代表当前对象可比较的,是在集合内部实现排序. Comparable代表一个 ...
- jquery中使用event.target的几点
jquery中使用event.target的几点 1.this和event.target的区别: js中事件是会冒泡的,所以this是可以变化的,但event.target不会变化,它永远是直接接受事 ...
- 【leetcode】Excel Sheet Column Title & Excel Sheet Column Number (easy)
Given a positive integer, return its corresponding column title as appear in an Excel sheet. For exa ...