0

There is this value in a column, below i have shown i used to extract the data from that field.

with A4 as 
(
select 'govinda j/INDIA_MH/9975215025' as employee_name from dual
)
select employee_name , 
TRIM(SUBSTR(upper(A4.employee_name),1,INSTR(A4.employee_name,'/',1,1)-1)) AS employee_name1,
  TRIM(SUBSTR(upper(A4.employee_name),INSTR(A4.employee_name,'/',1,1)+1,INSTR(A4.employee_name,'_',1,1)-INSTR(A4.employee_name,'/',1,1)-1)) AS Country,
  TRIM(SUBSTR(upper(A4.employee_name),INSTR(A4.employee_name,'_',1,1)+1,INSTR(A4.employee_name,'/',1,2)-INSTR(A4.employee_name,'_',1,1)-1)) AS State

   from A4

Output

EMPLOYEE_NAME                   EMPLOYEE_NAME1   COUNTRY       STATE
govinda j/INDIA_MH/9975215025   GOVINDA J        INDIA         MH

Now our database system is changed, I am struggling to achieve same in postgres.

1
  • Are you really still using Postgres 9.1? That has been out of support for over 2 years now. You should really plan the upgrade to a supported version (e.g. 10) as soon as possible. Commented Sep 20, 2018 at 11:17

1 Answer 1

1

One option is split_part():

select split_part(employee_name, '/', 1) as employee_name1,
       split_part(split_part(employee_name, '/', 2), '_', 1) as country,
       split_part(split_part(employee_name, '/', 2), '_', 2) as state
from a4
Sign up to request clarification or add additional context in comments.

3 Comments

There is another column validate which is as below
Is there any similar function like REGEXP_COUNT in Postgres
@MayurRandive . . . New questions should be asked as new questions. This question is specifically about one format. Continually modifying a question is not a good practice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.