插入钱时使用的 SQL 数据类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29014283/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Datatype to use when inserting money
提问by user3686991
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?
我正在使用 Oracle SQL 数据库,我必须插入一个货币值(工资)作为行的一部分。由于某种奇怪的原因,货币命令不起作用,是否有任何替代方法可以解决这个问题?
Data input format: £00,000.000
数据输入格式:£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)
);
采纳答案by Jean-Fran?ois Savard
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.
如果您正在寻找类似于SQL-Server
小额货币类型的东西,您想使用 aNumber(10,4)
然后格式化数字。
You can format the number using to_char
function
您可以使用to_char
功能格式化数字
select to_char(yourColumn, ',999.99') from yourTable where someCondition
回答by Heinzi
The "strange" reason is simple: There is no MONEY data type.
“奇怪”的原因很简单:没有 MONEY 数据类型。
The data type most appropriate for monetary values would be NUMBER
(using an appropriate scale). Since it is a decimalfloating-point type, it is better suited for monetary values than the binaryfloating-point types BINARY_FLOAT
and BINARY_DOUBLE
.
最适合货币值的数据类型是NUMBER
(使用适当的比例)。由于它是十进制浮点类型,因此与二进制浮点类型BINARY_FLOAT
和BINARY_DOUBLE
.
Note, though, that you will still need to parsethe input string £00,000.000
in your front end and send it as a numeric valueto the back end.
但是请注意,您仍然需要在前端解析输入字符串£00,000.000
并将其作为数值发送到后端。