How to get a year back dynamically in Oracle?

Hello experts,

I try to create partitions on a table and would go back up to the year last to create partitions. I am currently hardcode values. I want to configure it dynamically based on SYSDATE. Someone here could help me please?

CREATE TABLE PRDT_SALES 
   (SALES_ID NUMBER NOT NULL ENABLE, 
   PRDT_NM VARCHAR2(50 CHAR) NOT NULL ENABLE, 
   SALE_START TIMESTAMP (6), 
   SALE_END TIMESTAMP (6), 
   PRDT_TYPE VARCHAR2(50 CHAR), 
   PRDT_NM VARCHAR2(50 CHAR), 
   PRDT_CODE VARCHAR2(50 CHAR), 
   PRDT_DESC VARCHAR2(50 CHAR), 
   SALE_DT DATE NOT NULL ENABLE, 
   SALE_UPDT_TS TIMESTAMP (6) DEFAULT SYSTIMESTAMP NOT NULL ENABLE
   )
PARTITION BY RANGE (SALE_DT)
 (PARTITION P20131001 VALUES LESS THAN (TO_DATE('2013-10-02 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) );

Later, I am running this script.

DECLARE
   c_start_dt   DATE := TO_DATE ('11-NOV-2013') ;
   c_end_dt     DATE := TO_DATE ('11-NOV-2014');
BEGIN
   FOR dt_rec IN (SELECT 'P' || TO_CHAR (dt, 'YYYYMMDD') AS part_nm,
                         dt + 1 AS part_dt
                    FROM (SELECT c_start_dt - 1 + ROWNUM AS dt
                            FROM all_objects
                           WHERE c_start_dt - 1 + ROWNUM <= c_end_dt
                         )
                   ORDER BY dt
                 )
   LOOP
       EXECUTE IMMEDIATE 'ALTER TABLE prdt_sales' ||
                         ' ADD PARTITION ' || dt_rec.part_nm ||
                    ' VALUES LESS THAN (TO_DATE(' || '''' || TO_CHAR (dt_rec.part_dt, 'DD-MON-YYYY') || '''' || ',' || '''' || 'DD-MON-YYYY' || '''' || '))';
   END LOOP;
END;
/

I would like to know how to make the c_start_dt and dynamic c_end_dt based on SYSDATE.

Thank you

Julaayi

Thank you. This helped.

Just to clarify, we need to declare it as date.

c_start_dt DATE: = trunc ((sysdate-12) add_months);

c_end_dt DATE: = trunc (sysdate);

Tags: Database

Similar Questions

  • Anyone know how to get your money back?  My CC application does not start and I have tried the suggested workaround solutions listed above and they have not worked for me.  The amount of problems listed here in the forum, I have to ask the product is real

    Anyone know how to get your money back?  My CC application does not start and I have tried the suggested workaround solutions listed above and they have not worked for me.  I'm new to the CC Apps but use the versions installed for years.  The amount of questions listed here in this forum, I have to ask the product is really stable?

    Thank you.  I've deleted and reinstalled.  Seems to have solved the problem.

  • I was charged for an application that was not mean to buy how I get my money back?

    I was charged for an application that was not mean to buy how I get my money back?

    Purchases are considered final, but you can try the page 'report a problem' to contact iTunes Support and see if they will refund or credit you: http://reportaproblem.apple.com

    Or you can try to contact iTunes Support via: https://support.apple.com/contact or https://www.apple.com/emea/support/itunes/contact.html

  • Someone has created a website for my business before I joined 5 weeks ago. We do not have a lot of information about how they did it! I know it's good Muse - any ideas on how to get into the back-office to do this editing?

    Someone has created a website for my business before I joined 5 weeks ago. We do not have a lot of information about how they did it! I know it's good Muse - any ideas on how to get into the back-office to do this editing?

    You would need to Muse and the original file of Muse. There is no 'back-office' on Muse like WordPress or Joomla sites! If that's what you're looking for.

  • How to get the screen back to how it should be as at the present time, it is on the side

    Hello

    Can your hel [, the screen of my laptop is not how it should be and is now on the side as a result of a slip of the hand and a bad button, but we do not know which key it is.

    You can advice how to get on the screen back to normal.

    Kind regards

    Anthony Lawson

    Hello

    Try holding the CTRL and Alt keys, then press the arrow pointing upwards.

    Kind regards

    DP - K

  • How to get my Windows back on computer original.

    My computer came with Windows 7 Home premium 64 bit already intalled.

    A friend of mind said it could update my computer and he put Windows 7 Ulitimate on it, but 32-bit. Im having a lot of problems with the computer now.

    Is there a way I can get my Windows original back on my computer? The computer has not come with any cd or manual. In addition, the sticker with the product key number is partially ripped off I can't see the integer keys to reintall it.   Is there a solution for this problem?

    Thank you

    Judi

    If a branded computer (Dell, HP, etc.). He must be fed with a partition recovery with an image of the computer as it was originally provided. If so, there is a method to restore the computer from this image. How to get to it varies among policy makers, but in general it be a button repeatedly during the first start-up. Search the web for the recovery of the computer manufacturer procedure find the necessary process but we can quote the f9 f11 f12 key but another option are used.

    Unfortunately it's not uncommon to find it does not work because someone has deleted the necessary files. Some manufacturers will allow you to buy online recovery discs.

    Otherwise, if the ultimate upgrade, it can still have the tool to create your own recovery discs that would be for the initial charge. If none were provided the seller was legally required to provide records, so you would need to go back to them.

    Recovery options have the key for manufacturers of large systems, so the label is not necessary. You can try to contact re replacing manufacturers, but they are unlikely to help.

    Otherwise, you will need to purchase a new license.

  • How to get the path page dynamically

    Hello.

    How to get the path to the current page in the processRequest of the controller method? e.g. "/ oracle/apps/ak/sandbox sand/webui/SamplePG.

    -wheleph

    pageContext.getParameter ("page");

    This line will give you exactly what you want...
    Thank you
    Annapurneswar

  • How to get the value of PMT in oracle?

    Hi all

    I need to calculate the value of the PMT


    There is the Excel PMT function == > PMT (rate, nPer, PV, (FV), (TYPE))

    I have to calculate using pl/sql.

    Can any body help how to get the value of PMT in PL/SQL?

    Thanks for your help.

    Kind regards
    Iwanto

    There is no Oracle built-in function to calculate the payments, but the formula is easy to find. If you look at using Excel PV function, you should find the formula that excel uses to calculate. You can rearrange the calculation in terms of payment. If FV and TYPE are 0, then the calculation is

    PV*rate*power((1+rate),nPer)/(power((1+rate),nPer) - 1)
    

    You don't need really PL/SQL to do this.

    Kind regards
    Bob

  • How to get "Internet Checkers" back on the desktop with an icon?

    Original title: How can I "INTERNET draughts" _A game I still had on my desk back when I search it does not find the program that is the play area, but no matter what I can't get it back

    I used to play the original game on my computer every day, I even had an icon dedicated to it on the right side with all the other icons on the blank screen, it turns out that since I am disconnected from a router to another router I have more icon of the familia which shows a blue chip Checkers game & where the icon used to be there is an icon that looks like a miniature 'windows' (with the small blue border along the top from left to right), the same size as the other icons, and instead of internet checkers it says: "chkrz.ex" I do not know, but it is a similar term, but he wwas exactly & it's gone now.  How can I get it back to my windows xp computer?

    Hi EddieQuing,
     
    It would be possible that the shortcut for the game has been corrupted.
     
    Check if the game is available in "all programs". If so, create a new shortcut.
    a. click Start. Click "all programs."
    b. click on games. Highlight on draughts of the Internet and click on send to and choose Destop (shortcut).
     
    Check if that helps.
     
    If that's not enough, and if the game is not available at this location, follow these steps to see if the game has been turned off and activate the same.
     
    a. click the Start button, click Control Panel, click on Add / Remove Programsand then click Add or remove Windows components in the left pane.
    b. now in the Windows Components Wizard select the check box for Accessories and utilities-> click Details-> Select the CheckBox games and double click on it and in the list of games that appears, check the box for 'online games', click OK.
    c. click OK twice.
    d. restart the computer now and check.
     
    Keep me updated on the status of the issue.
  • instructions on how to get your photos back after your computer has been deleted and the

    my computer has been deleted and my photos from my photo file. so I wonder how I can get all my photos if I can at all... my computer was giving me problems and saying that the hard drive has been mess up so I went back and restored my programs and it restored everything but my photos and other files, that I would just get my photos.

    How exactly do you run restore?

    If you have used a disk recovery or a recovery Partition...
    to reinstall your system as it was when you first
    bought it... your personal files may be missing
    unless you do backups on an external support.

    There are programs of software designed to recover the
    deleted files. The following freeware is an example...
    a Google search will find more.

    If there is no file on your hard drive with
    not been crushed... There is a little chance that
    You may be able to recover some of them.

    (FWIW... it's always a good idea to create a system)
    Restore point before installing software or updates)

    Recuva - file recovery
    http://www.Recuva.com/

    Introduction of Recuva (tutorials)
    http://docs.Piriform.com/Recuva/introducing-Recuva

    The following article can be also worth a visit:

    How to recover files deleted with free software
    http://Lifehacker.com/393084/how-to-recover-deleted-files-with-free-software

    Good luck.

  • How to get iTunes after back to Windows window 7 10? Thank you.

    How to bring back my iTunes? I had no problem when I had window 7. After the passage of window 10 back in Windows 7, I lost iTunes and can not download the music I bought on iTunes store.

    Are you sure that iTunes is missing from your computer rather than not have the icon on your desktop?  Click on the iTunes start Orb and type.  Do you have a link like this:

    Have you tried to download and install the latest version of iTunes from here--> https://www.apple.com/itunes/download/

    If this isn't the case, please do.

    If you did, that's happened?

    If you try to install iTunes and get an error, please report the full text of the error message.

    Report the version of Windows you have, include whether 32-bit or 64-bit if you have installed a service pack.  If you do not know the answer to this, click Start, right click computer and select Properties.

  • How to get sql % number of dynamic sql code lines

    Hello

    In this procedure I'm inserting and updating using dynamic sql. Now I want to go back two more PARAMETERS, the parameter should be back the number of lines inserted and how updated by stmtas of UPDATE as well as an INSERT. I'm not able to do can help you on that?

    CREATE OR REPLACE PROCEDURE Sp_Array_Test( PV_TGT_NAME   IN  VARCHAR2,
                                               PV_SRC_NAME   IN  VARCHAR2,
                                               PV_PK_COLS    IN  VARCHAR2,
                                               PN_ERR_CD     OUT NUMBER,
                                               PN_ERR_MSG    OUT VARCHAR2)
    AS
    
    
    TYPE ARR_TAB IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER;
    
    
    --UTL_FP        UTL_FILE.FILE_TYPE;
    LV_AN_
    
    
    
    BLOCK   VARCHAR2(32767);
    LN_CUR        BINARY_INTEGER := DBMS_SQL.OPEN_CURSOR;
    LN_DESC       DBMS_SQL.DESC_TAB;
    LN_COL_CNT    PLS_INTEGER := 0;
    LV_SEL_UPD_STMT   VARCHAR2(4000);
    LV_SEL_INS_STMT   VARCHAR2(4000);
    ARR_INDX      NUMBER := 1;
    LV_DATA_TYPE  VARCHAR2(8);
    LN_FIND_FLAG  NUMBER := 0;
    LN_TAB        ARR_TAB;
    LV_COLS_ARR   ARR_TAB;
    LV_ERR_MSG    VARCHAR2(500);
    
    
    
    
    --PROCEDURE FILE_WRITE ( FH_IN     IN UTL_FILE.FILE_TYPE,
    --                STRING_IN IN VARCHAR2 ) IS
    --BEGIN
    --   UTL_FILE.PUT_LINE(FH_IN,STRING_IN);
    --   LV_AN_BLOCK := LV_AN_BLOCK||STRING_IN;
    --EXCEPTION
    --   WHEN OTHERS THEN
    --      RAISE;
    --END FILE_WRITE;
    
    
    
    
    BEGIN
    
    
    --   UTL_FP := UTL_FILE.FOPEN('TEST_DIR', 'TEST.sql', 'W');
    
    
        LV_SEL_UPD_STMT := 'SELECT A.'||REPLACE(PV_PK_COLS,',','||A.')||' PK_COLS , A.* , B.ROWID FROM '||PV_SRC_NAME||' A, '||PV_TGT_NAME||' B WHERE ';
    
    
        LV_SEL_INS_STMT := 'SELECT A.* FROM '||PV_SRC_NAME||' A WHERE NOT EXISTS (SELECT ''1'' FROM '||PV_TGT_NAME||' B WHERE ';
    
    
        LN_TAB(ARR_INDX) := 'DECLARE ';
        ARR_INDX := ARR_INDX + 1;
    
    
        LN_TAB(ARR_INDX) := 'CURSOR CUR_VIEW_UPD IS '||LV_SEL_UPD_STMT ;
        ARR_INDX := ARR_INDX + 1;
    
    
    
    
        SELECT SUBSTR(COLS,DECODE(RN,1,1,INSTR(COLS,',',1,RN-1)+1),DECODE(RN,1,INSTR(COLS,',',1,RN)-1,INSTR(COLS,',',1,RN)-INSTR(COLS,',',1,RN-1)-1))
    BULK COLLECT INTO LV_COLS_ARR
          FROM ( SELECT RN, PV_PK_COLS||',' COLS
                   FROM (SELECT ROWNUM RN
                           FROM ALL_OBJECTS
                          WHERE ROWNUM <= LENGTH(PV_PK_COLS)- LENGTH(REPLACE(PV_PK_COLS,','))+1)) ;
        FOR K IN 1 .. LV_COLS_ARR.COUNT LOOP
            LV_SEL_UPD_STMT     := LV_SEL_UPD_STMT||' A.'||LV_COLS_ARR(K)||' = ';
            LN_TAB(ARR_INDX) := ' A.'||LV_COLS_ARR(K)||' = ';
            LV_SEL_UPD_STMT     := LV_SEL_UPD_STMT||' B.'||LV_COLS_ARR(K) ||CASE WHEN K = LV_COLS_ARR.COUNT THEN NULL ELSE ' AND ' END;
            LN_TAB(ARR_INDX) := LN_TAB(ARR_INDX)||' B.'||LV_COLS_ARR(K) ||CASE WHEN K = LV_COLS_ARR.COUNT THEN ' ;' ELSE ' AND ' END;
            ARR_INDX := ARR_INDX + 1;
        END LOOP;
    
    
        LN_TAB(ARR_INDX) := 'CURSOR CUR_VIEW_INS IS '||LV_SEL_INS_STMT ;
        ARR_INDX := ARR_INDX + 1;
    
    
        FOR K IN 1 .. LV_COLS_ARR.COUNT LOOP
            LV_SEL_INS_STMT     := LV_SEL_INS_STMT||' A.'||LV_COLS_ARR(K)||' = ';
            LN_TAB(ARR_INDX) := ' A.'||LV_COLS_ARR(K)||' = ';
            LV_SEL_INS_STMT     := LV_SEL_INS_STMT||' B.'||LV_COLS_ARR(K) ||CASE WHEN K = LV_COLS_ARR.COUNT THEN NULL ELSE ' AND ' END;
            LN_TAB(ARR_INDX) := LN_TAB(ARR_INDX)||' B.'||LV_COLS_ARR(K) ||CASE WHEN K = LV_COLS_ARR.COUNT THEN ' );' ELSE ' AND ' END;
            ARR_INDX := ARR_INDX + 1;
        END LOOP;
    
    
    
    
        LV_ERR_MSG := 'WHILE PARSING SELECT STATEMENT -- '||LV_SEL_UPD_STMT;
        DBMS_SQL.PARSE(LN_CUR, LV_SEL_UPD_STMT, DBMS_SQL.NATIVE);
    
    
        LV_ERR_MSG := 'WHILE DESCRIBING SELECT STATEMENT -- '||LV_SEL_UPD_STMT;
        DBMS_SQL.DESCRIBE_COLUMNS(LN_CUR, LN_COL_CNT, LN_DESC);
    
    
    
    
    
    
       FOR i IN LN_DESC.FIRST .. LN_DESC.LAST LOOP
          IF LN_DESC(i).col_type = 2 THEN
             LV_DATA_TYPE := 'NUMBER';
          ELSIF LN_DESC(i).col_type = 12 THEN
             LV_DATA_TYPE := 'DATE';
          ELSE
             LV_DATA_TYPE := 'VARCHAR2';
          END IF;
           LN_TAB(ARR_INDX) := '   T_'||LN_DESC(i).col_name||' DBMS_SQL.'||LV_DATA_TYPE||'_TABLE;';
           ARR_INDX := ARR_INDX + 1;
       END LOOP;
    
    
    
    
    
    
        LN_TAB(ARR_INDX) := 'BEGIN ';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '   EXECUTE IMMEDIATE ''ALTER SESSION SET NLS_DATE_FORMAT = ''''DD-MON-YYYY HH24:MI:SS'''''';';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '   OPEN CUR_VIEW_UPD;';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '   LOOP';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '      FETCH CUR_VIEW_UPD BULK COLLECT INTO T_'||LN_DESC(LN_DESC.FIRST).col_name||',';
        ARR_INDX := ARR_INDX + 1;
        FOR i IN LN_DESC.FIRST + 1 .. LN_DESC.LAST - 1 LOOP
          LN_TAB(ARR_INDX) := '                        T_'||LN_DESC(i).col_name||',';
          ARR_INDX := ARR_INDX + 1;
        END LOOP;
       LN_TAB(ARR_INDX) := '                        T_'||LN_DESC(LN_DESC.LAST).col_name||' LIMIT 500 ;';
       ARR_INDX := ARR_INDX + 1;
       LN_TAB(ARR_INDX) := '     FORALL I IN 1 .. '||'T_'||LN_DESC(LN_DESC.LAST).col_name||'.COUNT ';
       ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '      UPDATE '||PV_TGT_NAME||' SET  ';
        ARR_INDX := ARR_INDX + 1;
        LN_FIND_FLAG := 0;
        FOR I IN LN_DESC.FIRST + 1 .. LN_DESC.LAST-1 LOOP
          FOR K IN 1 .. LV_COLS_ARR.COUNT LOOP
             LN_FIND_FLAG := 0;
             IF LN_DESC(I).COL_NAME = LV_COLS_ARR(K) THEN
                LN_FIND_FLAG := 1;
                EXIT;
             END IF;
          END LOOP;
          IF LN_FIND_FLAG = 0 THEN
            LN_TAB(ARR_INDX) := '                        '||LN_DESC(i).col_name||' = '||'T_'||LN_DESC(i).col_name||'(I)'||CASE WHEN I = LN_DESC.LAST-1 THEN ' WHERE ' ELSE ',' END;
            ARR_INDX := ARR_INDX + 1;
          END IF ;
        END LOOP;
    
    
       LN_TAB(ARR_INDX) := '                        ROWID = '||'T_'||LN_DESC(LN_DESC.LAST).col_name||'(I) ;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      COMMIT;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      EXIT WHEN CUR_VIEW_UPD%NOTFOUND;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '   END LOOP;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '   CLOSE CUR_VIEW_UPD;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      COMMIT;';
       ARR_INDX := ARR_INDX + 1;
    
    
    
    
        LN_TAB(ARR_INDX) := '   OPEN CUR_VIEW_INS;';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '   LOOP';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '      FETCH CUR_VIEW_INS BULK COLLECT INTO T_'||LN_DESC(LN_DESC.FIRST+1).col_name||',';
        ARR_INDX := ARR_INDX + 1;
        FOR i IN LN_DESC.FIRST + 2 .. LN_DESC.LAST - 2 LOOP
          LN_TAB(ARR_INDX) := '                        T_'||LN_DESC(i).col_name||',';
          ARR_INDX := ARR_INDX + 1;
        END LOOP;
       LN_TAB(ARR_INDX) := '                        T_'||LN_DESC(LN_DESC.LAST-1).col_name||' LIMIT 500 ;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '     FORALL J IN 1 .. '||'T_'||LN_DESC(LN_DESC.FIRST + 1).col_name||'.COUNT ';
       ARR_INDX := ARR_INDX + 1;
       LN_TAB(ARR_INDX) := '     INSERT INTO '||PV_TGT_NAME||' (';
       ARR_INDX := ARR_INDX + 1;
        FOR i IN LN_DESC.FIRST + 1 .. LN_DESC.LAST - 1 LOOP
          LN_TAB(ARR_INDX) := '                        '||LN_DESC(i).col_name||CASE WHEN I = LN_DESC.LAST - 1  THEN ' )' ELSE ',' END ;
          ARR_INDX := ARR_INDX + 1;
        END LOOP;
        FOR i IN LN_DESC.FIRST + 1 .. LN_DESC.LAST - 1 LOOP
          LN_TAB(ARR_INDX) := CASE WHEN I = LN_DESC.FIRST + 1 THEN 'VALUES (' ELSE NULL END ||'                        T_'||LN_DESC(i).col_name||'(J)'||CASE WHEN I = LN_DESC.LAST - 1  THEN ' ) ;' ELSE ',' END ;
          ARR_INDX := ARR_INDX + 1;
        END LOOP;
    
    
       LN_TAB(ARR_INDX) := '      COMMIT;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      EXIT WHEN CUR_VIEW_INS%NOTFOUND;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '   END LOOP;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '   CLOSE CUR_VIEW_INS;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      COMMIT;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := 'END ;';
       ARR_INDX := ARR_INDX + 1;
    
    
    
    
       FOR J IN 1 .. LN_TAB.COUNT LOOP
    --     DBMS_OUTPUT.PUT_LINE( LN_TAB(J));
    --     FILE_WRITE(UTL_FP,LN_TAB(J));
         LV_AN_BLOCK := LV_AN_BLOCK||LN_TAB(J);
       END LOOP;
    
    
    --   UTL_FILE.FCLOSE(UTL_FP);
    
    
       EXECUTE IMMEDIATE LV_AN_BLOCK;
    
    
    PN_ERR_CD    := 0;
    PN_ERR_MSG   := 'Successful Completion';
    
    
    EXCEPTION
    WHEN OTHERS THEN
    PN_ERR_CD    := SQLCODE;
    PN_ERR_MSG   := LV_ERR_MSG||' -- '||SQLERRM ;
    END;
    /
    

    Thank you all for your answers. I agree with you all. I have manged this time by adding variable bind, then run it immediately ON aid. I don't know how it's going to be training.

    From now on my side no problem I don't thank you.

  • I just paid my adobe converted to the Word file and it does not work, how I get my money back?

    I paid for something to convert Adobe to the word and it is not the same word, there are missing words and characters are missing and messed up. I want my money, how can I get a refund?

    ICES.html https://helpx.adobe.com/x-productkb/Policy-Pricing/Cancel-subscription-Acrobat-Online-serv

    [subject moved to cloud Document PDF Services forum]

  • How to get the year and month of a whole year

    Hello

    I have a list of selection and when the user selects the list values are like this 201101,201102,201103

    I tried like this


    declare
    T_DATE varchar2 (25);
    Start
    because me in 1.12 loop
    Select TO_CHAR (ADD_MONTHS (SYSDATE, + 1), "YYYYMM") in the double T_DATE;
    dbms_output.put_line (V_DATE);
    end loop;
    end;

    But its bad and I can not get clear idea where to change the code

    Thanks and greetings
    Srikkanth.M

    Srikkanth.M wrote:
    Hello

    I have a list of selection and when the user selects the list values are like this 201101,201102,201103

    If you want to list for the current year from Jan 201101,201102, 201103... 201112, then try this

    DECLARE
      v_Date  VARCHAR2(25);
      n_month NUMBER;
    BEGIN
      SELECT extract (MONTH FROM sysdate) INTO n_month FROM dual;
      FOR i IN 1..12
      LOOP
        SELECT TO_CHAR(ADD_MONTHS(SYSDATE, (i-n_month)), 'YYYYMM')
        INTO v_date
        FROM dual;
        dbms_output.put_line(v_date);
      END LOOP;
    END;
    

    Vivek L

  • How to get the year of Date data

    Hi all

    I have the following scenario:

    County - Date - Code
    5 DS - 01/09/2009
    5 DS - 15/01/2009
    5 LO - 21/01/2009
    1. IT - 02/09/2009
    5 DS - 03/09/2009
    5 LO - 04/09/2009
    4 DS - 05/09/2009
    5 - IS - 06/09/2009
    5 DS - 07/09/2009
    5 - IS - 08/09/2009
    3 DS - 09/09/2009
    5 DS - 10/09/2009
    5 LO - 11/09/2009
    2 DS - 12/09/2009
    5 DS - 01/09/2010
    5 LO - 02/09/2010
    4 DS - 03/09/2010

    How can I only CDA data for 2009 and one year for 2010... Is meant by CDA 2009 data until the day of the date for example, if its 9 March today... TBE outcome will bring full jan, Feb and until the 9th day of March ' 09 and full jan, Feb and until the 9th day of March 10

    Thank you

    Published by: [email protected] on March 9, 2010 23:03

    Published by: [email protected] on March 9, 2010 23:06

    Something like:

    where dt <= trunc(dt,'YYYY')+(trunc(sysdate,'DD')-(trunc(sysdate,'YYYY'))
    

    "Dt" corresponding to your date column.

Maybe you are looking for