小编典典

错误:查询没有结果数据的目的地

sql

我创建了一个函数PostgreSQL以插入以下内容

  CREATE TABLE gtab83
(
  orderid integer NOT NULL DEFAULT nextval('seq_gtab83_id'::regclass),
  acid integer,
  slno integer,
  orderdte date
)

并创建的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行


阅读 172

收藏
2021-05-23

共1个答案

小编典典

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;
2021-05-23