СREATE OR REPLACE FUNCTION "public"."report" (text, text) RETURNS text AS
$body$
DECLARE
_date_in ALias For $1;
_time_in ALias For $2;
_DTime_Beg_Day Text;--timestamp;
_DTime_End timestamp;
_DTime_Beg_Mon timestamp;
_Plan_Day Real;
_Plan_Mon Real;
_mon integer;
_Year integer;
_Day integer;
_Record public.report_obor%rowtype;
_day_of_mon INTEGER;
_dt text;
_gar Text;
BEGIN
_Day:=to_number(substr($1,1,2),'00');
_mon:=to_number(substr($1,4,2),'00');
_year:=to_number(substr($1,7,4),'0000');
Select Case
When _mon IN(1,3,5,7,8,10,12) THEN 31
When _mon IN(4,6,9,11) THEN 30
When _mon IN(2) THEN 28 into _day_of_mon end;
--Начало дата по суткам
--_DTime_Beg_Day:=to_timestamp(_date_in||_gar||_time_in,'DDMMYYYY HH:MM');
_DTime_Beg_Day:=$1||_gar||$2;
--Конец даты по суткам и с начала месяца
if _Day+1>=_day_of_mon
Then _Day:=_day_of_mon;
Else _Day:=_Day+1;
End if;
_dt:=to_char(_day,'00')||chr(46)||TRIM(to_char(_mon,'00')||chr(46)||Trim(to_char(_year,'9999')));
_DTime_End:=to_timestamp(_dt||_gar||_time_in,'DDMMYYYY HH:MM');
--_DTime_End:=to_timestamp(||_gar||_time_in,'DDMMYYYY HH:MM')'14.09.2009 08:08';
_DTime_Beg_Mon:='01.09.2009 08:00';
DELETE From public.report_obor;
INSERT INTO public.report_obor(nom_obor,
name_excav,
name_gorizont,
piket,
ed_izm,
Plan_dob,
id_excav)
SELECT
public.excav.num_obor,
public.excav.name AS name_excv,
public.gorizont.name AS name_goriz,
public.excav_line.piket,
public.excav.ed_izm,
public."Plan"."Plan_dob",
public.excav.id_excav
FROM public.excav_line
INNER JOIN public.smena ON (public.excav_line.id_smena = public.smena.id_smena)
INNER JOIN public.excav ON (public.excav_line.id_excav = public.excav.id_excav)
INNER JOIN public.gorizont ON (public.excav_line.gorizont = public.gorizont.id_gorizont)
INNER JOIN public."Plan" ON (public.excav.id_excav = public."Plan".id_excav)
WHERE
public.smena.date_sm = to_date(_date_in,'DDMMYYYY') AND
public."Plan".mon = _mon AND
public."Plan".year = _year;
FOR _Record in SELECT * from report_obor Loop
UPDATE report_obor set fakt_day=(
SELECT SUM(b.tcoalsum) AS fakt FROM public.traffic b
WHERE b.dt_beg_upload BETWEEN _DTime_Beg_Day AND _DTime_end
and b.id_excav=_Record.id_excav
and b.tcoalsum>0
GROUP BY b.id_excav) Where id_excav=_Record.id_excav;
UPDATE report_obor set fakt_mon=(
SELECT SUM(b.tcoalsum) AS fakt FROM public.traffic b
WHERE b.dt_beg_upload BETWEEN _DTime_Beg_mon AND _DTime_end
and b.id_excav=_Record.id_excav
and b.tcoalsum>0
GROUP BY b.id_excav) Where id_excav=_Record.id_excav;
End Loop;
update public.report_obor set plan_mon=Plan_dob/_day_of_mon*_day,plan_day=Plan_dob/_day_of_mon;
update public.report_obor set delta_day=fakt_day-plan_day,delta_mon=fakt_mon-plan_mon;
RETURN _DTime_Beg_Day;
END;
$body$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100;
Нарисовал такую штуку _DTime_Beg_Day:=$1||_gar||$2; но вожвращает в return NULL помогите
Потому что
Потому что _gar=null.
Попробуй так _gar Text='';