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?
 
SujithConnect With a Mentor Data 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
 
Steve WalesConnect With a Mentor Senior 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
 
awking00Connect With a Mentor Commented:
You can also use floor and ceil functions. Given your examples, precisely what do you want the outcome to be?
0
 
awking00Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.