Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DB2 Functions

Status
Not open for further replies.

Dagon

MIS
Jan 30, 2002
2,301
GB
I recently started using DB2 after years of using Oracle. There are a few functions I used a lot in Oracle that I'm struggling to find equivalents of in DB2.

a) Is there a function which pads a string with a given character either on the right or the left (lpad/rpad in Oracle) e.g.

select lpad('9', 5, '0') gives '000009'
select rpad('9', 5, '0') gives '900000'

I suppose I could contrive something using REPEAT and concatenate but that seems like hard work.

b) Is there a function which converts dates to strings and vice versa ? I know there is a date function but this only recognises certain formats. For example, if I try to pass a date in a format such as YYYYMMDD rather than YYYY-MM-DD, it doesn't like it. Is there one where you can specify the format you would like the date to appear in ?




 
Dagon,

there are functions in DB2 which I believe to be the equivalent.

Try using RIGHT and LEFT.

SELECT RIGHT('00000'¦¦col_1,length)

Cheers
Greg

 
Hi,

You can also try using SUBSTR function.

Cheers,
Grofaty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top