如何创建一个返回最高ID的函数? [英] How to create a function that return the highest id?

查看:78
本文介绍了如何创建一个返回最高ID的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用此功能,因此有很多错误.我已经研究了当声明变量和函数时使用syntaxis. 但是我仍然做不到.

I cannot make work this function, i got a lot mistakes from it. i have researched about the syntaxis when it comes to declare variables and functions. But i still cannot do it.

这是我到目前为止尝试过的代码,但是它们都不起作用.

this is the code i have tried so far, but none of them work.

Create function Consecutive()
returns int
return (select @id := max(id) from pais);

Create function Consecutive()
returns int
BEGIN
DECLARE id int;
set id = (select max(id) from pais;
return id;
END

推荐答案

DELIMITER $$
CREATE FUNCTION consecutive()
RETURNS integer
 DETERMINISTIC
BEGIN
  RETURN (SELECT max(id)
                 FROM pais);
END;

这是我的问题的解决方案.

this is the solution to my question.

这篇关于如何创建一个返回最高ID的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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