我是PostgreSQL的新手并试图执行一些查询。 我在.sql文件中编写了一个函数,并从一个.bat文件中调用了这个sql文件,该文件可以从命令行执行。
Installer.bat> abc.sql> (sql文件已编写函数)
功能是,
CREATE FUNCTION getLabelTranslation(p_webForm varchar(50), p_labelName varchar(50), p_languageID int, p_fallbackLanguageID int)
RETURNS VARCHAR(1000) AS $$
DECLARE
v_retval VARCHAR(1000) := p_labelName;
BEGIN
IF EXISTS (SELECT ID FROM LabelTextList WHERE WebForm=p_webForm AND LabelName=p_labelName AND LanguageListID=p_languageID) THEN
v_retval:= (SELECT Text FROM LabelTextList WHERE WebForm=p_webForm AND LabelName=p_labelName AND LanguageListID=p_languageID);
RETURN v_retval;
ELSE IF EXISTS (SELECT ID FROM LabelTextList WHERE WebForm='Any' AND LabelName=p_labelName AND LanguageListID=p_languageID) THEN
v_retval:= (SELECT Text FROM LabelTextList WHERE WebForm='Any' AND LabelName=p_labelName AND LanguageListID=p_languageID );
RETURN v_retval;
ELSE IF p_languageID<>p_fallbackLanguageID AND EXISTS (SELECT ID FROM LabelTextList WHERE WebForm=p_webForm AND LabelName=p_labelName AND LanguageListID=p_fallbackLanguageID) THEN
v_retval:= (SELECT Text FROM LabelTextList WHERE WebForm=p_webForm AND LabelName=p_labelName AND LanguageListID=p_fallbackLanguageID);
RETURN v_retval;
ELSE IF p_languageID<>p_fallbackLanguageID AND EXISTS (SELECT ID FROM LabelTextList WHERE WebForm='Any' AND LabelName=p_labelName AND LanguageListID=p_fallbackLanguageID) THEN
v_retval:= (SELECT Text FROM LabelTextList WHERE WebForm='Any' AND LabelName=p_labelName AND LanguageListID=p_fallbackLanguageID );
RETURN v_retval;
END IF;
END;
$$ LANGUAGE plpgsql;
错误
ERROR: syntax error at or near ";" LINE 20: END; (i.e. last END; statement)
答案 0 :(得分:1)
ELSIF
/ ELSEIF
而不是ELSE IF
。如果您将单词分开,则它是一个新的IF
语句,并且每个IF
都必须具有相应的END IF
。