仅在 Oracle 中检索周末数据行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3836413/
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
Retrieving Weekend Data Rows Only in Oracle
提问by tonyf
How to query rows in a table where the created_date column value in the table falls on a weekend date ONLY, i.e. Saturday/Sunday using Oracle SQL..
如何查询表中的行,其中表中的 created_date 列值仅落在周末日期,即使用 Oracle SQL 的星期六/星期日。
Thanks
谢谢
回答by Joe Stefanelli
SELECT *
FROM YourTable
WHERE TO_CHAR (created_date, 'DY') IN ('SAT', 'SUN')
回答by andr
@Joe Stefanelli This is not absolutely correct, since the abbreviations returned are NLS-sensitive: the language in which month and day names and abbreviations are returned use the default date language for your session.
@Joe Stefanelli 这不是绝对正确的,因为返回的缩写是 NLS 敏感的:返回月份和日期名称和缩写的语言使用会话的默认日期语言。
If you compare to-char result to literals in English (IN ('SAT', 'SUN')
), it's better to precisely indicate it with nlsparams
parameter, so the resulting query will look like this:
如果将 to-char 结果与英文 ( IN ('SAT', 'SUN')
) 中的文字进行比较,最好使用nlsparams
参数精确指示它,因此结果查询将如下所示:
SELECT *
FROM YourTable
WHERE TO_CHAR (created_date, 'DY', 'NLS_DATE_LANGUAGE=AMERICAN') IN ('SAT', 'SUN')
回答by zerkms
WHERE to_char(created_date, 'D') >= 6
To improve the performance you could create function based index to_char(created_date, 'D')
为了提高性能,您可以创建基于函数的索引 to_char(created_date, 'D')