Replace Only second character with # in the name.

All sort of Mainframes Interview Questions.
Post Reply
ThriVikram
New Member
Posts: 1
Joined: Wed Dec 17, 2014 12:18 pm

Replace Only second character with # in the name.

Post 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.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

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

Post 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.
User avatar
Anuj Dhawan
Founder
Posts: 2802
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

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

Post 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.
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “Interview Questions.”