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

时间:2014-06-06 11:42:35

标签: sql postgresql

我在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(整数,整数,日期)第3行

2 个答案:

答案 0 :(得分:6)

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;

答案 1 :(得分:4)

此代码正常运行:

postgres=# create table xx(a int);
CREATE TABLE

postgres=# create or replace function bu(int) returns int as 
             $$declare x int; 
             begin 
               insert into xx values($1) returning a into x; 
               return x; 
             end $$ language plpgsql;
CREATE FUNCTION

postgres=# select bu(10);
 bu 
────
 10

(1行)

因为它与你的代码相同,我希望,所以你使用一些非常古老的Postgres。我记得pg中的类似错误,但已经修复了五年多。

相关问题