Oracle11g 甲骨文:本周

Oracle11g 甲骨文:本周,oracle11g,Oracle11g,我有下面的SQL Server语法,我正在尝试将语法转换为Oracle。我正在尝试捕获一周的数据,例如:1/16-1/22 例如: FullDate Week of (PreferredFormat): 1/1/2016 12/27-01/02 1/2/2016 12/27-01/02 1/3/2016 01/03-01/09 下面是我的SQL Server语法: CONVERT(NVARCHAR(20), DAT

我有下面的SQL Server语法,我正在尝试将语法转换为Oracle。我正在尝试捕获一周的数据,例如:1/16-1/22

例如:

FullDate       Week of (PreferredFormat):
  1/1/2016          12/27-01/02
  1/2/2016          12/27-01/02 
  1/3/2016          01/03-01/09
下面是我的SQL Server语法:

CONVERT(NVARCHAR(20), DATEADD(dd, -(DATEPART(dw, fulldate)-1), fulldate), 110) + '-' + 
 CONVERT(NVARCHAR(20), DATEADD(dd, 7-    (DATEPART(dw, fulldate)), fulldate), 110) AS 'WeekOf'
-----------------------------------------------
 ,CONVERT(NVARCHAR(05), DATEADD(dd, -(DATEPART(dw, fulldate)-1), fulldate), 10) + '-' + 
 CONVERT(NVARCHAR(05), DATEADD(dd, 7- (DATEPART(dw, fulldate)), fulldate), 10) AS 'WeekOf_2'
-----------------------------------------------------
  ,REPLACE(replace(left(CONVERT(NVARCHAR(05), DATEADD(dd, -(DATEPART(dw, fulldate)-1), fulldate), 10),5),'0',''),'-','/') + '-' +
  REPLACE(replace(left(CONVERT(NVARCHAR(05), DATEADD(dd, 7- (DATEPART(dw, fulldate)), fulldate), 10),5),'0',''),'-','/') AS 'WeekOf_3'

你的一周似乎从星期天一直持续到星期六。下面的解决方案使用
next_day()
函数;请注意,它的使用取决于会话的日期语言(不幸的是,这不是函数的可选参数)。另外,当您从另一个DB产品迁移时,如果您将日期放在数据类型DATE的列中会更好;我假设输入是
date
数据类型中的日期,而不是
nvarchar

with
     inputs ( dt ) as (
       select to_date('1/1/2016', 'mm/dd/yyyy') from dual union all
       select to_date('1/2/2016', 'mm/dd/yyyy') from dual union all
       select to_date('1/3/2016', 'mm/dd/yyyy') from dual
     )
-- end of test data (not part of the solution!); SQL query begins below this line
select dt, 
       to_char(next_day(dt, 'Sunday') - 7, 'mm/dd-') || 
                        to_char(next_day(dt, 'Sunday') - 1, 'mm/dd') as week_of
from   inputs
;

DT         WEEK_OF
---------- -----------
01/01/2016 12/27-01/02
01/02/2016 12/27-01/02
01/03/2016 01/03-01/09

3 rows selected.

to_char('iw',fulldate)
:你能详细说明一下吗?你所说的“试图捕捉数据周”是什么意思?我有日期:2016年1月1日,我想捕捉一周的开始和结束。就像上面提到的SQL Server一样*编辑问题