postgreSQL 存储过程及存储过程调用

本文介绍了一个在PostgreSQL中创建和使用的存储过程`mt_f_avl_oee_period`,该过程根据传入参数`i_type`判断执行不同逻辑。主要功能包括根据当前时间获取过去2小时或3小时的起止时间,并调用其他存储过程计算效率指标。存储过程采用PL/pgSQL语言编写,处理异常并确保权限设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CREATE OR REPLACE FUNCTION mt_f_avl_oee_period(i_station character varying,i_type int)
  RETURNS integer AS
$BODY$
DECLARE


 v_start_hour  character varying;
 v_end_hour character varying;

 
 v_start_time  character varying;
 v_end_time character varying;

 v_start_datetime  timestamp;
 v_end_datetime timestamp;

 v_type int := 0;

 v_rtn int;

 
/*
 v_test9_count int;
 v_test9_success int;

 v_runningtime double precision;
 v_availablerate double precision;
 */

BEGIN

-- hour = even, minute > 30
-- exists
-- 

if i_type = 1 then

SELECT EXTRACT(HOUR FROM CURRENT_TIME - interval '2 hours' ) into v_start_hour;	 	--two hours ago
SELECT EXTRACT(HOUR FROM CURRENT_TIME ) into v_end_hour;				--get 'hour' of current time

select v_start_hour || ':30' into v_start_time;

select v_end_hour || ':30' into v_end_time;

select mt_f_avl_oee_period_e(i_station, to_char( CURRENT_Date, 'YYYY-MM-DD'),  v_start_time
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值