Search
 
SCRIPT & CODE EXAMPLE
 

SQL

ORACLE RANGE DATE USING CONNECT BY PER WEEK,MONTHS,ETC

 SELECT DISTINCT  TO_CHAR(z.START_DATE,'MMRRRR') MM  
            ,TO_CHAR(z.START_DATE,'DD-MON-RRRR') START_DATE 
            ,TO_CHAR(z.END_DATE,'DD-MON-RRRR') END_DATE
    FROM  (WITH C_RANGE AS   
    (SELECT TRUNC(:STARTDATE) + LEVEL - 1 FECHA_INI
                ,ADD_MONTHS(TRUNC(:STARTDATE),LEVEL) - 1 FECHA_FIN
        FROM DUAL 
    CONNECT BY LEVEL <= (TRUNC(:ENDDATE) - TRUNC(:STARTDATE)))
    SELECT DISTINCT
               (CASE WHEN L.FECHA_INI = TRUNC(:STARTDATE) THEN TRUNC(:STARTDATE) ELSE ADD_MONTHS(L.FECHA_FIN,-1) +1 END) START_DATE
              ,(CASE WHEN L.FECHA_FIN +1 >= TRUNC(:ENDDATE)  THEN  TRUNC(:ENDDATE) ELSE L.FECHA_FIN  END)  END_DATE  
      FROM  C_RANGE L
     WHERE ADD_MONTHS(L.FECHA_FIN,-1) <= TRUNC(:ENDDATE)
         AND  TRUNC(:ENDDATE) >= TRUNC(:STARTDATE)) z
   ORDER BY MM ASC ;
       
Comment

ORACLE RANGE DATE USING CONNECT BY PER WEEK,MONTHS,ETC

 SELECT DISTINCT  TO_CHAR(z.START_DATE,'MMRRRR') MM  
            ,TO_CHAR(z.START_DATE,'DD-MON-RRRR') START_DATE 
            ,TO_CHAR(z.END_DATE,'DD-MON-RRRR') END_DATE
    FROM  (WITH C_RANGE AS   
    (SELECT TRUNC(:STARTDATE) + LEVEL - 1 FECHA_INI
                ,ADD_MONTHS(TRUNC(:STARTDATE),LEVEL) - 1 FECHA_FIN
        FROM DUAL 
    CONNECT BY LEVEL <= (TRUNC(:ENDDATE) - TRUNC(:STARTDATE)))
    SELECT DISTINCT
               (CASE WHEN L.FECHA_INI = TRUNC(:STARTDATE) THEN TRUNC(:STARTDATE) ELSE ADD_MONTHS(L.FECHA_FIN,-1) +1 END) START_DATE
              ,(CASE WHEN L.FECHA_FIN +1 >= TRUNC(:ENDDATE)  THEN  TRUNC(:ENDDATE) ELSE L.FECHA_FIN  END)  END_DATE  
      FROM  C_RANGE L
     WHERE ADD_MONTHS(L.FECHA_FIN,-1) <= TRUNC(:ENDDATE)
         AND  TRUNC(:ENDDATE) >= TRUNC(:STARTDATE)) z
   ORDER BY MM ASC ;
       
Comment

ORACLE RANGE DATE USING CONNECT BY PER WEEK,MONTHS,ETC

 SELECT DISTINCT  TO_CHAR(z.START_DATE,'MMRRRR') MM  
            ,TO_CHAR(z.START_DATE,'DD-MON-RRRR') START_DATE 
            ,TO_CHAR(z.END_DATE,'DD-MON-RRRR') END_DATE
    FROM  (WITH C_RANGE AS   
    (SELECT TRUNC(:STARTDATE) + LEVEL - 1 FECHA_INI
                ,ADD_MONTHS(TRUNC(:STARTDATE),LEVEL) - 1 FECHA_FIN
        FROM DUAL 
    CONNECT BY LEVEL <= (TRUNC(:ENDDATE) - TRUNC(:STARTDATE)))
    SELECT DISTINCT
               (CASE WHEN L.FECHA_INI = TRUNC(:STARTDATE) THEN TRUNC(:STARTDATE) ELSE ADD_MONTHS(L.FECHA_FIN,-1) +1 END) START_DATE
              ,(CASE WHEN L.FECHA_FIN +1 >= TRUNC(:ENDDATE)  THEN  TRUNC(:ENDDATE) ELSE L.FECHA_FIN  END)  END_DATE  
      FROM  C_RANGE L
     WHERE ADD_MONTHS(L.FECHA_FIN,-1) <= TRUNC(:ENDDATE)
         AND  TRUNC(:ENDDATE) >= TRUNC(:STARTDATE)) z
   ORDER BY MM ASC ;
       
