如何在 Postgres Procedure 中使用 IN 和 INOUT 值调用过程

How to call procedure with IN and INOUT values in Postgres Procedure

我已经在 AWS SCT(模式转换工具)的帮助下将 oracle 数据库迁移到 RDS AWS 上的 Aurora Postgresql。 Oracle 中的一些包以以下格式转换为 postgres。

CREATE OR REPLACE PROCEDURE miptd."pkg_rpt$strptst"(i_molo text,INOUT o_cursor refcursor)
LANGUAGE 'plpgsql'
AS $BODY$
DECLARE

    o_cursor$ATTRIBUTES aws_oracle_data.TCursorAttributes;
    
BEGIN   
    o_cursor := NULL;
    OPEN o_cursor FOR
    
    EXECUTE CONCAT_WS('','select count(ID) From 
                        (select DISTINCT D.ID, B.CSS_DISTRICT, B.RDA, C.TECH_TYPE, C.FORECAST_DATE, D.SITE_TYPE
                        FROM
                        ALB.VIEWSIRPT B, 
                        ALB.VIEWWRDATA C,
                        ALB.', i_molo, ' D
                        WHERE
                        (D.CSR = C.CSR) AND (D.CUSTOMER = C.CUSTOMER)
                        AND (D.CSR = B.CSR ) AND (D.CUSTOMER = B.CUSTOMER )  )a ');

    o_cursor$ATTRIBUTES := ROW (TRUE, 0, NULL, NULL);
END;
$BODY$;

不知道游标在 postgres 中的使用 我如何调用程序。 ? 我在哪里可以通过调用过程看到我的结果值? 可以将其转换为函数吗?

你应该使用一个函数,你应该避免SQL注入:

CREATE function some_name(i_molo text) RETURNS bigint
   LANGUAGE plpgsql AS
$$BEGIN
   RETURN EXECUTE
      format('SELECT count(ID)
              FROM (SELECT DISTINCT D.ID,
                                    B.CSS_DISTRICT,
                                    B.RDA, C.TECH_TYPE,
                                    C.FORECAST_DATE,
                                    D.SITE_TYPE
                    FROM ALB.%I D
                       JOIN ALB.VIEWWRDATA C
                          ON D.CUSTOMER = C.CUSTOMER AND D.CSR = C.CSR
                       JOIN ALB.VIEWSIRPT B
                          ON D.CUSTOMER = B.CUSTOMER AND D.CSR = B.CSR
                   ) AS a',
              i_molo);
END;$$;