20

I need the output of a string column in my table as 13 length char, irrespective of whatever length it is, i need to stuff the remaining chars with 0...

I tried to use the following code in my hive query, but failed to get the desired output

right('0000000000000' + ProductID, 13)

Any help? Thanks

Muthu Palaniappan
  • 221
  • 1
  • 2
  • 5

1 Answers1

53

Hive has built-in lpad and rpad functions. In your case you could use:

lpad(ProductId, 13, "0")

Or, if you might need to truncate to 13 characters, you could wrap this in the "right" function.

Jason Rosendale
  • 593
  • 6
  • 6