如何在数据库中进行自动增量并返回给用户 [英] How to make auto increment in database and return to user

查看:75
本文介绍了如何在数据库中进行自动增量并返回给用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为schcode for state的数据库。当用户想要输入新代码时,它会给出自动增加的代码。我怎样才能实现它



我尝试了什么:



创建功能fngetlastcodeofvillage(IN区名文本,

in talukname text,

IN villagenam text)RETURNS setof text AS

$ BODY $

BEGIN

SELECT schcd FROM villagerural_school_form where districtna = $ 1 and talukname = 2美元和villagenam = $ 3订单由id desc限制1

如果schcd是空那么

RETURN census2011 || 01来自villanaural,其中districtna = $ 1和talukname = $ 2和villagenam = $ 3

其他

从villagerural_school_form返回schcd + 01,其中districtna = $ 1,talukname = $ 2和villagenam = $ 3

END IF;



END;



$ BODY $

LANGUAGE sql VOLATILE

COST 100

RO WS 1000;

ALTER FUNCTION fngetlastcodeofvillage(文本,文字,文字)

所有者的邮件;



我想要做一些像上面这样的事情,你能告诉我们上面的函数是什么错误并使它成为wotkout

i have database with field called schcode for state.when user wants to enter new code it give auto incremented code.How can i achieve it

What I have tried:

CREATE FUNCTION fngetlastcodeofvillage( IN districtname text,
IN talukname text,
IN villagenam text) RETURNS setof text AS
$BODY$
BEGIN
SELECT schcd FROM villagerural_school_form where districtna=$1 and talukname=$2 and villagenam=$3 order by id desc limit 1
IF schcd IS NULL THEN
RETURN census2011||01 from villagerural where districtna=$1 and talukname=$2 and villagenam=$3
else
return schcd+01 from villagerural_school_form where districtna=$1 and talukname=$2 and villagenam=$3
END IF;

END;

$BODY$
LANGUAGE sql VOLATILE
COST 100
ROWS 1000;
ALTER FUNCTION fngetlastcodeofvillage(text, text, text)
OWNER TO postgres;

I want to do some thing like above can you tell whats wrong in the above function and make it wotkout

推荐答案

BODY




BEGIN

SELECT schcd FROM villagerural_school_form where districtna =

BEGIN
SELECT schcd FROM villagerural_school_form where districtna=


1 and talukname =
1 and talukname=


这篇关于如何在数据库中进行自动增量并返回给用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