您好,登錄后才能下訂單哦!
這篇文章主要講解了“PG存儲過程是什么”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“PG存儲過程是什么”吧!
-- 刪除函數 drop function if exists upgrade_task_device(integer); create or replace function upgrade_task_device(exec_way integer) returns integer as $$ declare cron_prefix varchar default '0 */'; cron_suffix varchar default ' * * * ?'; cron_period varchar; tmp_cron_period integer; cron_exp varchar default ''; cur_row record; ret integer default 0; task_cursor cursor (exec_way integer) for select t.* from task t where t.execution_way = exec_way; begin -- task表如果 time_period > 59,設值為59 update task set time_period = 59 where time_period is not null and time_period > 59; open task_cursor(exec_way); loop fetch task_cursor into cur_row; exit when not FOUND; -- 定時執行|立即執行 if cur_row.execution_way = 1 or cur_row.execution_way = 2 then update task_device set task_type = cur_row.task_type, task_name = cur_row.task_name, retry = cur_row.retry, start_time=cur_row.start_time, end_time=cur_row.end_time, -- 執行方式全部更改為‘周期執行’ execution_way = 3, create_user_id=cur_row.create_user_id where task_id = cur_row.id and time_rule is null; elsif cur_row.execution_way = 3 then -- 周期執行 tmp_cron_period = cur_row.time_period; if tmp_cron_period > 59 then tmp_cron_period = 59; end if; -- 轉換為字符串進行拼接 cron_period = TRIM(to_char(tmp_cron_period, '99')); -- cron 拼接 cron_exp = cron_prefix || cron_period || cron_suffix; update task_device set task_type = cur_row.task_type, task_name = cur_row.task_name, retry = cur_row.retry, start_time=cur_row.start_time, end_time=cur_row.end_time, time_rule=cron_exp, -- 執行方式全部更改為‘周期執行’ execution_way = 3, create_user_id=cur_row.create_user_id where task_id = cur_row.id and time_rule is null; end if; end loop; close task_cursor; ret = 1; return ret; end; $$ language plpgsql; -- 分別處理定時執行、周期執行、立即執行 select upgrade_task_device(1); select upgrade_task_device(2); select upgrade_task_device(3); -- 刪除函數 drop function if exists upgrade_task_device(integer);
感謝各位的閱讀,以上就是“PG存儲過程是什么”的內容了,經過本文的學習后,相信大家對PG存儲過程是什么這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。