- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
Length will be dynamic and i want to find the data before last occurrence of a character in a string in MYSQL
类似于 php 中的 strrchr
To get last occurrence of _ (underscore) I need to pass length. and here it's 3
mysql> SELECT SUBSTRING_INDEX ('this_is_something_here', '_', 3);+----------------------------------------------------+| SUBSTRING_INDEX ('this_is_something_here', '_', 3) |+----------------------------------------------------+| this_is_something |+----------------------------------------------------+
And here, to get last occurrence of _ (underscore) i need to pass length. and here it's 6
mysql> SELECT SUBSTRING_INDEX ('and_this_may_go_like_this_too', '_', 6);+-----------------------------------------------------------+| SUBSTRING_INDEX ('and_this_may_go_like_this_too', '_', 6) |+-----------------------------------------------------------+| and_this_may_go_like_this |+-----------------------------------------------------------+
i want data string before last occurrence of _ (underscore) just shown in above example but without passing length.
Note : from above example i want before data of "_here" and "_too"
last occurrence of _ (underscore)
在 MySQL 中是否有任何内置功能可以实现此目的?
在此先感谢 friend 们。
最佳答案
我不太明白你的例子,但我认为你想要的是传递 -1 作为长度并在前面加上子字符串。
比较
strrchr('and_this_may_go_like_this_too', '_'); // Returns _too
SELECT SUBSTRING_INDEX('and_this_may_go_like_this_too', '_', -1);
-- Returns too, just need to concatenate `_` so...
SELECT CONCAT('_', SUBSTRING_INDEX('and_this_may_go_like_this_too', '_', -1));
-- Returns _too
如果您正在寻找字符串的之前和针之前的部分,并且不是从针到字符串末尾的部分,您可以使用:
SET @FULL_STRING = 'this_is_something_here';
SELECT LEFT(@FULL_STRING, LENGTH(@FULL_STRING) - LOCATE('_', REVERSE(@FULL_STRING)));
-- Returns this_is_something
请注意,第二个语句不是strrchr
所做的。
关于MySQL : Find the last occurrence of a character in a string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44276940/
我知道,我不是第一个问这个的人。我在堆栈本身中发现了很多问题,比如 Delete only one instance of a recurring event from my Android cale
我有一个字符串: a = '0202201131181' 我想用单个 1 替换 a 中所有多次出现的 1 ,但如果只有一次 '1 ' 找到然后用空字符串 '' 替换它。 我的最终目标是: a = '0
我需要在给定日期之后从 loginhistory 表中查找重复出现的用户登录。我尝试了以下查询,但它给出了零行。 loginhistory 表有两列,即 userkeyid 和 datecreated
我有两个数据集,我想要的可能被松散地称为“非关键变量的外部连接”。 这是数据集 数据集 1 oc oc2 state_id r_state A011 A01 1808 1.00
因此,此方法会传递一个 Occurences 数组列表,其中每个包含一个字符串和一个频率。频率是这里唯一重要的部分。但我需要做的是使用二分搜索将 arraylist 中的最后一个元素插入到排序位置。每
谁能告诉我为什么以下内容不匹配: >>> re.search(r'(\d{2, 10})', '153') 这个匹配: >>> re.search(r'\d{3}', '153') 最佳答案 re模
我尝试定义以下类型 Inductive t : Type -> Type := | I : t nat | F : forall A, (t nat -> t A) -> t A. 我收到以下
这是我的代码片段: import Control.Monad.State as S get x = x + 1 现在,如果我尝试使用 get,我会收到以下错误: Ambiguous occurrenc
当您在 NetBeans 7 中选择一个变量时,使用 PHP(也适用于其他语言),程序会突出显示文件中使用相同变量的所有位置。 我知道如何更改实际突出显示文本的颜色(在 Options->Fonts
这个问题已经有答案了: How to get multiple regex matches in Java? (2 个回答) 已关闭 3 年前。 我有一个电话号码和其他文本列表,如下所示: +1-70
这个问题已经有答案了: How to Count Repetition of Words in Array List? (5 个回答) 已关闭5 年前。 我使用 Collections.frequen
我有一个翻译表,其中有一列重复包含值(语言名称)。如下: id | neutral text | language | translation ---+--------------+---------
我已尝试实现这篇文章中的想法,以按每对的出现顺序对我的输出进行排序 - MySQL: Count occurrences of distinct values 我需要的是能够考虑两个不同的列,而不仅仅
假设我有以下内容: items : (item separator)+ 这适用于: i1, i2, i3, 但不适用于: i1, i2, i3 如何做到不需要结尾分隔符? 最佳答案 这看起来更像是您需
这个问题在这里已经有了答案: Replace all NSNull objects in an NSDictionary (8 个答案) 关闭 8 年前。 我有一个 NSArray其中包含 stri
我有以下文本文件。 foo1 bam foo1 bam foo2 bam foo1 zip foo2 boo foo1 zip foo3 zip 我想制作一个
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve thi
在 OCaml 中,如何在正则表达式中指定模式的出现次数?我浏览了 Str 模块,找不到 {n} 的等效项量词。 例如,如果我想指定一个“年份”模式,即正好 4 位数字,除了执行 "[0-9][0-9
我有一个很大的data.table(这里只显示了五行)。 taxpath
我有一张这样的表: col1 col2 id1 item1 id1 item2 id1 item3 id2 item1 id2 item4 i
我是一名优秀的程序员,十分优秀!