本文介绍了Postgres Sql Else如果语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我是 PostgreSQL 的新手,我正在尝试制作一个函数,但它显示语法错误 CREATE OR REPLACE FUNCTION master.test(tehsil text ,district text ,state text ,flag text ) RETURNS SETOF refcursor AS $ BODY $ DECLARE recordSet refcursor; BEGIN OPEN 记录集 FOR IF flag = ' A' 那么 SELECT 计数(*) FROM population WHERE incomein( 1 , 2 ) AND statecode = ' 07 ; [ELSIF flag = ' B' 那么 SELECT 计数(*) FROM population WHERE incomein( 1 , 2 ) AND statecode = ' 07' AND districtcode = ' '; [ELSIF flag = ' C' 那么 SELECT 计数(*) FROM population WHERE incomein( 1 , 2 ) AND statecode = ' 07' AND districtcode = ' ' AND tehsilcode = ' '; ] ] [ ELSE SELECT 计数(*) FROM population WHERE incomein( 1 , 2 ); ] END IF ; RETURN NEXT recordSet; 返回; END ; $ BODY $ LANGUAGE plpgsql 解决方案 BODY DECLARE recordSet refcursor; BEGIN OPEN 记录集 FOR IF flag = ' A' 那么 SELECT 计数(*) FROM population WHERE incomein( 1 , 2 ) AND statecode = ' 07 ; [ELSIF flag = ' B' 那么 SELECT 计数(*) FROM population WHERE incomein( 1 , 2 ) AND statecode = ' 07' AND districtcode = ' '; [ELSIF flag = ' C' 那么 SELECT 计数(*) FROM population WHERE incomein( 1 , 2 ) AND statecode = ' 07' AND districtcode = ' ' AND tehsilcode = ' '; ] ] [ ELSE SELECT 计数(*) FROM population WHERE incomein( 1 , 2 ); ] END IF ; RETURN NEXT recordSet; 返回; END ; BODY I am very new to PostgreSQL and i am trying to make a function in this but it''s showing syntax errorCREATE OR REPLACE FUNCTION master.test(tehsil text, district text, state text,flag text) RETURNS SETOF refcursor AS $BODY$DECLARE recordSet refcursor; BEGIN OPEN recordset FOR IF flag = 'A' THEN SELECT Count(*) FROM population WHERE incomein(1,2) AND statecode='07';[ ELSIF flag = 'B' THEN SELECT Count(*) FROM population WHERE incomein(1,2) AND statecode='07' AND districtcode = ''; [ ELSIF flag = 'C' THEN SELECT Count(*) FROM population WHERE incomein(1,2) AND statecode='07' AND districtcode = '' AND tehsilcode = '';]] [ ELSE SELECT Count(*) FROM population WHERE incomein(1,2); ] END IF; RETURN NEXT recordSet; RETURN; END; $BODY$ LANGUAGE plpgsql 解决方案 BODYDECLARE recordSet refcursor; BEGIN OPEN recordset FOR IF flag = 'A' THEN SELECT Count(*) FROM population WHERE incomein(1,2) AND statecode='07';[ ELSIF flag = 'B' THEN SELECT Count(*) FROM population WHERE incomein(1,2) AND statecode='07' AND districtcode = ''; [ ELSIF flag = 'C' THEN SELECT Count(*) FROM population WHERE incomein(1,2) AND statecode='07' AND districtcode = '' AND tehsilcode = '';]] [ ELSE SELECT Count(*) FROM population WHERE incomein(1,2); ] END IF; RETURN NEXT recordSet; RETURN; END;BODY 这篇关于Postgres Sql Else如果语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-24 02:37