如果這裏的條件不起作用,我的嵌套。我不知道爲什麼。我是Postgresql中的新成員。你能幫我解決這個問題嗎?我不知道該怎麼辦。 :。'(Postgresql中的嵌套IF完全不起作用?
CREATE OR REPLACE FUNCTION pl_uploadhousehoold(mchholdnumber character varying, mcbrgycode character varying, mcstio character varying, mcstreet character varying, mnhousenumber character varying, mclat character varying, mclong character varying, mcrespondentname character varying, mddateinterview date, mdstattime character varying, mdendtime character varying, mcpurok character varying, mnuserid integer, mczone character varying, mccategory character varying, mfile_path_household character varying, mfile_path character varying, mfile_respondent character varying, mdyear date, mnuser integer, mdaccomplished character varying, mdregistered character varying, mdvalidated character varying, mcsubcategory character varying, mcfacilityname character varying, mcposition character varying)
RETURNS SETOF tbl_household AS
$BODY$
DECLARE
t_10 time without time zone;
t_11 time without time zone;
t_21 timestamp without time zone;
t_22 timestamp without time zone;
t_23 timestamp without time zone;
hh_id character varying;
BEGIN
IF hh_id is NULL THEN
IF mdstattime !='' THEN
t_10:=(select CAST (mdstattime as time without time zone) as dstattime);
INSERT INTO tbl_household(chholdnumber,cbrgycode,csitio,cstreet,nhousenumber,clat,clong,crespondentname,ddateinterview,dstattime,cpurok,nuserid,czone,ccategory,file_path_household, file_path, file_respondent,dyear,nuser, csubcategory, cfacilityname, cposition)
values($1,$2,$3,$4,$5,$6,$7,$8,$9,t_10,$12,$13,$14,$15,$16,$17,$18,$19,$20,$24,$25,$26);
END IF;
IF mdendtime !='' THEN
t_11:=(select CAST (mdendtime as time without time zone) as dendtime);
INSERT INTO tbl_household(chholdnumber,cbrgycode,csitio,cstreet,nhousenumber,clat,clong,crespondentname,ddateinterview,dendtime,cpurok,nuserid,czone,ccategory,file_path_household, file_path, file_respondent,dyear,nuser, csubcategory, cfacilityname, cposition)
values($1,$2,$3,$4,$5,$6,$7,$8,$9,t_11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$24,$25,$26);
END IF;
IF mdaccomplished !='' THEN
t_21:=(select CAST (mdaccomplished as timestamp without time zone) as daccomplished);
INSERT INTO tbl_household(chholdnumber,cbrgycode,csitio,cstreet,nhousenumber,clat,clong,crespondentname,ddateinterview,cpurok,nuserid,czone,ccategory,file_path_household, file_path, file_respondent,dyear,nuser,daccomplished, csubcategory, cfacilityname, cposition)
values($1,$2,$3,$4,$5,$6,$7,$8,$9,$12,$13,$14,$15,$16,$17,$18,$19,$20,t_21,$24,$25,$26);
END IF;
IF mdregistered !='' THEN
t_22:=(select CAST (mdregistered as timestamp without time zone) as dregistered);
INSERT INTO tbl_household(chholdnumber,cbrgycode,csitio,cstreet,nhousenumber,clat,clong,crespondentname,ddateinterview,cpurok,nuserid,czone,ccategory,file_path_household, file_path, file_respondent,dyear,nuser,dregistered, csubcategory, cfacilityname, cposition)
values($1,$2,$3,$4,$5,$6,$7,$8,$9,$12,$13,$14,$15,$16,$17,$18,$19,$20,t_22,$24,$25,$26);
END IF;
IF mdvalidated !='' THEN
t_23:=(select CAST (mdvalidated as timestamp without time zone) as dvalidated);
INSERT INTO tbl_household(chholdnumber,cbrgycode,csitio,cstreet,nhousenumber,clat,clong,crespondentname,ddateinterview,cpurok,nuserid,czone,ccategory,file_path_household, file_path, file_respondent,dyear,nuser,dvalidated, csubcategory, cfacilityname, cposition)
values($1,$2,$3,$4,$5,$6,$7,$8,$9,$12,$13,$14,$15,$16,$17,$18,$19,$20,t_23,$24,$25,$26);
END IF;
IF mdaccomplished ='' and mdstattime='' and mdendtime='' and mdregistered ='' and mdvalidated ='' THEN
INSERT INTO tbl_household(chholdnumber,cbrgycode,csitio,cstreet,nhousenumber,clat,clong,crespondentname,ddateinterview,cpurok,nuserid,czone,ccategory,file_path_household, file_path, file_respondent,dyear,nuser, csubcategory, cfacilityname, cposition)
values($1,$2,$3,$4,$5,$6,$7,$8,$9,$12,$13,$14,$15,$16,$17,$18,$19,$20,$24,$25,$26);
END IF;
IF mdaccomplished !='' and mdstattime!='' and mdendtime!='' and mdregistered !='' and mdvalidated !='' THEN
t_22:=(select CAST (mdregistered as timestamp without time zone) as dregistered);
t_21:=(select CAST (mdaccomplished as timestamp without time zone) as daccomplished);
t_10:=(select CAST (mdstattime as time without time zone) as dstattime);
t_11:=(select CAST (mdendtime as time without time zone) as dendtime);
t_23:=(select CAST (mdvalidated as timestamp without time zone) as dvalidated);
INSERT INTO tbl_household(chholdnumber,cbrgycode,csitio,cstreet,nhousenumber,clat,clong,crespondentname,ddateinterview,dstattime,dendtime,cpurok,nuserid,czone,ccategory,file_path_household, file_path, file_respondent,dyear,nuser,daccomplished,dregistered,dvalidated, csubcategory, cfacilityname, cposition)
values($1,$2,$3,$4,$5,$6,$7,$8,$9,t_10,t_11,$12,$13,$14,$15,$16,$17,$18,$19,$20,t_21,t_22,t_23,$24,$25,$26);
END IF;
ELSE
END IF;
我測試過我mdendtime空值,但它的條件不工作
什麼是錯誤? –
「*不起作用*」不是有效的Postgres錯誤消息。你測試的任何變量('mdendtime','mdstattime')是否都是'null'?爲什麼將名爲「time」的變量與字符串文字進行比較?這些變量的數據類型是什麼? –
我已經添加了功能部分。它不顯示錯誤,但條件部分根本不起作用:) –