1

我有 oracle 存储过程,它具有三个输入参数和四个输出参数。存储过程查表很少,有一些逻辑,不是很复杂,但是根据不同的条件查找很多。另一个系统想要使用相同的逻辑。不幸的是,调用存储过程或将逻辑放入 SQL 对他们来说成本更高(人工天数)。他们希望访问视图或表并使用 where 子句过滤器获取结果。是否有任何模式或建议的方法来实现这一目标?

如果您需要更多信息,请与我们联系。

我可以将存储过程更改为函数或任何需要的内容,但不能更改接口系统。这是一些代码。

CREATE OR REPLACE PACKAGE BODY PKG_TEST
IS
    FUNCTION F_DETERMINE_SOMETHING
    (
        i_location_id IN T_SYSTEM_LOCATION.SYSTEM_LOCATION_ID%TYPE,
        i_customer_id IN T_CUSTOMER.CUSTOMER_ID%TYPE,
        i_ccy IN T_CURRENCY.CCY_ID%TYPE
    )
    RETURN RC_SOME_ACCT_INFO
    IS
        o_some_acct_info RC_SOME_ACCT_INFO;
        CURSOR some_acct_cursor IS
        select some_acct_id,
               area,
               portfolio
        from t_override_some_acct
        where customer_id = i_customer_id
            and SYSTEM_location_id = i_location_id
            and ccy1_id = i_ccy;
    BEGIN
        OPEN some_acct_cursor;
        FETCH some_acct_cursor into o_some_acct_info.tdr_id, o_some_acct_info.bk_area, o_some_acct_info.bk_portfolio;
        CLOSE some_acct_cursor;

        return o_some_acct_info;
    END F_DETERMINE_SOMETHING;


    FUNCTION F_GET_SOME_ACCT_GRT
    (
        i_location_id IN T_SYSTEM_LOCATION.SYSTEM_LOCATION_ID%TYPE,
        i_ccy IN T_CURRENCY.CCY_ID%TYPE
    )
    RETURN RC_SOME_ACCT_INFO
    IS
      o_some_acct_info RC_SOME_ACCT_INFO;

      CURSOR SYSTEM_location_accounts_cursor IS
      select risk_account,
      risk_area
      from V_SYSTEM_LOCATION_ACCTS
      where SYSTEM_location_id = i_location_id
      and ccy1_id = i_ccy;

      CURSOR SYSTEM_location_traderId_cursor IS
      select autopric_tdr_id
      from V_SYSTEM_LOCATION
      where SYSTEM_location_id = i_location_id;

    BEGIN
      OPEN SYSTEM_location_accounts_cursor;
       FETCH SYSTEM_location_accounts_cursor into o_some_acct_info.bk_portfolio, o_some_acct_info.bk_area;
      CLOSE SYSTEM_location_accounts_cursor;

      OPEN SYSTEM_location_traderId_cursor;
       FETCH SYSTEM_location_traderId_cursor into o_some_acct_info.tdr_id;
      CLOSE SYSTEM_location_traderId_cursor;

      return o_some_acct_info;

    END F_GET_SOME_ACCT_GRT;


    FUNCTION F_DETERMINE_SOME_ACCT
    (
        i_location_id IN T_SYSTEM_LOCATION.SYSTEM_LOCATION_ID%TYPE,
        i_customer_id IN T_CUSTOMER.CUSTOMER_ID%TYPE,
        i_bought_ccy IN T_CURRENCY.CCY_ID%TYPE,
        i_sold_ccy IN T_CURRENCY.CCY_ID%TYPE
    )
    RETURN RC_SOME_ACCT_INFO
    IS
        o_some_acct_ids RC_SOME_ACCT_INFO;
        v_SYSTEM_location_id T_SYSTEM_LOCATION.SYSTEM_LOCATION_ID%TYPE;

    BEGIN
        v_SYSTEM_location_id := i_location_id;

      if (v_SYSTEM_location_id <> 4) then
      begin
          o_some_acct_ids := F_DETERMINE_SOMETHING( v_SYSTEM_location_id, i_customer_id, i_bought_ccy );

          if ( o_some_acct_ids.bk_area is null OR o_some_acct_ids.bk_portfolio is null) then
          begin
              o_some_acct_ids := F_DETERMINE_SOMETHING( v_SYSTEM_location_id, i_customer_id, i_sold_ccy );

              if ( o_some_acct_ids.bk_area is null OR o_some_acct_ids.bk_portfolio is null) then
              begin
                  o_some_acct_ids := F_DETERMINE_SOMETHING( v_SYSTEM_location_id, i_customer_id, PKG_CONSTANTS.C_OTH_VALUE );

                      if ( o_some_acct_ids.bk_area is null OR o_some_acct_ids.bk_portfolio is null ) then
                      begin
                          v_SYSTEM_location_id := PKG_CONSTANTS.C_SYSTEM_LOCATION_ALL;

                          o_some_acct_ids := F_DETERMINE_SOMETHING( v_SYSTEM_location_id, i_customer_id, i_bought_ccy );

                          if ( o_some_acct_ids.bk_area is null OR o_some_acct_ids.bk_portfolio is null ) then
                          begin
                              o_some_acct_ids := F_DETERMINE_SOMETHING( v_SYSTEM_location_id, i_customer_id, i_sold_ccy );

                              if ( o_some_acct_ids.bk_area is null OR o_some_acct_ids.bk_portfolio is null ) then
                              begin
                                  o_some_acct_ids := F_DETERMINE_SOMETHING( v_SYSTEM_location_id, i_customer_id, PKG_CONSTANTS.C_OTH_VALUE );
                              end;
                              end if;
                          end;
                          end if;
                      end;
                      end if;
              end;
              end if;
          end;
          end if;
      end;
      else
        o_some_acct_ids := F_GET_SOME_ACCT_GRT(v_SYSTEM_location_id, i_bought_ccy );
         if ( o_some_acct_ids.bk_area is null OR o_some_acct_ids.bk_portfolio is null ) then
         begin
            o_some_acct_ids := F_GET_SOME_ACCT_GRT(v_SYSTEM_location_id, i_sold_ccy );
            if ( o_some_acct_ids.bk_area is null OR o_some_acct_ids.bk_portfolio is null ) then
            begin
              o_some_acct_ids := F_GET_SOME_ACCT_GRT(v_SYSTEM_location_id, PKG_CONSTANTS.C_OTH_VALUE );
            end;
            end if;
         end;
         end if;
      end if;
      return o_some_acct_ids;
    END F_DETERMINE_SOME_ACCT;

    PROCEDURE P_RETRIEVE_SYSM_CUST_DETAILS (
        i_sysm_short_name IN T_CUSTOMER.SYSM_CUSTOMER_ID%TYPE,
        i_sysm_legal_entity IN T_SYSM_LEI_LOCATION_MAPPING.SYSM_LEGAL_ENTITY%TYPE,
        i_bought_ccy IN T_CURRENCY.CCY_ID%TYPE,
        i_sold_ccy IN T_CURRENCY.CCY_ID%TYPE,
        o_sysw_customer_id OUT T_CUSTOMER.SYSW_CUST_ID%TYPE,
        o_sysw_city OUT T_CUSTOMER.CITY%TYPE,
        o_tdr_id OUT T_OVERRIDE_SOME_ACCT.SOME_ACCT_ID%TYPE,
        o_bk_area OUT T_OVERRIDE_SOME_ACCT.AREA%TYPE,
        o_bk_portfolio OUT T_OVERRIDE_SOME_ACCT.PORTFOLIO%TYPE,
        o_error OUT varchar2
    )
    IS
        v_SYSTEM_location_id T_SYSTEM_LOCATION.SYSTEM_LOCATION_ID%TYPE;
        v_customer_id T_CUSTOMER.CUSTOMER_ID%TYPE;
        v_city T_CUSTOMER.CITY%TYPE;
        v_sysw_cust_id T_CUSTOMER.SYSW_CUST_ID%TYPE;

        o_some_acct_ids RC_SOME_ACCT_INFO;

        CURSOR customer_cursor IS
        select customer_id, sysw_cust_id, city
        from v_customer
        where sysm_customer_id = UPPER(i_sysm_short_name);

        CURSOR lei_location_cursor IS
        select location_id
        from T_SYSM_LEI_LOCATION_MAPPING
        where sysm_legal_entity = UPPER(i_sysm_legal_entity);
    BEGIN
       open lei_location_cursor;
       FETCH lei_location_cursor into v_SYSTEM_location_id;
       close lei_location_cursor;

       open customer_cursor;
       FETCH customer_cursor into v_customer_id,v_sysw_cust_id,v_city;
       close customer_cursor;
       o_some_acct_ids := F_DETERMINE_SOME_ACCT(v_SYSTEM_location_id, v_customer_id, i_bought_ccy, i_sold_ccy);

        if ( o_some_acct_ids.bk_area is null OR o_some_acct_ids.bk_portfolio is null ) then
            o_error := '<<Error: Data not found>>';
        else
            o_sysw_customer_id := v_sysw_cust_id;
            o_sysw_city := v_city;
            o_tdr_id := o_some_acct_ids.tdr_id;
            o_bk_area := o_some_acct_ids.bk_area;
            o_bk_portfolio := o_some_acct_ids.bk_portfolio;
            o_error := null;
        end if;
    END P_RETRIEVE_SYSM_CUST_DETAILS;
END PKG_TEST;

P_RETRIEVE_SYSM_CUST_DETAILS 是应该用视图替换的过程。

4

1 回答 1

3

您可以使用流水线函数包装您的过程。

可能是这样的——

create type t_out_params as object
(
  o_1 number,
  o_2 number,
  o_3 number,
  o_4 number
);

create type t_out_params_tab is table of t_out_params;

create function f(i_1 number, i_2 number, i_3 number) return t_out_params_tab pipelined as
begin
  -- in this example I just calculated things with the input parameters
  -- you can run your logic or stored procedure and get the 4 out parameters
  -- instead (should initialize t_out_params)
  pipe row(t_out_params(i_1*2, i_2+10, i_3, i_1+i_2+i_3));
return;
end;

这是一个 sqlfiddle 示例

于 2013-05-28T04:36:19.123 回答