postgresql 存储过程的事务处理
来源:百度知道 编辑:UC知道 时间:2024/05/10 11:07:44
能给我一段PGSQL的存储过程事务处理的代码就好了,谢谢!!
一个PostgreSQL存储过程的例子
需求:
给出如下条件进行批处理编排
- 开始日期时间
- 重复间隔(分钟)
- 重复次数
要求在档期内重复安排节目播出, 比如: 2003.01.01 08:00 开始每隔240分钟播出一次, 一共播出100次
数据库表格(CO_SCHEDULE)
------------------------------
N_PROGID INT
DT_STARTTIME TIMESTAMP
DT_ENDTIME TIMESTAMP
存储过程的实现:
create table co_schedule(n_progid int,dt_starttime timestamp,dt_endtime timestamp);
//创建函数:
create function add_program_time(int4,timestamp,int4,int4,int4) returns bool as '
declare
prog_id alias for $1;
duration_min alias for $3;
period_min alias for $4;
repeat_times alias for $5;
i int;
starttime timestamp;
ins_starttime timestamp;
ins_endtime timestamp;
begin
starttime :=$2;
i := 0;
while i<repeat_times loop
ins_starttime := starttime;
ins_endt