如何格式化日期列以获取 Oracle SQL 中的日期名称?

How to format date column to get the day name in Oracle SQL?

我有一个 oracle 数据库,它有两列,所以我想根据数据库中的给定日期显示日期 ex:(SUNDAY, MONDAY...)。

Table 姓名:TBL_HOLIDAY_MASTER:

     Holiday_date     Description
***********************************
    22-NOV-15       Weekly Holiday
    23-NOV-15       Working Day
    24-NOV-15       Working Day
    29-NOV-15       Weekly Holiday
    30-NOV-15       Working Day
    21-MAY-17       Weekly Holiday
    18-AUG-19       Weekly Holiday

我想要输出像:-

    Holiday_date    Description
*************************************
    SUNDAY          Weekly Holiday
    MONDAY          Working Day
    TUESDAY         Working Day
    SUNDAY          Weekly Holiday
    MONDAY          Working Day
    SUNDAY          Weekly Holiday
    SUNDAY          Weekly Holiday

您可以使用带有 DAY 参数的 TO_CHAR 函数来实现此目的,在您的情况下它将是:

SELECT TO_CHAR(Holiday_date,'DAY') as Holiday_date, Description 
FROM TBL_HOLIDAY_MASTER;

您需要使用 TO_CHARFMDAY 格式来获取日期名称。 FM 需要删除 尾随空格

TO_CHAR(date_column, 'FMDAY', 'NLS_DATE_LANGUAGE=ENGLISH') 

例如,

SQL> SELECT TO_CHAR(SYSDATE + LEVEL -1, 'FMDAY', 'NLS_DATE_LANGUAGE=ENGLISH') "DAYS"
  2  FROM DUAL
  3    CONNECT BY level <= 7;

DAYS
---------
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
SUNDAY

7 rows selected.