Comment

ORACLE RANGE DATE USING CONNECT BY PER WEEK,MONTHS,ETC

 SELECT DISTINCT  TO_CHAR(z.START_DATE,'MMRRRR') MM  
            ,TO_CHAR(z.START_DATE,'DD-MON-RRRR') START_DATE 
            ,TO_CHAR(z.END_DATE,'DD-MON-RRRR') END_DATE
    FROM  (WITH C_RANGE AS   
    (SELECT TRUNC(:STARTDATE) + LEVEL - 1 FECHA_INI
                ,ADD_MONTHS(TRUNC(:STARTDATE),LEVEL) - 1 FECHA_FIN
        FROM DUAL 
    CONNECT BY LEVEL <= (TRUNC(:ENDDATE) - TRUNC(:STARTDATE)))
    SELECT DISTINCT
               (CASE WHEN L.FECHA_INI = TRUNC(:STARTDATE) THEN TRUNC(:STARTDATE) ELSE ADD_MONTHS(L.FECHA_FIN,-1) +1 END) START_DATE
              ,(CASE WHEN L.FECHA_FIN +1 >= TRUNC(:ENDDATE)  THEN  TRUNC(:ENDDATE) ELSE L.FECHA_FIN  END)  END_DATE  
      FROM  C_RANGE L
     WHERE ADD_MONTHS(L.FECHA_FIN,-1) <= TRUNC(:ENDDATE)
         AND  TRUNC(:ENDDATE) >= TRUNC(:STARTDATE)) z
   ORDER BY MM ASC ;
       
Comment

ORACLE RANGE DATE USING CONNECT BY PER WEEK,MONTHS,ETC

 SELECT DISTINCT  TO_CHAR(z.START_DATE,'MMRRRR') MM  
            ,TO_CHAR(z.START_DATE,'DD-MON-RRRR') START_DATE 
            ,TO_CHAR(z.END_DATE,'DD-MON-RRRR') END_DATE
    FROM  (WITH C_RANGE AS   
    (SELECT TRUNC(:STARTDATE) + LEVEL - 1 FECHA_INI
                ,ADD_MONTHS(TRUNC(:STARTDATE),LEVEL) - 1 FECHA_FIN
        FROM DUAL 
    CONNECT BY LEVEL <= (TRUNC(:ENDDATE) - TRUNC(:STARTDATE)))
    SELECT DISTINCT
               (CASE WHEN L.FECHA_INI = TRUNC(:STARTDATE) THEN TRUNC(:STARTDATE) ELSE ADD_MONTHS(L.FECHA_FIN,-1) +1 END) START_DATE
              ,(CASE WHEN L.FECHA_FIN +1 >= TRUNC(:ENDDATE)  THEN  TRUNC(:ENDDATE) ELSE L.FECHA_FIN  END)  END_DATE  
      FROM  C_RANGE L
     WHERE ADD_MONTHS(L.FECHA_FIN,-1) <= TRUNC(:ENDDATE)
         AND  TRUNC(:ENDDATE) >= TRUNC(:STARTDATE)) z
   ORDER BY MM ASC ;
       
Comment

ORACLE RANGE DATE USING CONNECT BY PER WEEK,MONTHS,ETC

 SELECT DISTINCT  TO_CHAR(z.START_DATE,'MMRRRR') MM  
            ,TO_CHAR(z.START_DATE,'DD-MON-RRRR') START_DATE 
            ,TO_CHAR(z.END_DATE,'DD-MON-RRRR') END_DATE
    FROM  (WITH C_RANGE AS   
    (SELECT TRUNC(:STARTDATE) + LEVEL - 1 FECHA_INI
                ,ADD_MONTHS(TRUNC(:STARTDATE),LEVEL) - 1 FECHA_FIN
        FROM DUAL 
    CONNECT BY LEVEL <= (TRUNC(:ENDDATE) - TRUNC(:STARTDATE)))
    SELECT DISTINCT
               (CASE WHEN L.FECHA_INI = TRUNC(:STARTDATE) THEN TRUNC(:STARTDATE) ELSE ADD_MONTHS(L.FECHA_FIN,-1) +1 END) START_DATE
              ,(CASE WHEN L.FECHA_FIN +1 >= TRUNC(:ENDDATE)  THEN  TRUNC(:ENDDATE) ELSE L.FECHA_FIN  END)  END_DATE  
      FROM  C_RANGE L
     WHERE ADD_MONTHS(L.FECHA_FIN,-1) <= TRUNC(:ENDDATE)
         AND  TRUNC(:ENDDATE) >= TRUNC(:STARTDATE)) z
   ORDER BY MM ASC ;
       
