sql - 如何在sql oracle中获取月份的名称
问题描述
完整显示日期“14-jul-15”的月份名称。
我尝试了多种方法,但我无法让它显示月份的名称。
解决方案
使用TO_CHAR
具有适当格式掩码的函数。
SQL> select to_char(sysdate, 'fm dd-Month-yyyy') result
2 from dual;
RESULT
------------------
25-March-2021
SQL>
或者,如果您只有一个 string '14-jul-15'
,则首先将其转换为有效的日期值(使用TO_DATE
),然后TO_CHAR
对其应用。
我NLS_DATE_LANGUAGE
也使用 then 参数,因为我的数据库说克罗地亚语,所以“jul”对我来说是无效月份。你可能不需要它。
SQL> with test (col) as
2 (select '14-jul-15' from dual)
3 select
4 to_char(
5 to_date(col, 'dd-mon-yy', 'nls_date_language = english'),
6 'fm dd-Month-yyyy', 'nls_date_language = english'
7 ) result
8 from test;
RESULT
------------------
14-July-2015
SQL>
推荐阅读
- python - django REST api 通用视图的 queryset 属性
- flutter - 从另一个有状态小部件调用一个有状态小部件中的方法 - Flutter
- android - 自定义通知声音,安卓奥利奥?
- postgresql - 将带有 ON CONFLICT 的 jsonb 插入到 postgres 视图中时,“属性 5 的类型错误”?
- sql - 删除 SQlite3 中的选定行
- angular - 量角器 .sendKeys() 无法使用 ngModel 处理输入
- android - OpenCV 洪水填充错误
- windows - 在 windows 上安装 matplotlib 的问题
- mysql - MySQL:构建一个视图,其列的数据依赖于另一个视图
- tfs - 防止 TFS 任务(工作项)被“解决”