Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Datatype to use when inserting money

I am using Oracle SQL database and I have to insert a monetary value(salary) as part of a row. For some strange reason the money command isnt working, is there any alternates that would work with this?

Data input format: £00,000.000

CREATE TABLE staff
                   (staffno CHAR(6) NOT NULL
                    , staffsurname VARCHAR(8) NOT NULL
                    , staffforename VARCHAR(7) NOT NULL
                    , salary MONEY NOT NULL
                    , PRIMARY KEY (staffno)
                   );
like image 283
user3686991 Avatar asked Mar 12 '15 15:03

user3686991


People also ask

Which data type is used for money?

The money data type is an abstract data type. Money values are stored significant to two decimal places. These values are rounded to their amounts in dollars and cents or other currency units on input and output, and arithmetic operations on the money data type retain two-decimal-place precision.

What is the best data type for price in SQL?

The best type for price column should be DECIMAL. The type DECIMAL stores the value precisely. For Example - DECIMAL(10,2) can be used to store price value. It means the total digit will be 10 and two digits will be after decimal point.

Which data type is best for currency amounts in SQL Server?

If you need the highest precision, a DECIMAL can use up to 17 bytes for each value. Generally though, I like using DECIMAL(19,4) for currency, which needs 9 bytes and can store numbers 19 digits wide, where the last four digits are after the decimal place.


1 Answers

Look at this line

salary MONEY NOT NULL

There is no existing money datatype.

If you are looking for something similar to SQL-Server small money type, you want to use a Number(10,4) and then format the number.

You can format the number using to_char function

select to_char(yourColumn, '$99,999.99') from yourTable where someCondition
like image 176
Jean-François Savard Avatar answered Oct 24 '22 02:10

Jean-François Savard