问题描述:

'YOUR UTR SBINH13246802674 RTN' this is the input. I want fetch only 'SBINH13246802674' from the above input. This value is inserted to another column, that's why I am fetching that particular value. The condition is to only use the Oracle TRIM function. Is there possible to fetch that value using TRIM?

网友答案:

If you only want to use trim then use the below.

select rtrim(ltrim('YOUR UTR SBINH13246802674 RTN', 'YOUR UTR '), 'RTN') from dual;

If you need to do with any function then go for below considering you have all data with same format and length "YOUR UTR {DATA}"

select substr('YOUR UTR SBINH13246802674 RTN' , 10, 16) from dual;
网友答案:

You could use below select query:

SELECT TRIM(' ' FROM TRIM(TRAILING 'R' FROM TRIM(TRAILING 'T' FROM TRIM(TRAILING 'N' FROM TRIM('R' FROM TRIM('T' FROM TRIM('U' FROM 
       TRIM(' ' FROM TRIM('R' FROM TRIM('U' FROM TRIM('O' FROM TRIM('Y' FROM 'YOUR UTR SBINH13246802674 RTN')))))))))))) DATA
FROM   DUAL;

This method uses repeated TRIMs which take out the unwanted string, one character at a time.

A better way to do this, however, is:

SELECT REPLACE(REPLACE('YOUR UTR SBINH13246802674 RTN', 'YOUR UTR '), ' RTN')
FROM   DUAL;
相关阅读:
Top