Page 1 of 1

Replace Only second character with # in the name.

Posted: Sat Jul 25, 2015 8:38 pm
by ThriVikram
Hi,

In a DB2 Table, say Employee, I need to replace only second character with # in the first name. How to do that?

Can someone please help with this question. I was not able to understand that question and could not answer it.

Re: Replace Only second character with # in the name.

Posted: Sat Jul 25, 2015 9:10 pm
by Robert Sample
This may have been a question to determine your problem-solving techniques, or it may have been a question to check your knowledge of DB2 functions. Questions that would need to be answered include:
- Is first name a column in the table?
- If not, is the employee name in first name last name order or last name, first name order?
Depending on the answers to these questions, you should have mentioned SUBSTR and LOCATE functions.

Re: Replace Only second character with # in the name.

Posted: Sun Jul 26, 2015 7:34 pm
by Anuj Dhawan
Assuming EMP_NAME is the column for first name, this should help:

Code: Select all

SELECT EMP_NAME,SUBSTR(ENAME,1,1)||'#'||SUBSTR(EMP_NAME,3,LENGTH(EMP_NAME)) FROM EMPLOYEE;


where EMPLOYEE is the table name.