首页 > 数据库 >SQL 自定义函数 生成网卡地址,MES开发中经常会用到的

SQL 自定义函数 生成网卡地址,MES开发中经常会用到的

时间:2024-09-07 13:02:45浏览次数:1  
标签:SUBSTRING iNewSeqNo Set 自定义 ----------------------------------------------------

SQL 自定义函数 生成网卡地址,MES开发中经常会用到的

ALTER Function [dbo].[Fun_ReleaseMACadd]
(
	@CurrentSeqNo varchar(6)
)
Returns varchar(18)
-------------------------------------------------------------------------------------------------  
As
-------------------------------------------------------------------------------------------------  
-----Created by Jock.Luo, 2024/09/05.
-----Purpose: 得到新的流水号,目前是按照34进制来计算的.
-----输入的参数为当前流水号,返回下一个流水号.
-------------------------------------------------------------------------------------------------  
Begin
	Declare @iNewSeqNo varchar(18)
	--Declare @macAddress varchar(18)
	Declare @OEMmacAddress varchar(18)
	Declare @FormatString varchar(36)
	Set @FormatString='0123456789ABCDEF'
	set @OEMmacAddress='A1B2C3'
	-------------------------------------------------------------------------------------------------  
	Declare @CurrentFirstCode char(1)
	Declare @CurrentSecondCode char(1)
	Declare @CurrentThirdCode char(1)
	Declare @CurrentFourthCode char(1)
	Declare @CurrentLastModCode char(1)
	Declare @CurrentLastCode char(1)
	-------------------------------------------------------------------------------------------------  
	Declare @NextFirstCode char(1)
	Declare @NextSecondCode char(1)
	Declare @NextThirdCode char(1)
	Declare @NextFourthCode char(1)
	Declare @NextLastModCode char(1)
	Declare @NextLastCode char(1)
	-------------------------------------------------------------------------------------------------  
	Set @CurrentFirstCode=Substring(@CurrentSeqNo,1,1)
	Set @CurrentSecondCode=Substring(@CurrentSeqNo,2,1)
	Set @CurrentThirdCode=Substring(@CurrentSeqNo,3,1)
	Set @CurrentFourthCode=Substring(@CurrentSeqNo,4,1)
	Set @CurrentLastModCode=Substring(@CurrentSeqNo,5,1)
	Set @CurrentLastCode=Substring(@CurrentSeqNo,6,1)
	-------------------------------------------------------------------------------------------------
	if len(@CurrentSeqNo)=6
	begin
		If @CurrentSeqNo='FFFFFF'  
		Begin
			Set @iNewSeqNo='000000'
			set @iNewSeqNo=@OEMmacAddress+@iNewSeqNo
			set @iNewSeqNo=SUBSTRING(@iNewSeqNo, 1, 2) + '-' + SUBSTRING(@iNewSeqNo, 3, 2)+ '-' + SUBSTRING(@iNewSeqNo, 5, 2) + '-' + SUBSTRING(@iNewSeqNo, 7, 2) + '-' + SUBSTRING(@iNewSeqNo, 9, 2) + '-' + SUBSTRING(@iNewSeqNo, 11, 2)
			Return(@iNewSeqNo)
		End
		-------------------------------------------------------------------------------------------------  
		If @CurrentSecondCode+@CurrentThirdCode+@CurrentFourthCode+@CurrentLastModCode+@CurrentLastCode='FFFFF'
		Begin
			Set @NextFirstCode=Substring(@FormatString,CharIndex(@CurrentFirstCode,@FormatString)+1,1)
			Set @iNewSeqNo=@NextFirstCode+'00000'
			set @iNewSeqNo=@OEMmacAddress+@iNewSeqNo
			set @iNewSeqNo=SUBSTRING(@iNewSeqNo, 1, 2) + '-' + SUBSTRING(@iNewSeqNo, 3, 2)+ '-' + SUBSTRING(@iNewSeqNo, 5, 2) + '-' + SUBSTRING(@iNewSeqNo, 7, 2) + '-' + SUBSTRING(@iNewSeqNo, 9, 2) + '-' + SUBSTRING(@iNewSeqNo, 11, 2)
			Return(@iNewSeqNo)
		End
	
		-------------------------------------------------------------------------------------------------  
		If @CurrentThirdCode+@CurrentFourthCode+@CurrentLastModCode+@CurrentLastCode='FFFF'
		Begin
			Set @NextSecondCode=Substring(@FormatString,CharIndex(@CurrentSecondCode,@FormatString)+1,1)
			Set @iNewSeqNo=@CurrentFirstCode+@NextSecondCode+'0000'
			set @iNewSeqNo=@OEMmacAddress+@iNewSeqNo
			set @iNewSeqNo=SUBSTRING(@iNewSeqNo, 1, 2) + '-' + SUBSTRING(@iNewSeqNo, 3, 2)+ '-' + SUBSTRING(@iNewSeqNo, 5, 2) + '-' + SUBSTRING(@iNewSeqNo, 7, 2) + '-' + SUBSTRING(@iNewSeqNo, 9, 2) + '-' + SUBSTRING(@iNewSeqNo, 11, 2)
			Return(@iNewSeqNo)
		End

		-------------------------------------------------------------------------------------------------  
		If @CurrentFourthCode+@CurrentLastModCode+@CurrentLastCode='FFF'
		Begin
			Set @NextThirdCode=Substring(@FormatString,CharIndex(@CurrentThirdCode,@FormatString)+1,1)
			Set @iNewSeqNo=@CurrentFirstCode+@CurrentSecondCode+@NextThirdCode+'000'
			set @iNewSeqNo=@OEMmacAddress+@iNewSeqNo
			set @iNewSeqNo=SUBSTRING(@iNewSeqNo, 1, 2) + '-' + SUBSTRING(@iNewSeqNo, 3, 2)+ '-' + SUBSTRING(@iNewSeqNo, 5, 2) + '-' + SUBSTRING(@iNewSeqNo, 7, 2) + '-' + SUBSTRING(@iNewSeqNo, 9, 2) + '-' + SUBSTRING(@iNewSeqNo, 11, 2)
			Return(@iNewSeqNo)
		End

		-------------------------------------------------------------------------------------------------  
		If @CurrentLastModCode+@CurrentLastCode='FF'
		Begin
			Set @NextFourthCode=Substring(@FormatString,CharIndex(@CurrentFourthCode,@FormatString)+1,1)
			Set @iNewSeqNo=@CurrentFirstCode+@CurrentSecondCode+@CurrentThirdCode+@NextFourthCode+'00'
			set @iNewSeqNo=@OEMmacAddress+@iNewSeqNo
			set @iNewSeqNo=SUBSTRING(@iNewSeqNo, 1, 2) + '-' + SUBSTRING(@iNewSeqNo, 3, 2)+ '-' + SUBSTRING(@iNewSeqNo, 5, 2) + '-' + SUBSTRING(@iNewSeqNo, 7, 2) + '-' + SUBSTRING(@iNewSeqNo, 9, 2) + '-' + SUBSTRING(@iNewSeqNo, 11, 2)
			Return(@iNewSeqNo)
		End

		-------------------------------------------------------------------------------------------------  
		If +@CurrentLastCode='F'
		Begin
			Set @NextLastModCode=Substring(@FormatString,CharIndex(@CurrentLastModCode,@FormatString)+1,1)
			Set @iNewSeqNo=@CurrentFirstCode+@CurrentSecondCode+@CurrentThirdCode+@CurrentFourthCode+@NextLastModCode+'0'
			set @iNewSeqNo=@OEMmacAddress+@iNewSeqNo
			set @iNewSeqNo=SUBSTRING(@iNewSeqNo, 1, 2) + '-' + SUBSTRING(@iNewSeqNo, 3, 2)+ '-' + SUBSTRING(@iNewSeqNo, 5, 2) + '-' + SUBSTRING(@iNewSeqNo, 7, 2) + '-' + SUBSTRING(@iNewSeqNo, 9, 2) + '-' + SUBSTRING(@iNewSeqNo, 11, 2)
			Return(@iNewSeqNo)
		End
		-------------------------------------------------------------------------------------------------  
		-----除上述情况之外的其它情况.
		Set @NextFirstCode=@CurrentFirstCode
		Set @NextSecondCode=@CurrentSecondCode
		Set @NextThirdCode=@CurrentThirdCode
		Set @NextFourthCode=@CurrentFourthCode
		set @NextLastModCode=@CurrentLastModCode
		Set @NextLastCode=Substring(@FormatString,CharIndex(@CurrentLastCode,@FormatString)+1,1)
		Set @iNewSeqNo=@CurrentFirstCode+@CurrentSecondCode+@CurrentThirdCode+@CurrentFourthCode+@CurrentLastModCode+@NextLastCode
		set @iNewSeqNo=@OEMmacAddress+@iNewSeqNo
		set @iNewSeqNo=SUBSTRING(@iNewSeqNo, 1, 2) + '-' + SUBSTRING(@iNewSeqNo, 3, 2)+ '-' + SUBSTRING(@iNewSeqNo, 5, 2) + '-' + SUBSTRING(@iNewSeqNo, 7, 2) + '-' + SUBSTRING(@iNewSeqNo, 9, 2) + '-' + SUBSTRING(@iNewSeqNo, 11, 2)
		Return(@iNewSeqNo)
		-------------------------------------------------------------------------------------------------
	end
	Return(@iNewSeqNo)
		-------------------------------------------------------------------------------------------------
