convert decimal data type to integer and char(8) data types

How do I convert decimal data type to integer and char(8) data types

table name
titles
column name
PRICE

21.99
19.95
39.95
12.99
6.95
19.95
23.95
10
13.95

This is an example from the internet that I tried, without success
SELECT SUBSTRING(price, 1, 30) AS price
FROM titles
WHERE CONVERT(char(8))
mnb951Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve WalesSenior Database AdministratorCommented:
For converting to characters use the to_char function.

Syntax with examples here: http://www.techonthenet.com/oracle/functions/to_char.php

For decimal to integer what are you planning on doing with the decimal pieces since integers by definition are whole numbers.

If you want to round to the nearest whole number use the ROUND function:
http://www.techonthenet.com/oracle/functions/round_nbr.php

If you just want to chop them off use the TRUNC function:
http://www.techonthenet.com/oracle/functions/trunc_nbr.php
0
awking00Information Technology SpecialistCommented:
You can also use floor and ceil functions. Given your examples, precisely what do you want the outcome to be?
0
SujithData ArchitectCommented:
Not clear what is the expected output you are looking for. Post your sample data and expected results.

you may try something like this.

SQL> select * from tbl1;
 
       VAL
----------
     21.99
     19.95
     39.95
     12.99
      6.95
     19.95
     23.95
        10
     13.95
 
9 rows selected.
 
SQL> select val, to_char(val), lpad(to_char(val), 8), round(val)
  2  from tbl1;
 
       VAL TO_CHAR(VAL)                             LPAD(TO_ ROUND(VAL)
---------- ---------------------------------------- -------- ----------
     21.99 21.99                                       21.99         22
     19.95 19.95                                       19.95         20
     39.95 39.95                                       39.95         40
     12.99 12.99                                       12.99         13
      6.95 6.95                                         6.95          7
     19.95 19.95                                       19.95         20
     23.95 23.95                                       23.95         24
        10 10                                             10         10
     13.95 13.95                                       13.95         14
 
9 rows selected.
 
SQL> 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
awking00Information Technology SpecialistCommented:
I find it interesting that you accepted answers, but gave a grade of B, when the responders requested you to post some sample data and your expected output. Had you done so, I'm sure you would have been provided an answer worthy of a grade of A.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.