5

I have this table of rows

RowA
______
ABC123
DEF432
WER677
JKL342

how can I add a '_' in between the record using oracle to this? Assuming to add on the last 4 character.

RowA
______
ABC_123
DEF_432
WER_677
JKL_342

2 Answers 2

13

You would try something like:

Update Table_name set table_column = substr(table_column, 1, 3) || '_' || substr(table_column, 4);

The SUBSTR functions allows you to extract a substring from a string. The syntax for the SUBSTR function is:

SUBSTR( string, start_position, [ length ] )

string is the source string.

start_position is the position for extraction. The first position in the string is always 1.

length is optional. It is the number of characters to extract. If this parameter is omitted, the SUBSTR function will return the entire string.

Sign up to request clarification or add additional context in comments.

Comments

7

Another approach, using regexp_replace() regular expression function:

 select regexp_replace(RowA, '^([[:alpha:]]{3})', '\1_') as res
   from your_table

Result:

RES
----------
ABC_123
DEF_432
WER_677
JKL_342

SQLFiddle Demo

Comments

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.