带数组参数的函数错误:您可能需要添加显式类型转换

时间:2018-06-02 16:51:04

标签: postgresql-9.4

请帮助,我在调用postgres函数时出错。

这是我的功能:

CREATE OR REPLACE FUNCTION public.eprop_budget_mt(character varying, INT[], INT[], integer, INT[], INT[], INT[], INT[])

  RETURNS TABLE(budget_year character varying, company_id integer, company_name character varying, company_code character varying, division_id integer, division_name character varying, area_id integer, region_id integer, area character varying, region character varying, subregion character varying, brand_code character varying, brand_name character varying, product_sub_type character varying, brand_id integer, kategory_id integer, activity_id integer, activity_name character varying, kategory_name character varying, produk_id integer, produk_name character varying, account_id integer, account_name character varying, row_number integer, budget_amount numeric, person_id integer, person_name character varying, position_id integer, position_name character varying, subregion_id integer, budget_str_detail_id integer, budget_str_header_id integer) AS
$BODY$

DECLARE
var_r record;
_budget_year ALIAS FOR $1;
_brand_id ALIAS FOR $2;
_person_id ALIAS FOR $3;
_division_id ALIAS FOR $4;
_area_id ALIAS FOR $5;
_activity_id ALIAS FOR $6;
_account_id ALIAS FOR $7;
_produk_id ALIAS FOR $8;
BEGIN
        FOR var_r IN (SELECT DISTINCT mtl_budget.budget_year,
                mtl_budget.company_id,
                mtl_company.company_name,
                mtl_company.company_code,
                mtl_division.id AS division_id,
                mtl_division.division_name,
                user_access_mt_acc_v.area_id,
                user_access_mt_acc_v.region_id,
                user_access_mt_acc_v.area,
                user_access_mt_acc_v.region,
                user_access_mt_acc_v.subregion,
                mtl_brand_produk.brand_code,
                mtl_brand_produk.brand_name,
                mtl_brand_produk.product_sub_type,
                mtl_brand_produk.id AS brand_id,
                activity_division_v.kategory_id,
                activity_division_v.activity_id,
                activity_division_v.activity_name,
                activity_division_v.kategory_name,
                mtl_produk.id AS produk_id,
                mtl_produk.produk_name,
                user_access_mt_acc_v.account_id,
                user_access_mt_acc_v.account_name,
                row_number() OVER () AS row_number,
                0 AS budget_amount,
                user_access_mt_acc_v.person_id,
                user_access_mt_acc_v.name AS person_name,
                user_access_mt_acc_v.position_id,
                user_access_mt_acc_v.position_name,
                user_access_mt_acc_v.subregion_id,
                mtl_budget_str_detail.id AS budget_str_detail_id,
                mtl_budget.id AS budget_str_header_id
               FROM mtl_budget
                 JOIN mtl_budget_str_detail ON mtl_budget.id = mtl_budget_str_detail.budget_hdr_id
                 JOIN mtl_company ON mtl_budget.company_id = mtl_company.id
                 JOIN mtl_brand_produk ON mtl_company.id = mtl_brand_produk.company_id AND mtl_budget_str_detail.brand_id = mtl_brand_produk.id and mtl_brand_produk.id = ANY(_brand_id::INT[])
                 JOIN user_access_mt_acc_v ON mtl_budget_str_detail.mt_account_id = user_access_mt_acc_v.account_id and user_access_mt_acc_v.person_id = ANY(_person_id::INT[])
                 JOIN activity_division_v ON mtl_budget_str_detail.cat_activity_id = activity_division_v.kategory_id AND activity_division_v.division_code::text = 'NKA'::text
                 JOIN mtl_division ON activity_division_v.division_id = mtl_division.id              
                 JOIN mtl_produk ON mtl_brand_produk.id = mtl_produk.brand_id
               WHERE mtl_budget.budget_year = _budget_year
               AND mtl_budget_str_detail.mt_account_id = ANY(_account_id) 
               AND mtl_budget_str_detail.cat_activity_id = ANY(_activity_id)
               AND activity_division_v.kategory_id= ANY(_activity_id) 
               AND mtl_brand_produk.id = ANY(_brand_id)
               AND mtl_produk.brand_id = ANY(_brand_id) 
               AND mtl_produk.id = ANY(_produk_id)  
               AND  area_id = ANY(_area_id) 
               AND user_access_mt_acc_v.account_id = ANY(_account_id) 
               AND user_access_mt_acc_v.person_id = ANY(_person_id))
          LOOP
            budget_year :=  var_r.budget_year;
            company_id  :=  var_r.company_id;
            company_name    :=  var_r.company_name;
            company_code    :=  var_r.company_code;
            division_id :=  var_r.division_id;
            division_name   :=  var_r.division_name;
            area_id :=  var_r.area_id;
            region_id   :=  var_r.region_id;
            area    :=  var_r.area;
            region  :=  var_r.region;
            subregion   :=  var_r.subregion;
            brand_code  :=  var_r.brand_code;
            brand_name  :=  var_r.brand_name;
            product_sub_type    :=  var_r.product_sub_type;
            brand_id    :=  var_r.brand_id;
            kategory_id :=  var_r.kategory_id;
            activity_id :=  var_r.activity_id;
            activity_name   :=  var_r.activity_name;
            kategory_name   :=  var_r.kategory_name;
            produk_id   :=  var_r.produk_id;
            produk_name :=  var_r.produk_name;
            account_id  :=  var_r.account_id;
            account_name    :=  var_r.account_name;
            row_number  :=  var_r.row_number;
            budget_amount   :=  var_r.budget_amount;
            person_id   :=  var_r.person_id;
            person_name :=  var_r.person_name;
            position_id :=  var_r.position_id;
            position_name   :=  var_r.position_name;
            subregion_id    :=  var_r.subregion_id;
            budget_str_detail_id    :=  var_r.budget_str_detail_id;
            budget_str_header_id    :=  var_r.budget_str_header_id;
        RETURN NEXT;
          END LOOP;

LOOP
END LOOP;

END;
$BODY$
  LANGUAGE plpgsql STABLE
  COST 100
  ROWS 1000;

这就是我调用我的功能的方式

SELECT * FROM eprop_budget_mt('2018'::character varying,'{1,2,3}'::integer[], '{159,160}'::integer[],'2'::integer,'{78,105,54}'::integer[], '{9,8}'::integer[],'{1,2,4}'::integer[],'{1,2,4}'::integer[]);

但我收到此错误

**********错误**********

错误:函数eprop_budget_mt(字符变化,整数[],整数[],整数,整数[],整数[],整数[],整数[])不存在 SQL状态:42883 提示:没有函数匹配给定的名称和参数类型。您可能需要添加显式类型转换。

请帮助解决我的问题。

非常感谢你的帮助和善意。

致以最诚挚的问候,

0 个答案:

没有答案