2024-04-17 08:57:56
ACCESS数据库无法用正则表达式来解决这种问题。建议编写一个全局自定义函数,然后在SQL更新查询中调用这个函数来解决这个需求。
下面是具体方案:
新建一个Access模块,取名“模块1”,在该模块编写自定义函数
Public Function ReplaceNonNum_A2Z(strg As String) As String
Dim aChar As String, Str As String, i As Long, yes As Boolean
For i = 1 To Len(strg)
yes = False
aChar = Mid(strg, i, 1)
Select Case aChar
Case "a" To "z"
yes = True
Case "A" To "Z"
yes = True
Case "0" To "9"
yes = True
End Select
If yes = False Then
Str = Str & "_"
Else
Str = Str & aChar
End If
Next i
ReplaceNonNum_A2Z = Str
End Function
保存上述模块和自定义函数后即可,在SQL语句中调用该函数了。非常方便
调用该函数举例
update TestTable set TestColumn=ReplaceNonNum_A2Z(TestColumn);