Get the first 5 characters of a column in DB2?

All sort of Mainframes Interview Questions.
Post Reply
Suresh R
New Member
Posts: 2
Joined: Fri Dec 19, 2014 3:34 pm

Get the first 5 characters of a column in DB2?

Post by Suresh R »

Hi,

How can we get the first 5 characters of a column in DB2? Interviewer explained it again saying, how would you get the first 5 characters of say, FIRSTNAME column of DB2 table STUDENT?

Please help how to do this?
Chandan Yadav
Website Team
Website Team
Posts: 70
Joined: Wed Jul 31, 2013 10:19 pm

Re: Get the first 5 characters of a column in DB2?

Post by Chandan Yadav »

Hi,

Check for SUBSTR function of Db2

Regards,
Chandan
Suresh R
New Member
Posts: 2
Joined: Fri Dec 19, 2014 3:34 pm

Re: Get the first 5 characters of a column in DB2?

Post by Suresh R »

Thanks Chandan. Examples in this link http://www-01.ibm.com/support/knowledge ... ubstr.dita has helped me. Giving it here for reference:

Example 1: FIRSTNME is a VARCHAR(12) column in sample table DSN8A10.EMP. When FIRSTNME has the value 'MAUDE':

SUBSTR(FIRSTNME,2,3) -- 'AUD'
SUBSTR(FIRSTNME,2) -- 'AUDE'
SUBSTR(FIRSTNME,2,6) -- 'AUDE' followed by two blanks
SUBSTR(FIRSTNME,6) -- a zero-length string
SUBSTR(FIRSTNME,6,4) -- four blanks
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: Get the first 5 characters of a column in DB2?

Post by zprogrammer »

Thanks for sharing the link , It would help people future :)
zprogrammer
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.”