How To Convert Character Types to Numeric Types

Q

How To Convert Character Types to Numeric Types? - Oracle DBA FAQ - Understanding PL/SQL Language Basics

✍: FYIcenter.com

A

You can convert character types to numeric types in two ways:

  • Explicitly by using TO_NUMBER() function.
  • Implicitly by putting character data in a numeric operation.

The sample script below shows you how to convert character types to numeric types:

PROCEDURE proc_convert_1 AS
  start_time CHAR(5);
  finish_time CHAR(5);
  elapsed_time NUMBER(5);
BEGIN
  start_time := '12052';
  finish_time := '15314';
  elapsed_time := TO_NUMBER(finish_time)
    - TO_NUMBER(start_time);
  elapsed_time := finish_time - start_time; -- same as above
END;

2007-04-30, 4885👍, 0💬