Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I need division of two varchar2 defined columns in NUMBER(19,10) format in Oracle

I am executing below sql not getting expected result, I am converting the columns into NUMBER(19,10) before division but I need the result (after division) to be converted into NUMBER (19,10);

SELECT DISTINCT 
CAST(TO_NUMBER(BASE_AMT) AS NUMBER (19,10))/CAST(TO_NUMBER(ACT_AMT) AS NUMBER (19,10))
FROM CUSTOMER;

Note: BASE_AMT and ACT_AMT columns are varchar2 defined

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should have probably applied cast function to final result, e.g.

SQL> create table customer (code varchar2(3), name varchar2(8), base_amt varchar2(5), act_amt varchar2(5));

Table created.

SQL> insert into customer (code, name, base_amt, act_amt) values ('100', 'Scott', '33', '4');

1 row created.

Like this:

SQL> select distinct
  2    cast(to_number(base_amt) / to_number(act_amt) as number (19,10)) result
  3  from customer;

    RESULT
----------
      8,25

SQL>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading