Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Inserting leading zeros into oracle database field

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
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.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

721 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