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

前端之家收集整理的这篇文章主要介绍了postgreSQL 存储过程及存储过程调用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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,v_end_time) into v_rtn;

else

SELECT EXTRACT(HOUR FROM CURRENT_TIME - interval '3 hours' ) into v_start_hour;
SELECT EXTRACT(HOUR FROM CURRENT_TIME ) into v_end_hour;

select v_start_hour || ':30' into v_start_time;

select v_end_hour || ':00' into v_end_time;

select mt_f_avl_oee_period_midnight(i_station,v_end_time) into v_rtn;

end if;


RETURN 1;


EXCEPTION

WHEN others THEN
    RAISE;

RETURN 0;

END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION mt_f_avl_oee_period(i_station character varying,i_type int)
  OWNER TO postgres;
原文链接:https://www.f2er.com/postgresql/195946.html

猜你在找的Postgre SQL相关文章