Solved

Inserting leading zeros into oracle database field

Posted on 2009-04-08
4
1,117 Views
Last Modified: 2013-12-19
Hi I have an oracle database with address and contact details on it. We recently did a change to one of the tables and to keep my data safe we did a csv extract.  The data was re-imported when the other work had been done, unfortunately no one chedked the csv telephone field and we have managed to strip out the leading zero's from the telephone number.  My sql is not good enough to write a script that will allow me to insert the leading zero without destroying the main body of the number. Can anyone help please?

Mike
the table name is unit and the field is called cellular_code

Open in new window

0
Comment
Question by:202sqn
4 Comments
 
LVL 16

Accepted Solution

by:
Milleniumaire earned 125 total points
ID: 24098795
Assuming you want to update the data, try:

update unit
set cellular_code = lpad(cellular_code,'0',8)
where cellular_code is not null;

Where 8 is the required size of your cellular_code value.

You could test the statement using a select statement first:

select cellular_code, lpad(cellular_code,'0',8) new_cellular_code
from unit
where cellular_code is not null;
0
 
LVL 20

Expert Comment

by:flow01
ID: 24098917
If cellular_code is defined as varchar2 and
if you want 10 positions:

select lpad(cellular_code,10,'0')  from unit
where rownum < 100
/

update  unit set cellular_code = lpad(cellular_code,10,'0')
/
0
 
LVL 23

Expert Comment

by:David
ID: 24099255
Presumably you are not storing this as numeric, in which case it's simply masking the column to the desired display.
0
 

Author Closing Comment

by:202sqn
ID: 31568104
Thanks all for your input. I selected this as my answer as it is simple for me to understand thank you
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
execute immediate plsql block 5 57
Use of Exception to end a Loop 3 45
Oracle encryption 12 48
Database Design Dilemma 6 58
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question