Home » SQL & PL/SQL » SQL & PL/SQL » VARCHAR to NUMBER conversion
VARCHAR to NUMBER conversion [message #2923] Thu, 22 August 2002 05:18 Go to next message
Vinod
Messages: 76
Registered: April 1999
Member
Hey guyz,
I have a table -
field1 - VARCHAR(30)
field2 - NUMBER(5)

Whenever an insert happens in the table, i have to check if field1 has a valid numeric value. If yes, then update that value into field2. Now, i cannot find any function that can do this check form me. Any ideas on how to do this?

thanx,
Vinod.
Re: VARCHAR to NUMBER conversion [message #2929 is a reply to message #2923] Thu, 22 August 2002 09:19 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
I would just handle this in a trigger:

create or replace trigger trg_name
before insert on t
for each row
begin
  begin
    :new.field2 := to_number(:new.field1);
  exception
    when value_error then
      null;
  end;
end;
/
Previous Topic: Re: optimizing sql statement
Next Topic: Filtering
Goto Forum:
  


Current Time: Fri Apr 26 13:22:07 CDT 2024