-4

I am not able to create a this Select query :

When I query:

SELECT DISTINCT PRODUCT_ID FROM SYSADM.TABLE; 

I get the output as:

EMA12345

EMA4567844

EMA4545455

US12342

NA4545454

PRS767657

Now I want to fetch the data such as product id retrieved is:

12345

4567844

4545455

US12342

NA4545454

PRS767657

That means every product id other than starting with EMA should come as it is and those starting with EMA should be without EMA.

Need to append this within another select query. Can't use procedure.

0

3 Answers 3

1

Use the REPLACE function:

SELECT DISTINCT REPLACE(PRODUCT_ID, 'EMA') FROM SYSADM.TABLE
Sign up to request clarification or add additional context in comments.

Comments

1
SELECT DECODE( INSTR( product_id, 'EMA' ), 1, SUBSTR( product_id, 4 ), 
               product_id ) AS my_column
  FROM SYSADM.TABLE

Basically, if the first three characters of product_id are "EMA" then use the 4th character to the end of product_id, otherwise, use the whole product_id.

Comments

1

You could chain togethor replace statements such as:

select replace( replace( replace( product_id, 'EMA' ), 'US' ), 'NA' ) from sysadm.table;

Or follow one of the alternatives from here.

1 Comment

Oops sorry, misread. Thought you wanted to remove all prefixes.

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.