使用next_day检索前一天和第二天

时间:2014-11-27 11:04:30

标签: sql oracle oracle11g

我有一个sql代码。我试图使用next_Day函数检索上一个星期一和下个星期日。我如何使查询工作?我目前正在使用oracle sql developer来运行我的查询。

这是我要显示的数据:

 FullName,       Monday         Sunday
 John Brown      31-DEC-2012    06-JAN-2013

这是我到目前为止的代码:

 SELECT First_Name, Last_Name, DOB,
 Add_Months(dob, (extract(YEAR from sysdate)- extract(YEAR from dob))*12) AS BirthDateThisYear
 FROM Customers

我尝试添加这些语句,但运行查询后出错:

  NEXT_DAY(BirthDateThisYear-8, 'MON') AS PreviousMonday
  NEXT_DAY((BirthDateThisYear-8)+6, 'MON') AS UpcomingSunday

1 个答案:

答案 0 :(得分:2)

我可以试试这个:

select First_Name || ' ' || Last_Name as FullName,
       NEXT_DAY(BirthDateThisYear-8, 'Monday') AS PreviousMonday,
       NEXT_DAY(BirthDateThisYear-1, 'Sunday') AS UpcomingSunday
from       
(SELECT First_Name, Last_Name, DOB,
 Add_Months(dob, (extract(YEAR from sysdate)- extract(YEAR from dob))*12) AS BirthDateThisYear
 FROM Customers)