Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
函数中if语句的Postgresql语法错误_Postgresql_Plpgsql - Fatal编程技术网

函数中if语句的Postgresql语法错误

函数中if语句的Postgresql语法错误,postgresql,plpgsql,Postgresql,Plpgsql,我试图在postgresql中编写函数,但得到了if语句的语法错误: CREATE OR REPLACE FUNCTION getallcampuses(IN a character varying, IN b character varying) RETURNS TABLE(campusid charactervarying, campusname character varying) AS $BODY$ BEGIN if $1 = 'PREK' then SELECT * fr

我试图在postgresql中编写函数,但得到了if语句的语法错误:

CREATE OR REPLACE FUNCTION getallcampuses(IN a character varying, IN b character varying)
  RETURNS TABLE(campusid charactervarying, campusname character varying) AS
$BODY$
BEGIN
if $1 = 'PREK' then
     SELECT * from "SIS_campus";
ELSE
    BEGIN
       IF $2 = 'DAll' then
           SELECT distinct(district_id) || 'ALL' AS CampusID, ' District' AS CampusName

           UNION

           SELECT campus_id, name
           FROM   "SIS_campus"
           WHERE  district_name IS NOT NULL
           order by name;
       Elsif $2 = 'All' then

           SELECT campus_id, name
           FROM   "SIS_campus"
           WHERE  district_name IS NOT NULL
           and isnumeric(name) = 0
           order by name;
        end if;
    END
end if;
END
$BODY$
LANGUAGE sql;
以下是错误:

ERROR:  syntax error at or near "if"
LINE 5: if $1 = 'PREK' then
        ^

函数体是PL/PgSQL,但是您声明了它
语言sql

如果您正在编写PL/PgSQL,请使用
语言plpgsql


()

您在
Elsif$2='All'有一个输入错误,那么
感谢您提供完整的函数体和准确的错误消息文本。这是非常罕见的,值得赞赏。(不过,今后也请在文本中添加您的PostgreSQL版本)。