Home » SQL & PL/SQL » SQL & PL/SQL » Update Data Script -- Help !!!
Update Data Script -- Help !!! [message #19648] Tue, 02 April 2002 10:33 Go to next message
Arpit
Messages: 99
Registered: March 2001
Member
Hello ,

Can someone help me with my update script. I need to update the phone field in the employee table. The data this field has is +1 (416) 666-1234. How could i update it to (416) 666-1234. I need to get rid of +1 along with a single space.

Any help on this would be highly appreciated.

Thanks!
Alpesh
Re: Update Data Script -- Help !!! [message #19649 is a reply to message #19648] Tue, 02 April 2002 11:17 Go to previous messageGo to next message
Cindy
Messages: 88
Registered: November 1999
Member
Try this:

http://www.orafaq.net/cgi-bin/msgboard/view.cgi?board=sql&message=5051&query=to_phone

Execute the to_phone function then try the following:

update table_name
set phone_col = to_phone(17775559990, '9(999) 999-9999')
where pk_col = 'xxxxxx';

I have not test the update statement, but I believe it should work.
Re: Update Data Script -- Help !!! [message #19669 is a reply to message #19648] Wed, 03 April 2002 06:19 Go to previous messageGo to next message
Arpit
Messages: 99
Registered: March 2001
Member
Hello Cindy,

Thanks for your reply back.

while I run the script, it complains about an invalid column name for to_phone.

Any suggestions ?

Thanks!
Re: Update Data Script -- Help !!! [message #19672 is a reply to message #19648] Wed, 03 April 2002 07:23 Go to previous messageGo to next message
Cindy
Messages: 88
Registered: November 1999
Member
To_PHONE function:

create or replace function to_phone(phonein number, p_format varchar2)
return varchar2 is
phoneout varchar2(20) default '';
vlen number;
cnt pls_integer default 0;
cnt2 pls_integer default 0;
begin
vlen := length(p_format);

for i in 1..vlen loop
cnt := cnt + 1;

if substr(p_format, cnt, 1) <> '9' then
phoneout := phoneout || substr(p_format, cnt, 1);
cnt2 := cnt2 + 1;
else phoneout := phoneout || substr(phonein, (cnt - cnt2), 1);
end if;

end loop;
return phoneout;
end;
/

@to_phone.sql

SQL> create table t (t_phone varchar2(15));

Table created.

SQL> desc t
Name Null? Type
----------------------------------------- -------- -----------------
T_PHONE VARCHAR2(15)

SQL>insert into t values ('+1(777)234-8889');

Before update in t table:

SQL> select * from t;

T_PHONE
---------------
+1(777)234-8889

SQL> update t
2 set t_phone = to_phone(18887772222, '9(999) 999-9999');

1 row updated.

SQL> commit;

Commit complete.

After update t table:

SQL> select * from t;

T_PHONE
---------------
1(888) 777-2222

To_phone function will take convert any format. Check your columns name and don't modify any codes in the to_phone function.
Re: Update Data Script -- Help !!! P.S....... [message #19673 is a reply to message #19648] Wed, 03 April 2002 07:37 Go to previous message
Cindy
Messages: 88
Registered: November 1999
Member
When you do your update. Don't forget to include the where clause to select desire record to be updated only. Just a reminder.
Previous Topic: outer join
Next Topic: Update from multiple tables
Goto Forum:
  


Current Time: Fri Apr 19 16:17:43 CDT 2024