如何使用字母和数字自动递增ID号 [英] How to Auto Increment ID Numbers with Letters and Numbers

查看:125
本文介绍了如何使用字母和数字自动递增ID号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用字母和数字自动递增ID号,例如"KP-0001",它将递增为"KP-0002"

How to Auto Increment ID Numbers with Letters and Numbers, example "KP-0001" it will increment to "KP-0002"

谢谢!

推荐答案

这是一篇有用的文章

但基本上,我鼓励您在此基础上创建自己的算法.您可以在BEFORE INSERT触发器中添加该算法.或者,您可以在前端进行操作.

But basically I encourage you to create your own algorithm on this. You can add that algorithm in BEFORE INSERT trigger. Or you can do that on the front-end.

算法伪代码示例

  • 获取lastID [ KP-0001 ]
  • 删除一些字符并将其放入变量[ KP-]
  • 将剩余部分转换为数字,因为它是字符串[ 0001 ]
  • 增加1 [ 1 +1 = 2 ]
  • 将其转换回字符串,并在右侧的[ 0002 ]
  • 上填充零.
  • 连接变量和新增加的数字[ KP-0002 ]
  • 保存.
  • get the lastID [KP-0001]
  • remove some characters and put it in a variable [KP-]
  • convert the remaining into number since it's a string [0001]
  • increment by 1 [1 + 1 = 2]
  • convert it back to string and pad zero on the right [0002]
  • concatenate the variable and the newly incremented number [KP-0002]
  • save it.

这篇关于如何使用字母和数字自动递增ID号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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