sql 如何使用SQL在字符串中找到字符串的第一个位置?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 如何使用SQL在字符串中找到字符串的第一个位置?相关的知识,希望对你有一定的参考价值。
-------------------------------------MySQL------------------------------------------------------------------------
select
'The first agreement is to be impeccable with your word.
When you are impeccable, you take responsibility for your actions, but you do not judge or blame yourself!
Being impeccable with your word is not using the word against yourself.
Being impeccable with your word is the correct use of your energy' as phrase,
instr('The first agreement is to be impeccable with your word.
When you are impeccable, you take responsibility for your actions, but you do not judge or blame yourself!
Being impeccable with your word is not using the word against yourself.
Being impeccable with your word is the correct use of your energy', 'impeccable') as first_pos
phrase |first_pos
-------------------------------------------------------------------------------------|----------
The first agreement is to be impeccable with your word. ¶When you are impeccable, you|30
-----------------------------------PostgreSQL---------------------------------------------------------------------
select
'The first agreement is to be impeccable with your word.
When you are impeccable, you take responsibility for your actions, but you do not judge or blame yourself!
Being impeccable with your word is not using the word against yourself.
Being impeccable with your word is the correct use of your energy' as phrase,
position('impeccable' in 'The first agreement is to be impeccable with your word.
When you are impeccable, you take responsibility for your actions, but you do not judge or blame yourself!
Being impeccable with your word is not using the word against yourself.
Being impeccable with your word is the correct use of your energy') as first_pos
phrase |first_pos
-------------------------------------------------------------------------------------|----------
The first agreement is to be impeccable with your word. ¶When you are impeccable, you|30
-------------------------------------SQL server----------------------------------------------------------------
select
'The first agreement is to be impeccable with your word.
When you are impeccable, you take responsibility for your actions, but you do not judge or blame yourself!
Being impeccable with your word is not using the word against yourself.
Being impeccable with your word is the correct use of your energy' as phrase,
charindex('impeccable', 'The first agreement is to be impeccable with your word.
When you are impeccable, you take responsibility for your actions, but you do not judge or blame yourself!
Being impeccable with your word is not using the word against yourself.
Being impeccable with your word is the correct use of your energy') as first_pos,
charindex('impeccable', 'The first agreement is to be impeccable with your word.
When you are impeccable, you take responsibility for your actions, but you do not judge or blame yourself!
Being impeccable with your word is not using the word against yourself.
Being impeccable with your word is the correct use of your energy',32) as second_pos
phrase |first_pos |second_pos |
-------------------------------------------------------------------------------------|----------|-----------|
The first agreement is to be impeccable with your word. ¶When you are impeccable, you|30 |71 |
以上是关于sql 如何使用SQL在字符串中找到字符串的第一个位置?的主要内容,如果未能解决你的问题,请参考以下文章
在 SQL (Presto) 中的字符串中查找模式的第 n 次出现