varchar_to_num1.htm
Objective:
  • conversion of varchar to number type
  • number precisions to decimal points
Script:

-- convert varchar to number
-- convert_varchar_num1.sql
declare
v_char1 varchar2(20):= '1234.567891012';
--n_num1 number(10,7):= 1234.56789; -- not allowed
n_num1 number(10,4):= 1234.56789;-- equal or less
n_total1 number(10,4);
n_total2 number(10,8);
begin
n_total1 := n_num1 + v_char1;
dbms_output.put_line('char '||v_char1);
dbms_output.put_line('Total '||n_total1);
--
n_total2 := n_num1* 12 * '.0021';
n_total1:= v_char1;
dbms_output.put_line('Total 4 presc '||n_total1);
dbms_output.put_line('Total 8 presc '||n_total2);
end;
/