SQL 中的字符串函数
我需要查询(更具体地说,它是视图,而不是查询)将返回字符串列。字符串将是代码,可能以两个字母 (LJ) 为前缀。如果它有前缀--前缀必须被修剪。如果不存在前缀,则应保持不变。在 SQL 中可以做这样的事情吗?服务器是FirebirdSQL 1.5。
给定的解决方案都不起作用,但在他们的帮助下,我能够自己解决这个问题。 Substring
函数确实存在,但语法不同。您必须使用正确的关键字而不是逗号:
Substring(col from pos for count)
I need query (to be more specific, it is view, not query) that will return string column. String will be code, that might be prefixed with two letters (LJ). If it is prefixed -- prefix have to be trimmed. If there is no prefix present, it should be left untouched. Is it possible to do such thing in SQL? Server is FirebirdSQL 1.5.
None of given solutions worked, but with their help, I was able to figure it out by myself. Substring
function does exist, but has different syntax. Instead of commas you have to use proper keywords:
Substring(col from pos for count)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这就是我认为您正在寻找的内容,尚未执行测试,但您得到了要点...
希望它有帮助!
That's what I think you are looking for, haven't executed to test but you get the gist...
Hope it helps!
你可以通过字符串操作来做到这一点:
不确定这是否可以在 Firebird 中工作(在 Mysql 上测试)。
You could do it with string manipulation:
Not sure this would work in Firebird (tested on Mysql).
获取 FreeUDFLib 的副本,它有很多用于字符串、数学、日期的函数、转换、blob 处理等。它会做你想做的事情,还有更多的事情
Get a copy of FreeUDFLib, it have a LOT of functions for strings, math, date, convertions, blob handling, etc. It will do what you want, an a lot more of things
是的,不要选择列本身,而是编写一个表达式,将前缀 LJ 替换为空
yes, instead of selecting the column itself, write an expression that replaces the prefix LJ with nothing