本文介绍了如何在没有refcursor的情况下返回postgres中的多表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sql server中有一个这样的过程:::::

  CREATE   PROC  SP_FetchData()
as
开始
选择 FirstName,LastName 来自 TBl_Users;
选择 TaskId,CreatedBy 来自 TBl_Log;
END ;



我想在postgres函数中执行相同的查询而不使用refcursor。我怎么能这样做?



我尝试过:



  CREATE   FUNCTION  SP_FetchData() RETURNS  setof refcursor  AS  
$$
DECLARE c1 refcursor ;
DECLARE c2 refcursor;
BEGIN
OPEN c1 FOR
选择 FirstName,LastName 来自 TBl_Users;
RETURN NEXT c1;

OPEN c2 FOR
选择 TaskId,CreatedBy 来自 TBl_Log;
RETURN NEXT c2;
END ;
$$ LANGUAGE ' plpgsql';





- 它工作正常但我不想使用refcursor。我该怎么办?

解决方案




I have one procedure in sql server like this:::::

CREATE PROC SP_FetchData()
as
begin
select FirstName, LastName from TBl_Users;
select TaskId,CreatedBy from TBl_Log;
END;


I want execute the same query in postgres function without using refcursor. how can I do it?

What I have tried:

CREATE FUNCTION SP_FetchData() RETURNS setof refcursor AS
$$
DECLARE c1 refcursor;
DECLARE c2 refcursor;
BEGIN
    OPEN c1 FOR
    select FirstName, LastName from TBl_Users;
    RETURN NEXT c1;

    OPEN c2 FOR
    select TaskId,CreatedBy from TBl_Log;
    RETURN NEXT c2;
END;
$$ LANGUAGE 'plpgsql';



-- It is working properly but I don't want to use refcursor. How can I do it?

解决方案




这篇关于如何在没有refcursor的情况下返回postgres中的多表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 15:34