SUBSTR and INSTR SQL Oracle

后端 未结 2 1302
-上瘾入骨i
-上瘾入骨i 2021-01-28 08:49

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;         


        
2条回答
  •  日久生厌
    2021-01-28 09:37

    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.

提交回复
热议问题