Solved

Inserting leading zeros into oracle database field

Posted on 2009-04-08
4
1,308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
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 shows how to recover a database from a user managed backup
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

635 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