阅读背景:

Postgre存储过程写法

来源:互联网 
declare
tempSql text;
store_refcursor refcursor; 
id BIGINT;
name VARCHAR;
exist int;

BEGIN
tempSql :="select id as storeid,storename as storename  
from kx_kq_store 
where updatetime BETWEEN """||begintime||""" AND """||endtime||"""and platstatus=1";

raise notice "tempSql is : %",tempSql;

	-- 游标遍历纪录 to_char(l.createtime,""yyyy-MM-dd"") as date
	open store_refcursor for execute tempSql;
		loop 
			fetch store_refcursor into id,name;
					if found then 
			
						-- 对数据库里有的数据就做增量修正,没有的数据就做新增
						select count(*) from bi_dim_store where storeid=id into exist;
							if exist > 0 
								then
									update bi_dim_store set storename = name,platupdatetime = now()
									where storeid=id;
							else
								  insert into bi_dim_store(storeid,storename,platcreatetime,platupdatetime) 
                                                 values (id,name,now(),now());
							end if;
					else 
				     exit;
				  end if;
		end loop;
	close store_refcursor;

ENDdeclare
tempSql text;
store_refcursor refcurso



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: