Qasim0787
Qasim0787

Reputation: 301

How to add leading spaces in oracle?

I want to add leading spaces in one of the column of the table. This ID column has data type Char(6).

Example: Table1

ID
1234
5678

when I do select * from Table1. and save file into .csv with pipeline delimited. It show spaces at the end of number.

Current output:

 |1234  |
 |5678  |

desired output

 |  1234|
 |  5678|

Upvotes: 0

Views: 8081

Answers (2)

Justin Cave
Justin Cave

Reputation: 231681

You'd need to trim the value to remove the trailing spaces and then lpad it to add the leading spaces

select lpad(trim(id),6)
  from your_table

Here is a sqlfiddle example that shows the steps

Upvotes: 3

FutbolFan
FutbolFan

Reputation: 13733

Try:

select LPAD(trim(id), 2) from table

Upvotes: 2

Related Questions