Cristhian David
Cristhian David

Reputation: 3

How to fill a field until it reaches the length of the field SQL

I have a field that is 11 in length, what happens in this field is that when the entered data does not reach 11, we must fill the rest with 0, for example we enter the data "CARLOS", then in the database it should look like this "00000CARLOS"

Upvotes: 0

Views: 354

Answers (1)

GMB
GMB

Reputation: 222482

You can use lpad():

lpad(mycol, 11, '0')

This function is supported in both MySQL and Oracle (you initially tagged both), with the same syntax.

Upvotes: 1

Related Questions