2017-07-26 50 views
1
CREATE OR REPLACE FUNCTION public.merge_test (
    r_obj refcursor, 
    _ldeptid character varying 
) RETURNS refcursor 
    LANGUAGE 'plpgsql' COST 100.0 VOLATILE AS $function$ 
BEGIN 
    DROP TABLE IF EXISTS tblCumulate;  
    create temp table tblCumulate (
     lCompid varchar(10), 
     lOpenCount int default 0, 
     lClosedCount int default 0 
    ); 
    DROP TABLE IF EXISTS tblOpen; 
    create temp table tblOpen (
     lOSID SERIAL, 
     lCount numeric(24,0), 
     lCompid varchar(100) 
    ); 
    MERGE into tblCumulate CUM using (select lcompid,lCount from tblopen) as OP 
     on CUM.lcompid=OP.lcompid 
     when matched 
     then update set cum.lOpenCount=op.lcount 
     when not matched 
     then insert (lCompid,lOpenCount) values op.lcompid,op.lcount); 
    open r_obj for 
     select * from tblCumulate; 
    return r_obj; 
END; 
$function$; 

當我執行(運行)此過程顯示以下錯誤。合併聲明與臨時表

ERROR: "tblcumulate" is not a known variable 
LINE 41: MERGE into tblCumulate CUM temp 
+0

您正在使用某些第三方PostgreSQL分支或修改版本。請確定您使用的確切數據庫服務器。 'SELECT version()'是一個好的開始。 –

回答