Comment

ORACLE RANGE DATE USING CONNECT BY PER WEEK,MONTHS,ETC

 SELECT DISTINCT  TO_CHAR(z.START_DATE,'MMRRRR') MM  
            ,TO_CHAR(z.START_DATE,'DD-MON-RRRR') START_DATE 
            ,TO_CHAR(z.END_DATE,'DD-MON-RRRR') END_DATE
    FROM  (WITH C_RANGE AS   
    (SELECT TRUNC(:STARTDATE) + LEVEL - 1 FECHA_INI
                ,ADD_MONTHS(TRUNC(:STARTDATE),LEVEL) - 1 FECHA_FIN
        FROM DUAL 
    CONNECT BY LEVEL <= (TRUNC(:ENDDATE) - TRUNC(:STARTDATE)))
    SELECT DISTINCT
               (CASE WHEN L.FECHA_INI = TRUNC(:STARTDATE) THEN TRUNC(:STARTDATE) ELSE ADD_MONTHS(L.FECHA_FIN,-1) +1 END) START_DATE
              ,(CASE WHEN L.FECHA_FIN +1 >= TRUNC(:ENDDATE)  THEN  TRUNC(:ENDDATE) ELSE L.FECHA_FIN  END)  END_DATE  
      FROM  C_RANGE L
     WHERE ADD_MONTHS(L.FECHA_FIN,-1) <= TRUNC(:ENDDATE)
         AND  TRUNC(:ENDDATE) >= TRUNC(:STARTDATE)) z
   ORDER BY MM ASC ;
       
Comment

ORACLE RANGE DATE USING CONNECT BY PER WEEK,MONTHS,ETC

 SELECT DISTINCT  TO_CHAR(z.START_DATE,'MMRRRR') MM  
            ,TO_CHAR(z.START_DATE,'DD-MON-RRRR') START_DATE 
            ,TO_CHAR(z.END_DATE,'DD-MON-RRRR') END_DATE
    FROM  (WITH C_RANGE AS   
    (SELECT TRUNC(:STARTDATE) + LEVEL - 1 FECHA_INI
                ,ADD_MONTHS(TRUNC(:STARTDATE),LEVEL) - 1 FECHA_FIN
        FROM DUAL 
    CONNECT BY LEVEL <= (TRUNC(:ENDDATE) - TRUNC(:STARTDATE)))
    SELECT DISTINCT
               (CASE WHEN L.FECHA_INI = TRUNC(:STARTDATE) THEN TRUNC(:STARTDATE) ELSE ADD_MONTHS(L.FECHA_FIN,-1) +1 END) START_DATE
              ,(CASE WHEN L.FECHA_FIN +1 >= TRUNC(:ENDDATE)  THEN  TRUNC(:ENDDATE) ELSE L.FECHA_FIN  END)  END_DATE  
      FROM  C_RANGE L
     WHERE ADD_MONTHS(L.FECHA_FIN,-1) <= TRUNC(:ENDDATE)
         AND  TRUNC(:ENDDATE) >= TRUNC(:STARTDATE)) z
   ORDER BY MM ASC ;
       
Comment

ORACLE RANGE DATE USING CONNECT BY PER WEEK,MONTHS,ETC

 SELECT DISTINCT  TO_CHAR(z.START_DATE,'MMRRRR') MM  
            ,TO_CHAR(z.START_DATE,'DD-MON-RRRR') START_DATE 
            ,TO_CHAR(z.END_DATE,'DD-MON-RRRR') END_DATE
    FROM  (WITH C_RANGE AS   
    (SELECT TRUNC(:STARTDATE) + LEVEL - 1 FECHA_INI
                ,ADD_MONTHS(TRUNC(:STARTDATE),LEVEL) - 1 FECHA_FIN
        FROM DUAL 
    CONNECT BY LEVEL <= (TRUNC(:ENDDATE) - TRUNC(:STARTDATE)))
    SELECT DISTINCT
               (CASE WHEN L.FECHA_INI = TRUNC(:STARTDATE) THEN TRUNC(:STARTDATE) ELSE ADD_MONTHS(L.FECHA_FIN,-1) +1 END) START_DATE
              ,(CASE WHEN L.FECHA_FIN +1 >= TRUNC(:ENDDATE)  THEN  TRUNC(:ENDDATE) ELSE L.FECHA_FIN  END)  END_DATE  
      FROM  C_RANGE L
     WHERE ADD_MONTHS(L.FECHA_FIN,-1) <= TRUNC(:ENDDATE)
         AND  TRUNC(:ENDDATE) >= TRUNC(:STARTDATE)) z
   ORDER BY MM ASC ;
       
