我创建了一个函数PostgreSQL以插入以下内容
PostgreSQL
CREATE TABLE gtab83 ( orderid integer NOT NULL DEFAULT nextval('seq_gtab83_id'::regclass), acid integer, slno integer, orderdte date )
并创建的Function是
Function
CREATE OR REPLACE FUNCTION funcInsert(iacid int,islno int,idate date) RETURNS int AS $$ declare id_val int; BEGIN INSERT INTO GTAB83 (acid,slno,orderdte) VALUES (iacid,islno,idate) RETURNING orderid into id_val; return id_val; END; $$ LANGUAGE plpgsql;
选择funcInsert(666,13,‘2014-06-06’
错误:查询没有结果数据的目标上下文:SQL语句中的PL / pgSQL函数procgtab83(integer,integer,date)第3行
create or replace function funcinsert(iacid int, islno int, idate date) returns int as $$ declare id_val int; begin with i as ( insert into gtab83 (acid,slno,orderdte) values (iacid,islno,idate) returning orderid ) select orderid into id_val from i; return id_val; end; $$ language plpgsql;
它可以比普通sql简单得多
create or replace function funcinsert(iacid int, islno int, idate date) returns int as $$ insert into gtab83 (acid,slno,orderdte) values (iacid,islno,idate) returning orderid ; $$ language sql;