SUBSTR和INSTR SQL Oracle [英] SUBSTR and INSTR SQL Oracle
问题描述
我已经开始在Oracle中使用SUBSTR和INSTR,但是遇到这个问题时我感到困惑.
I've started using SUBSTR and INSTR in Oracle but I got confused when I came across this.
SELECT PHONE, SUBSTR(PHONE, 1, INSTR(PHONE, '-') -1)
FROM DIRECTORY;
所以我知道SUBSTR切断了值,而INSTR显示了发生的位置,但是我上面举的示例使我感到困惑,因为结果为362.当我的原始值为362-127-4285时.这是如何运作的?
So I know SUBSTR cuts values off, and INSTR shows where the occurrence is but the example I've put above has confused me, because the result it 362. When my original value was 362-127-4285. How does that work?
推荐答案
INSTR(PHONE,'-')
给出-
的 index >在 PHONE
列中,以您的情况为 4
然后是 SUBSTR(PHONE,1,4-1)
或 SUBSTR(PHONE,1,3)
从 1st
给出 PHONE
列的 substring ,其长度为 3
个字符,即 362
,
如果 PHONE
列的值为 362-127-4285
.
INSTR(PHONE, '-')
gives the index of -
in the PHONE
column, in your case 4
and then SUBSTR(PHONE, 1, 4 - 1)
or SUBSTR(PHONE, 1, 3)
gives the substring of the PHONE
column from the 1st
that has length of 3
chars which is 362
,
if the value PHONE
column is 362-127-4285
.
这篇关于SUBSTR和INSTR SQL Oracle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!