用于标准化/清理名字/中间名/姓氏字段的 SQL
我正在用 SQL 编写一个函数,我们可以用它来验证给定表中的名字/中间名/姓氏。
目前,我正在处理字符的 ascii 代码列表,我将认为这些字符无效并从输入中删除。
我的计划是创建一个表,其中包含我认为无效的那些字符的字符代码,并编写一个游标来替换其正在处理的当前输入记录中的每个无效字符。
我应该直接浏览整个 ascii 表,还是有人见过类似的工作,我可以从中构建?
I'm writing a function in SQL that we can use to validate First/Middle/Last names we have in a given table.
At the moment I'm working on a list of ascii codes for characters that I'm going to consider invalid and strip out of the input.
My plan is to create a table which contains the character codes of those characters I consider to be invalid, and to write a cursor that will replace each invalid character from the current input record its working on.
Should I just work my way through the entire ascii table or has anyone ever seen a similar effort like this that I can look at to build from?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 SQL 中的代码扫描数据中的无效字符是一种非常慢的方法,而且不太可能让您满意。
我认为大多数人会在数据库之外进行验证。
如果必须在数据库内执行此操作,请编写一个使用数据库固有语言(Oracle PL/SQL、MSSQL tsql)的触发器来检查字符串,只需将有效字符列表编码到脚本中即可。
当名字带有口音或其他有趣字符的人出现时会发生什么?
Using code in SQL to scan data for invalid characters is a very slow approach and unlikely to make you happy.
Most people would, I think, do this validating outside the db.
If you must do it inside the db, look to write a trigger that uses the database's inherent language (Oracle PL/SQL, MSSQL tsql) to check the string, just coding the valid character list into the script.
And what happens when someone with a name with accents or other interesting characters shows up?
这几乎就是我们所做的。
当然,您希望在数据输入上执行此操作,而不是在整个表上执行此操作,因为这将花费很长时间。
This is pretty much what we do
Of course you want to do this on data entry not to the whole table as that will take forever.