Abstract: During the development project, a problem occurs: the data obtained from the remote server is composed of a regular string, but what you want is not the string, it is a string, So it uses the powerful Oracle functions. My problem is this. I want to extract the string in the red box shown below
Abstract: During the development project, a problem occurs: the data obtained from the remote server is composed of a regular string, but what you want is not the string, it is a string, So it uses the powerful Oracle functions. My problem is this. I want to extract the string in the red box shown below
Abstract: During the development project, a problem occurs: the data obtained from the remote server is composed of a regular string, but what you want is not the string, it is a string, So it uses the powerful Oracle functions. My problem is this. I want to extract the string in the red box shown below, that is to say, extract the string between the first "-" and the second:
I ::
2. Create a data table:
CREATE TABLE test (name VARCHAR2 (32));
3. insert data into the table:
insert into test values('CA-CA1344-A-11OCT141250-D');insert into test values('JD-JD693-A-11OCT141105-D');
Iv. query results:
Method 1:
select substr(name,instr(name,'-',1)+1,instr(name,'-',instr(name,'-',1)+1)-instr(name,'-',1)-1) from test;
Method 2:
select substr(name,instr(name,'-',1,1)+1,instr(name,'-',1,2)-1-instr(name,'-',1,1)) from test;
5. The result is as follows:
6. Next, let's write another method to take the string between the second "-" And the third:
select substr(name,instr(name,'-',2,2)+1,instr(name,'-',2,3)-1-instr(name,'-',2,2)) from test;
Result 7: