我创建了一个函数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’
procgtab83(integer,integer,date)
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;
It can be much simpler as plain 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;