SQL Server:应使用什么区域设置将数值格式化为 SQL Server 格式?
似乎 SQL Server 不接受使用以下格式的数字任何特定的语言环境。 它还不支持具有 0-9 以外数字的区域设置。
例如,如果当前区域设置是孟加拉语,则数字 123456789 将显示为 "১২৩৪৫৬৭৮৯"。这只是数字,不管数字分组是什么。
但是,对于Invariant区域设置中的数字也会出现同样的问题,该区域设置将数字格式设置为“123,456,789”,而 SQL Server 不会接受这种格式。
是否存在与 SQL Server 接受的数值相匹配的区域性?或者我是否必须创建一些自定义的“sql server”文化,自己从较低级别的格式化例程生成该文化的规则?
如果我在.NET(我不是)中,我可以仔细阅读标准数字格式字符串。 .NET 中可用的格式代码:
- c(货币):$123.46
- d(十进制):1234
- e(指数):1.052033E+003
- f(定点):1234.57
- g(常规):123.456
- n(数字):1,234.57
- p (百分比):100.00 %
- r(往返):123456789.12345678
- x(十六进制):FF
仅 6 接受所有数字类型:
- c(货币):$123.46
d(十进制):1234- e(指数):1.052033E+003
- f(定点):1234.57
- g(常规):123.456
- n(数字):1,234.57
- p(百分比):100.00 %
r(往返):123456789.12345678x (十六进制): FF
其中只有 2 个生成字符串表示形式,无论如何,在 en-US 语言环境中,SQL Server 都会接受它:
c (货币):$123.46d(十进制):1234e(指数):1.052033E+003- f(定点):1234.57
- g(一般): 123.456
n(数字):1,234.57p(百分比):100.00 %r(往返):123456789.12345678x(十六进制): FF
其余两个中,固定取决于区域设置的数字,而不是所使用的数字,留下通用 g 格式:
c(货币):$123.46d(十进制):1234e(指数):1.052033E+003f(定点):1234.57- g(常规):123.456
- < Strike>n(数字):1,234.57
p(百分比):100.00 %r(往返):123456789.12345678x(十六进制):FF< /strike>
我什至不能肯定地说 g 格式不会添加数字分组(例如 1,234)。
是否有一个区域设置可以按照 SQL Server 期望的方式格式化数字?有.NET格式的代码吗? java格式的代码?有Delphi格式的代码吗?有VB格式的代码吗? stdio 格式代码?
拉丁数字
It seems that SQL Server does not accept numbers formatted using any particular locale.
It also doesn't support locales that have digits other than 0-9.
For example, if the current locale is bengali, then the number 123456789 would come out as "১২৩৪৫৬৭৮৯". And that's just the digits, nevermind what the digit grouping would be.
But the same problem happens for numbers in the Invariant locale, which formats numbers as "123,456,789", which SQL Server won't accept.
Is there a culture that matches what SQL Server accepts for numeric values? Or will i have to create some custom "sql server" culture, generating rules for that culture myself from lower level formatting routines?
If i was in .NET (which i'm not), i could peruse the Standard Numeric Format strings. Of the format codes available in .NET:
- c (Currency): $123.46
- d (Decimal): 1234
- e (Exponentional): 1.052033E+003
- f (Fixed Point): 1234.57
- g (General): 123.456
- n (Number): 1,234.57
- p (Percent): 100.00 %
- r (Round Trip): 123456789.12345678
- x (Hexadecimal): FF
Only 6 accept all numeric types:
- c (Currency): $123.46
d (Decimal): 1234- e (Exponentional): 1.052033E+003
- f (Fixed Point): 1234.57
- g (General): 123.456
- n (Number): 1,234.57
- p (Percent): 100.00 %
r (Round Trip): 123456789.12345678x (Hexadecimal): FF
And of those only 2 generate string representations, in the en-US locale anyway, that would be accepted by SQL Server:
c (Currency): $123.46d (Decimal): 1234e (Exponentional): 1.052033E+003- f (Fixed Point): 1234.57
- g (General): 123.456
n (Number): 1,234.57p (Percent): 100.00 %r (Round Trip): 123456789.12345678x (Hexadecimal): FF
Of the remaining two, fixed is dependant on the locale's digits, rather than the number being used, leaving General g format:
c (Currency): $123.46d (Decimal): 1234e (Exponentional): 1.052033E+003f (Fixed Point): 1234.57- g (General): 123.456
n (Number): 1,234.57p (Percent): 100.00 %r (Round Trip): 123456789.12345678x (Hexadecimal): FF
And i can't even say for certain that the g format won't add digit groupings (e.g. 1,234).
Is there a locale that formats numbers in the way SQL Server expects? Is there a .NET format code? A java format code? A Delphi format code? A VB format code? A stdio format code?
latin-numeral-digits
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
常量的 SQL Server 规范描述了 T- 中可接受的格式SQL 表达式和批处理:
好消息是客户端应用程序不需要担心这些要求。客户端应用程序应将数值作为 @parameters 传递,而不是作为 T-SQL 文字常量传递。
The SQL Server specifications for constants are describing the acceptable formats in T-SQL expressions and batches:
The good news is that client applications don't need to worry about these requirements. Client applications should pass numeric values as @parameters, not as T-SQL literal constants.