Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Inserting leading zeros into oracle database field

Posted on 2009-04-08
4
Medium Priority
?
1,500 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 500 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 21

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

782 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