Comment

ORACLE RANGE DATE USING CONNECT BY PER WEEK,MONTHS,ETC

 SELECT DISTINCT  TO_CHAR(z.START_DATE,'MMRRRR') MM  
            ,TO_CHAR(z.START_DATE,'DD-MON-RRRR') START_DATE 
            ,TO_CHAR(z.END_DATE,'DD-MON-RRRR') END_DATE
    FROM  (WITH C_RANGE AS   
    (SELECT TRUNC(:STARTDATE) + LEVEL - 1 FECHA_INI
                ,ADD_MONTHS(TRUNC(:STARTDATE),LEVEL) - 1 FECHA_FIN
        FROM DUAL 
    CONNECT BY LEVEL <= (TRUNC(:ENDDATE) - TRUNC(:STARTDATE)))
    SELECT DISTINCT
               (CASE WHEN L.FECHA_INI = TRUNC(:STARTDATE) THEN TRUNC(:STARTDATE) ELSE ADD_MONTHS(L.FECHA_FIN,-1) +1 END) START_DATE
              ,(CASE WHEN L.FECHA_FIN +1 >= TRUNC(:ENDDATE)  THEN  TRUNC(:ENDDATE) ELSE L.FECHA_FIN  END)  END_DATE  
      FROM  C_RANGE L
     WHERE ADD_MONTHS(L.FECHA_FIN,-1) <= TRUNC(:ENDDATE)
         AND  TRUNC(:ENDDATE) >= TRUNC(:STARTDATE)) z
   ORDER BY MM ASC ;
       
Comment

ORACLE RANGE DATE USING CONNECT BY PER WEEK,MONTHS,ETC

 SELECT DISTINCT  TO_CHAR(z.START_DATE,'MMRRRR') MM  
            ,TO_CHAR(z.START_DATE,'DD-MON-RRRR') START_DATE 
            ,TO_CHAR(z.END_DATE,'DD-MON-RRRR') END_DATE
    FROM  (WITH C_RANGE AS   
    (SELECT TRUNC(:STARTDATE) + LEVEL - 1 FECHA_INI
                ,ADD_MONTHS(TRUNC(:STARTDATE),LEVEL) - 1 FECHA_FIN
        FROM DUAL 
    CONNECT BY LEVEL <= (TRUNC(:ENDDATE) - TRUNC(:STARTDATE)))
    SELECT DISTINCT
               (CASE WHEN L.FECHA_INI = TRUNC(:STARTDATE) THEN TRUNC(:STARTDATE) ELSE ADD_MONTHS(L.FECHA_FIN,-1) +1 END) START_DATE
              ,(CASE WHEN L.FECHA_FIN +1 >= TRUNC(:ENDDATE)  THEN  TRUNC(:ENDDATE) ELSE L.FECHA_FIN  END)  END_DATE  
      FROM  C_RANGE L
     WHERE ADD_MONTHS(L.FECHA_FIN,-1) <= TRUNC(:ENDDATE)
         AND  TRUNC(:ENDDATE) >= TRUNC(:STARTDATE)) z
   ORDER BY MM ASC ;
       
Comment

PREVIOUS NEXT
Code Example
Sql :: today midnight SQL 
Sql :: Update csvs para sql 
Sql :: pl sql turn off variable substitution 
Sql :: mamp find mysql port number mac 
Sql :: ORA-01400 
Sql :: view psql output in horizontal scrolling 
Sql :: how to connect aws postgresql database using pgadmin 4 
Sql :: create sql database 
Sql :: reset sql primary key 
Sql :: psql check table fields 
Sql :: sqlserver now 
Sql :: like date sql server not working 
Sql :: salesforce cpq apply immediately 
Sql :: updating mysql 
Sql :: reading from right to left from string find first special characters in sql 
Sql :: select A from B join C as D using E where F match G order by H desc 
Sql :: oracle last user logon 
Sql :: sql 2year 
Sql :: mysql readable output 
Sql :: mysql update set 
Sql :: select all same column value in sql 
Sql :: Get the User Name and Domain Name from an Email Address 
Sql :: mysql extract days 
Sql :: can pandas fetch data from sql 
Sql :: sql statement show all emails with dome 
Csharp :: c# print hello world 
Csharp :: convert to base64 c# 
Csharp :: simple reset transform.rotation c# 
Csharp :: unity check if number is multiple of x 
Csharp :: json ignore property c# 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =