问题
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)
);
回答1:
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
回答2:
The "strange" reason is simple: There is no MONEY data type.
The data type most appropriate for monetary values would be NUMBER (using an appropriate scale). Since it is a decimal floating-point type, it is better suited for monetary values than the binary floating-point types BINARY_FLOAT
and BINARY_DOUBLE
.
Note, though, that you will still need to parse the input string £00,000.000
in your front end and send it as a numeric value to the back end.
来源:https://stackoverflow.com/questions/29014283/sql-datatype-to-use-when-inserting-money