0
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
有人能幫我哪裏是我的錯誤?我相信它肯定是愚蠢的,但我無法弄清楚。請有人最早幫助我。
感謝@piro你已經打到了公牛的眼睛。我知道這很愚蠢。無論如何感謝您指出。 –
錯誤信息根本沒有幫助,我經常在這個問題上偶然發現。 – piro
是的,它不會給我們出錯的地方。 –