gpt4 book ai didi

function - Postgres函数创建返回 `syntax error at or near “LOOP”`

转载 作者:行者123 更新时间:2023-12-02 10:54:54 27 4
gpt4 key购买 nike

CREATE OR REPLACE FUNCTION ccdb_dummy.o_bills_new(a integer)
RETURNS void AS
$BODY$
DECLARE
bill_no bigint;
lc_cin_num bigint;
lc_consumer_num bigint;
lc_bill_type_group_code character varying(10);
t ccdb_stg.o_bills_stg%ROWTYPE;
t1 ccdb_stg.o_bills_details_stg%ROWTYPE;
BEGIN

FOR t IN
SELECT *
FROM ccdb_stg.o_bills_stg
WHERE section_code = a
LOOP
bill_no := nextval('ccdb_stg_test.bills_seq');

IF t.consumer_num IS NULL THEN
lc_consumer_num = t.applicant_num;
ELSE
lc_consumer_num = t.consumer_num;

SELECT bill_type
INTO lc_bill_type_group_code
FROM ccdb_dummy.bill_type_master a
WHERE a.bill_type_id = t.bill_type_id;

SELECT cin
INTO lc_cin_num
FROM ccdb_dummy.consumers b
WHERE b.consumer_num = lc_consumer_num;

INSERT INTO ccdb_dummy.bills(bill_id,source_system_id,mbc_bill_id,mbc_bill_no,cin,cust_connection_id,consumer_number,cust_type_flag,bill_type_group_code,bill_type_code,bill_month,total_consumption,bill_date,due_date,dc_date,dues_remind_date,dc_remind_date,org_unit_id,parent_bill_id,category_flag,status_flag,conn_cat_subgroup_id,dispute_flag,inst_flag,approved_date,bill_amt,paid_amt,past_arrear,arrear_collected,advance_amount,creation_dt,created_by)
VALUES (bill_no,1,t.mbc_bill_id,t.mbc_bill_no,lc_cin_num,t.cust_connection_id,lc_consumer_num,t.cust_type_flag,t.bill_type_group_code,lc_bill_type_group_code,t.bill_month,
t.total_consumption,t.bill_date,t.due_date,t.dc_date,t.dues_remaind_date,t.dc_remaind_date,t.section_code,t.parent_bill_id,t.category_flag,t.status_flag,
t.conn_cat_subgroup_id,t.dispute_flag,t.inst_flag,t.approved_date,t.bill_amt,t.paid_amt,t.past_arrear,t.arrear_collected,t.advance_amount,now(),'system');

FOR t1 IN
SELECT *
FROM ccdb_stg.o_bills_details_stg a
WHERE a.mbc_bill_id = t.mbc_bill_id
LOOP
INSERT INTO ccdb_dummy.bill_head_details(bill_id,charge_head_code,amount_billed,amount_paid,charge_head_descr,ccdb_update_time,creation_dt,created_by,tariff_id,
demand_date)
VALUES
(bill_no,t1.charge_head_code,t1.amount_billed,t1.amount_paid,null,now(),now(),'system',t1.tariff_id,t1.demand_date);
END LOOP;
END LOOP;

END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION ccdb_dummy.o_bills_new(integer)
OWNER TO ccdb_admin;

当我尝试编译此函数时,出现以下错误:
ERROR:  syntax error at or near "LOOP"
LINE 58: END LOOP;
^
********** Error **********
ERROR: syntax error at or near "LOOP"
SQL state: 42601
Character: 2282

我的错误在哪里?我敢肯定这一定是愚蠢的,但是我无法弄清楚。

最佳答案

我认为您缺少END IF。

关于function - Postgres函数创建返回 `syntax error at or near “LOOP”`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21905916/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com