Format 1:substr(string string,int index,int length)
Understanding: substr (the intercepted string, the subscript is the position of the start intercept - integer, the intercepted length - integer)
Suitable for scenes with intercepted length limits.
Format 2:substr(string string,int index)
Understanding: substr (the intercepted string, the subscript is the position where the start intercepting is - integer)
Suitable for no length limit, intercepting from the subscript position and intercepting until the end
Note: The position where the subscript in the substr() function starts to intercept, where 0 and 1 refer to both the first position, there is no difference. When the index position is a negative number, it is to search for the index position from right to left, and then start to intercept from left to right from left to right from subscript position. (Many explanations of this function, that is, intercepting from right to left, is this statement wrong, don’t understand it much, right? Let’s see the examples if you have nothing to do, maybe I understand it after reading it)
Example Format 1:
Understanding: substr (the intercepted string, the subscript is the position of the start intercept - integer, the intercepted length - integer)
Suitable for fields with intercepted length limits
select substr('Learn knowledge is all about knowledge, and understanding human feelings is about articles',1,2) from dual;--Output‘Things in the world' select substr('Learn knowledge is all about knowledge, and understanding human feelings is about articles',0,2) from dual;--Output‘Things in the world' Start location0and1,The result is the same select substr('Learn knowledge is all about knowledge, and understanding human feelings is about articles',2,3) from dual;--Output‘Things are clear' 当Start location为负数时,Comparison results,Discover the rules select substr('Learn knowledge is all about knowledge, and understanding human feelings is about articles',-3,2) from dual;--Output‘Instant text' select substr('Learn knowledge is all about knowledge, and understanding human feelings is about articles',-4,2) from dual;--Output‘Deci' select substr('Learn knowledge is all about knowledge, and understanding human feelings is about articles',-7,2) from dual;--Output‘Human Relationship'
Example Format 2:
Format 2: substr(string string,int index)
Understanding: substr (the intercepted string, the subscript is the position where the start intercepting is - integer)
Suitable for no length limit, intercepting from the subscript position and intercepting until the end
select substr('No one supports me in the sky, I step on the snow to the top of the mountain',1) from dual;--Output‘No one supports me,I stepped on the snow to the top of the mountain' select substr('No one supports me in the sky, I step on the snow to the top of the mountain',0) from dual;--Output‘No one supports me,I stepped on the snow to the top of the mountain' select substr('No one supports me in the sky, I step on the snow to the top of the mountain',3) from dual;--Output‘Help me to be ambition,I stepped on the snow to the top of the mountain' When the start position is negative,Comparison results,Discover the rules select substr('No one supports me in the sky, I step on the snow to the top of the mountain',-3) from dual;--Output‘To the top of the mountain'' select substr('No one supports me in the sky, I step on the snow to the top of the mountain',-4) from dual;--Output‘雪To the top of the mountain' select substr('No one supports me in the sky, I step on the snow to the top of the mountain',-7) from dual;--Output‘I stepped on the snow to the top of the mountain'
Summarize
This is the article about the use of substr function for intercepting strings of oracle databases. For more related contents of substr function for substr function, please search for my previous articles or continue browsing the following related articles. I hope everyone will support me in the future!