好久不见了。
:)13:00:11 SQL> select next_day(sysdate,7)-7 from dual;NEXT_DAY(SYSDATE,7)
-------------------
2004-10-16 13:00:22已用时间:  00: 00: 00.16
13:00:22 SQL>

解决方案 »

  1.   

    同意楼上的
    SQL> select next_day(sysdate,7)-7 from dual;NEXT_DAY(S
    ----------
    16-10月-04
      

  2.   

    select next_day(sysdate,7)-7 from dual;
    好像有问题咧如果当天是周日.....
      

  3.   

    SELECT SYSDATE - TO_NUMBER(TO_CHAR(SYSDATE,'D')) FROM DUAL
      

  4.   

    select next_day(sysdate-1,7)-7 from dual;
      

  5.   

    确实有问题
    :(
    15:04:41 SQL> select sysdate,
    15:05:12   2  sysdate-decode(to_char(sysdate,'d'),1,8,to_char(sysdate,'d')) col
    15:05:20   3  from dual;SYSDATE             COL
    ------------------- -------------------
    2004-10-17 15:05:23 2004-10-09 15:05:23已用时间:  00: 00: 00.31
    15:05:23 SQL> /SYSDATE             COL
    ------------------- -------------------
    2004-10-20 15:05:36 2004-10-16 15:05:36已用时间:  00: 00: 00.16
    15:05:36 SQL>
      

  6.   

    15:25:19 SQL> select a,next_day(a-1,7)-7 from t1;A                                        NEXT_DAY(A-1,7)-7
    ---------------------------------------- -------------------
    2004-10-01 00:00:00                      2004-09-25 00:00:00
    2004-10-02 00:00:00                      2004-09-25 00:00:00
    2004-10-03 00:00:00                      2004-10-02 00:00:00
    2004-10-04 00:00:00                      2004-10-02 00:00:00
    2004-10-05 00:00:00                      2004-10-02 00:00:00
    2004-10-06 00:00:00                      2004-10-02 00:00:00
    2004-10-07 00:00:00                      2004-10-02 00:00:00
    2004-10-08 00:00:00                      2004-10-02 00:00:00
    2004-10-09 00:00:00                      2004-10-02 00:00:00
    2004-10-10 00:00:00                      2004-10-09 00:00:00
    2004-10-11 00:00:00                      2004-10-09 00:00:00
    2004-10-12 00:00:00                      2004-10-09 00:00:00
    2004-10-13 00:00:00                      2004-10-09 00:00:00
    2004-10-14 00:00:00                      2004-10-09 00:00:00
    2004-10-15 00:00:00                      2004-10-09 00:00:00
    2004-10-16 00:00:00                      2004-10-09 00:00:00
    2004-10-17 00:00:00                      2004-10-16 00:00:00
    2004-10-18 00:00:00                      2004-10-16 00:00:00已选择18行。
      

  7.   

    select trunc(sysdate,'d')-1 from dual;
      

  8.   

    select trunc(sysdate,'d')-1 from dual;
      

  9.   

    楼上教了我一个很牛的方法呀,我查了资料,学会了这个函数的用法,谢谢了
    我把资料贴出来The TRUNC function truncates a date as specified by a format mask. The specification for TRUNC is:FUNCTION TRUNC (date_in IN DATE [, format_mask VARCHAR2]) RETURN DATEThe TRUNC date function is similar to the numeric FLOOR function. Generally speaking, it ROUNDs down to the beginning of the minute, hour, day, month, quarter, year, or century, as specified by the format mask.TRUNC offers the easiest way to retrieve the first day of the month or first day of the year. It is also useful when you want to ignore the time component of dates. This is often the case when you perform comparisons with dates, such as the following:IF request_date BETWEEN start_date AND end_date
    THEN
    ...The date component of date_entered and start_date might be the same, but if your application does not specify a time component for each of its dates, the comparison might fail. If, for example, the user enters a request_date and the screen does not include a time component, the time for request_date will be midnight or 12:00 a.m. of that day. If start_date was set from SYSDATE, however, its time component will reflect the time at which the assignment was made. Since 12:00 a.m. comes before any other time of the day, a comparison that looks to the naked eye like a match might well fail.If you are not sure about the time components of your date fields and variables and want to make sure that your operations on dates disregard the time component, TRUNCate them:IF TRUNC (request_date) BETWEEN TRUNC (start_date) AND TRUNC (end_date)
    THEN
    ...TRUNC levels the playing field with regard to the time component: all dates now have the same time of midnight (12:00 a.m.). The time will never be a reason for a comparison to fail.Syntax>哪TRUNC哪(date穆哪哪哪穆?哪><
                    滥, fmt馁Table 1: Format Mask elements for ROUND and TRUNCFormat Mask Truncates toCC or SSC Century
    SYYY, YYYY, YEAR, SYEAR, YYY, YY, or Y Year (rounds up to next year starting on July 1)
    IYYY, IYY, IY, or I Standard ISO year
    Q Quarter (rounds up on the sixteenth day of the second month of the quarter)
    MONTH, MON, MM, or RM Month (rounds up on the sixteenth day, which is not necessarily the same as the middle of the month)
    WW Same day of the week as the first day of the year
    IW Same day of the week as the first day of the ISO year
    W Same day of the week as the first day of the month
    DDD, DD, or J Day
    DAY, DY, or D Starting day of the week
    HH, HH12, HH24 Hour
    MI MinuteThe following example shows TRUNC being used to truncate a datetime value to the beginning of the year and the beginning of the month respectively: DECLARE
       date_in DATE := TO_DATE('24-Feb-2002 05:36:00 PM'
                        ,'DD-MON-YYYY HH:MI:SS AM');
       trunc_to_year DATE;
       trunc_to_month DATE;BEGIN
       trunc_to_year := TRUNC(date_in,'YYYY');
       trunc_to_month := TRUNC(date_in,'MM');   DBMS_OUTPUT.PUT_LINE(
          TO_CHAR(trunc_to_year, 'DD-MON-YYYY HH:MI:SS AM'));
       DBMS_OUTPUT.PUT_LINE(
          TO_CHAR(trunc_to_month,'DD-MON-YYYY HH:MI:SS AM'));
    END;01-JAN-2002 12:00:00 AM
    01-FEB-2002 12:00:00 AMTRUNC has enabled you to instantly jump back to the first of the year and the first of the month. A common use for both the TRUNC and ROUND functions is to set the time-of-day component of a DATE value to midnight (12:00:00 AM). By convention, midnight is the value used when you care only about the date itself, and not the time. The difference between the two functions lies in whether they disregard the time component entirely or use it to round the resulting DATE value up or down. Look closely at the different results from the two functions in the following example:DECLARE
       date_in DATE := TO_DATE('24-Feb-2002 05:16:00 PM'
                        ,'DD-MON-YYYY HH:MI:SS AM');
       date_rounded DATE;
       date_truncated DATE;
    BEGIN
       date_rounded := ROUND(date_in);
       date_truncated := TRUNC(date_in);   DBMS_OUTPUT.PUT_LINE(
          TO_CHAR(date_rounded, 'DD-MON-YYYY HH:MI:SS AM'));
       DBMS_OUTPUT.PUT_LINE(
          TO_CHAR(date_truncated,'DD-MON-YYYY HH:MI:SS AM'));
    END;25-FEB-2002 12:00:00 AM
    24-FEB-2002 12:00:00 AMLook closely at the value for date_rounded. Do you see that the day has been advanced from 24-Feb to 25-Feb? That's because the time, 5:16 PM, was closer to midnight of the following day (the 25th) than it was to the 24th. In contrast, the value for date_truncated is still the 24th. The TRUNC function simply eliminated the time of day information. The ROUND function respected the time of day, eliminated it, but also advanced the date by one day. Had the time of day been 5:16 AM, the rounding would have been downward, and both functions would have returned the same results. Try it. Understand that when using TRUNC or ROUND that unwanted datetime components do not "go away". All DATE variables specify values for year, month, day, hour, minute, and second. When "5:36 PM" is rounded to "6:00 PM", the minutes component is still there; it's just been set to zero.