End

  

标签:SUBSTRING,iNewSeqNo,Set,自定义,----------------------------------------------------
From: https://www.cnblogs.com/dudian/p/18401575

相关文章

  • QMessageBox使用方法详解,及用例演示
    QMessageBox是Qt框架中一个非常有用的类,用于显示模态对话框,以告知用户信息、警告、错误等,或者询问用户是/否的问题。这个类提供了丰富的静态函数来创建不同类型的对话框,而无需实例化QMessageBox对象本身。下面,我将详细解释QMessageBox的基本使用方法,并通过一些用例来......
  • 如何创建和管理自定义systemd服务
    创建和管理自定义systemd服务是Linux系统管理中的一项重要技能。systemd是一种初始化系统和服务管理器,广泛应用于现代Linux发行版。以下是创建和管理自定义systemd服务的详细步骤。1.创建自定义服务单元文件自定义服务的配置文件称为“单元文件”,通常位于/etc/system......
  • 记录 PyQt6 / PySide 6 自定义边框窗口的 Bug 及可能可行的解决方案:窗口抖动和添加 DW
    前言:本篇文章将要讨论我在前不久发表的关于PyQt6/PySide6自定义边框窗口代码及内容中的问题:(终)PyQt6/PySide6+Pywin32自定义标题栏窗口+完全还原Windows原生窗口边框特效_pyside6win32无边框窗口-CSDN博客https://blog.csdn.net/2402_84665876/article/detail......
  • JAVA获取本地的所有网卡IP地址列表
      privatestaticfinalStringNETMASK="(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";privatestaticfinalPatternIP_PATTERN=Pattern.compile("^(?:"+NETMASK+"\\.){3}"+NETMASK+"$");publicst......
  • 自定义排序规则
    Comparator接口的使用:TreeSet集合存储自定义类型的对象时,必须指定排序规则,支持如下两种方式来指定比较规则。方式一让自定义的类实现Comparable接口,重写里面的compareTo方法来指定比较规则。​//属性类publicclassStudentimplementsComparable<Student>{  privat......
  • VUE框架Vue3使用自定义事件的方式传递数据------VUE框架
    <template><!--给User绑定事件--><!--带参数的方法不要有括号,否则识别不到,我不懂原理...--><User@event1="showInfo"></User></template><script>importUserfrom"./components/User.vue"exportdefault{......
  • 【Linux】CentOS 7 网卡突然启动不了的解决办法
    最近在了解Hadoop,但是在虚拟机关机之后,重新启动,网卡就不见了。 具体情况是这样的:1.用ifconfig查看,发现网卡不见了。2.用ifconfig-a查看,发现ens33网卡是在的,只是状态是down的。3.临时的解决方法:使用ifconfig命令,直接启动ens33网卡[root@centos7~]#ifconfigens33up然后,临时配置......
  • 【YashanDB知识库】修改字段长度后,jdbc驱动接口报YAS-04007 Message:result set metada
    问题现象yashandb修改表的字段长度后,客户的业务接口报YAS-04007异常,截图如下:问题的风险及影响客户的业务在访问yashandb时异常出错,影响使用问题影响的版本所有的yashandb版本问题发生原因使用jdbc接口获取PreparedStatement以后,修改表的字段长度,再用前面获取的PreparedStatement继......
  • C语言-第六章-加餐:其他自定义类型
    传送门:C语言-第六章:结构体目录第一节:位段    1-1.位段是什么    1-2.位段的大小第二节:联合体    2-1.联合体是什么    2-2联合体的大小第三节:枚举类型    3-1.枚举是什么第四节:结构体中的柔性数组    4-1.柔性数组......
  • 功能发布-自定义SQL查询
    引言本期主要为大家介绍ClkLog九月上线的新功能-自定义SQL查询。什么是自定义SQL查询?自定义SQL查询是指根据具体的应用场景和需求,由开发者或数据库管理员自行编写的SQL(StructuredQueryLanguage,结构化查询语言)语句。自定义SQL查询有什么作用?以精确的方式从数据库中检索数据。在Cl......