在 Sybase 中创建唯一的 char 值
我需要创建一个 Syb15 存储过程,它接受 char(6) @parent 并基于 @parent 返回唯一的 char(6)。我想将 @parent 截断为最多 3 个字符,然后将字母 [AZ] 附加到该值,以便以前未使用过新符号。以下是运行序列示例:
get_sub_symbol( "DISNEY" ) 返回 "DISA"
get_sub_symbol( "DISNEY" ) 返回 "DISB"
get_sub_symbol( "GE" ) 返回 "GEA"
...
get_sub_symbol( "DISNEY" ) 返回 "DISZ"
get_sub_symbol( "DISNEY" ) 返回 "DISAA"
get_sub_symbol( "DISNEY" ) 返回 "DISAB"
get_sub_symbol( "GE" ) 返回 "GEB"
性能很重要,因此如果有一个带有 (symbol, last_suffix) 映射的新表会比处理“从符号中选择符号,其中符号像 substring(@父级,1, 3)”,那就可以了。
感谢您的帮助,
贾里德
I need to create a Syb15 stored proc that takes a char(6) @parent and returns a unique char(6) based on @parent. I want to truncate @parent to a max of 3 chars, and then append letters [A-Z] to that value such that the new symbol has not been used before. Here is an example run sequence:
get_sub_symbol( "DISNEY" ) returns "DISA"
get_sub_symbol( "DISNEY" ) returns "DISB"
get_sub_symbol( "GE" ) returns "GEA"
...
get_sub_symbol( "DISNEY" ) returns "DISZ"
get_sub_symbol( "DISNEY" ) returns "DISAA"
get_sub_symbol( "DISNEY" ) returns "DISAB"
get_sub_symbol( "GE" ) returns "GEB"
Performance is important, so if having a new table with (symbol, last_suffix) mappings would be better than processing the list returned by "select symbol from symbols where symbol like substring(@parent, 1, 3)", then that is ok.
Thanks for your help,
Jared
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你回答了你自己的问题。
确定您拥有的最大重复项数。创建一个包含许多唯一字符串的查找表。再加上意外情况等。查找新值时,取现有值的 MAX(),查找它,然后查找下一个值。
是的,单独存储缩写名称和后缀会有所帮助。
然而,就我个人而言,我只是使用 INT 作为后缀。无需查找表;
MAX(后缀)+ 1
。You answered your own question.
Determine the maximum number of duplicates you'd have. Create a lookup table with that many unique strings. Plus contingency, etc. When lookuping up a new value, take the MAX() of the existing values, look it up, and find the next one.
And yes, storing the shortended name and the suffix separately will help there.
Personally, however, I'd just use an INT as the suffix. No lookup table needed;
MAX(suffix) + 1
.