Solved

Inserting leading zeros into oracle database field

Posted on 2009-04-08
4
1,038 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Stay Alert! 13 62
Oracle SQL Syntax 8 57
Oracle Database creation fails 5 36
ORA-12560: TNS:protocol adapter error 8 48
Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
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…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now