SQL 语言相关转换(数字到月份名称)
我想将数字转换为月份名称,具体取决于语言。例如:
- 印度尼西亚语中 1 = 一月
- 中文中 1 = 一月。
- 1 = 意大利语中的gennaio。
怎么做呢?我的目的是转换为我的国家语言,即 BAHASA MALAYSIA(JANUARI、FEBRUARI、MAC ... disember)。
I would like to convert number to month name, language dependent. For example:
- 1 = januari in indonesia language
- 1 = 一月 in chinese language.
- 1 = gennaio in italian language.
How to do that? My purpose is to convert to my country language which is BAHASA MALAYSIA (JANUARI , FEBRUARI , MAC ... disember).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无法以这种方式在 SQL Server 中进行本地化:每个查询可以使用一种语言
DATENAME 使用此语言设置
因此,除非您需要大量查找表(每种语言一个),否则请在客户端上执行此操作。
DATENAME 对于某些语言来说也是不可靠的。请参阅 DATENAME(MONTH,GETADATE ()) 返回月份的数值为“09”
SQL Server 2012 通过 FORMAT 添加了一些区域性设置,但您需要必须将其传递到 SQL Server。就像我说的,在客户端中执行此操作。
编辑:
SQL Server 2005 中不通过 SET LANGUAGE 支持印度尼西亚语。
因此,对于这种一种语言,您需要一个 CASE
否则,请设置语言或在客户端中执行
You can't localise in SQL Server in this fashion: you can use one language per query
This language setting is what DATENAME uses
So unless you want a huge number of lookup tables (one per language), then do this on the client.
DATENAME is also unreliable for some languages. See DATENAME(MONTH,GETADATE()) is returning numeric value of the month as '09'
SQL Server 2012 adds some culture setting via FORMAT but you'd have to pass this into SQL Server. Like I said, do this in the client.
Edit:
Indonesian isn't supported in SQL Server 2005 via SET LANGUAGE.
So, for this one language you'd need a CASE
Otherwise, SET LANGUAGE or do it in the client
在我看来,如果可以避免的话,本地化不应该在服务器/业务逻辑级别上完成。因此,我将存储过程中的日期/月份作为
DATETIME
或INT
返回,并在处理数据的客户端中本地化此信息。In my opinion, localization shouldn't be done on server/business logic level if you can avoid it. Therefore, I would return the date/month in the stored procedure as a
DATETIME
orINT
and localize this information in the client which handles the data.我不知道如何为您的数据库类型正确编写它。主要思想是:
并且至少在Oracle中可以不用存储过程来编写
I don't know how to write it correctly for your kind of database. The main idea is:
And at least in Oracle it can be written without stored procedures