Help understanding how to pass dates to procedures in a package?

When I run the following script in SQL*Plus, I get no obvious errors, but the truncate does not happen and all the other processing doesn't happen. I ran a similar version in another tool and it worked. Much of the code is deleted here but I believe I don't fully understand passing dates in the procedure. I figure if one of the dates ends up null or something invalid, the procedure will run and give no results. If someone could correct me on how to pass variables, it would help greatly. As you can see, I am passing 2 dates in from an ACCEPT statement, passing them to 1 shell type procedure which runs other procedures and passes the dates to the procedures below it. This procedures calls the 3rd procedure and passes the same dates to it:
ACCEPT CUR_PERIOD PROMPT 'Current Period (MM/DD/YYYY): ';
ACCEPT PRIOR_PERIOD PROMPT 'Prior Period (MM/DD/YYYY): ';
EXEC RCO.MONTH_END_PACK_1.MONTHENDPHASE1PROC('&CUR_PERIOD','&PRIOR_PERIOD');
The spec looks like this:
CREATE OR REPLACE PACKAGE MONTH_END_PACK_1 AS
     PROCEDURE MonthEndPhase1PROC(get_cur_period IN DATE, get_prior_period IN DATE);
     PROCEDURE W_CAT_INFO_RPT_PROC(GET_CUR_PERIOD IN DATE, GET_PRIOR_PERIOD IN DATE);
     PROCEDURE WO_CAT_INFO_RPT_PROC(GET_CUR_PERIOD IN DATE, GET_PRIOR_PERIOD IN DATE);
END MONTH_END_PACK_1;
The body looks like this:CREATE OR REPLACE PACKAGE BODY MONTH_END_PACK_1  AS
PROCEDURE MonthEndPhase1PROC(get_cur_period IN DATE, get_prior_period IN DATE) IS
     BEGIN
          EXECUTE IMMEDIATE 'TRUNCATE TABLE RPT_DS1_CNT';
          EXECUTE IMMEDIATE 'TRUNCATE TABLE RPT_DS1_CNT_CAT';
          W_CAT_INFO_RPT_PROC(GET_CUR_PERIOD, GET_PRIOR_PERIOD);
     END;
PROCEDURE W_CAT_INFO_RPT_PROC(GET_CUR_PERIOD IN DATE, GET_PRIOR_PERIOD IN DATE) IS
     CUR_PERIOD DATE;
     PRIOR_PERIOD DATE;
     BEGIN
          -- Assign the dates to this procedure that were passed in above.
          CUR_PERIOD := GET_CUR_PERIOD;         --07/27/2007
          PRIOR_PERIOD := GET_PRIOR_PERIOD;     --06/27/2007
          -- Execute stored procedure, passing in dates.
          WO_CAT_INFO_RPT_PROC(CUR_PERIOD, PRIOR_PERIOD);
          -- Other code goes here
     END; -- W_CAT_INFO_RPT_PROC
PROCEDURE WO_CAT_INFO_RPT_PROC(GET_CUR_PERIOD IN DATE, GET_PRIOR_PERIOD IN DATE) IS
     CUR_PERIOD DATE;
     PRIOR_PERIOD DATE;
     BEGIN
          CUR_PERIOD := GET_CUR_PERIOD;
          PRIOR_PERIOD := GET_PRIOR_PERIOD;
          INSERT INTO RPT_DS1_CNT
          (select distinct trim(CVBI_KEY) as CVBI_KEY, vendor_id
          from
          (select m.cvbi_key, v.vendor_name
          from  rco.cogs_resource m,RCO.COGS_SRVCTYP st,rco.cogs_mkt ms,RCO.COGS_VENDOR v,
            (select distinct cvbi_key, vendor_id
             from RCO.COGS_resource
             where period = CUR_PERIOD)ak
          where  ak.cvbi_key = m.cvbi_key
          and  trim(m.cvbi_key) = trim(st.cvbi_key(+))
          and  period = CUR_PERIOD));
     END;
END;
/

EXEC RCO.MONTH_END_PACK_1.MONTHENDPHASE1PROC(to_date('&CUR_PERIOD','MM/DD/YYYY'),to_date('&PRIOR_PERIOD','MM/DD/YYYY'));
As you can see, I am passing 2 dates in from an ACCEPT statementUntil you convert them using TO_DATE they are just strings
Message was edited by:
3360
Fixed date formats

Similar Messages

  • How to pass data from one internal session to another internal session

    hi all sap experts ,
    How to pass data from one internal session to another internal session and from oneExternal session to another external session.
    Except : Import and Export parameters and SPA/GPA parameters.
    Tell me the otherWay to pass data ..
    Plz
    Thanks in advance

    hi,
      abap memory management u will understand about this concept.
    the import /export parameter will help u that passing data between two internal sessions by using abap memory.
      for syntax
    Passing Data Between Programs
    There are two ways of passing data to a called program:
    Passing Data Using Internal Memory Areas
    There are two cross-program memory areas to which ABAP programs have access (refer to the diagram in Memory Structures of an ABAP Program) that you can use to pass data between programs.
    SAP Memory
    SAP memory is a memory area to which all main sessions within a SAPgui have access. You can use SAP memory either to pass data from one program to another within a session, or to pass data from one session to another. Application programs that use SAP memory must do so using SPA/GPA parameters (also known as SET/GET parameters). These parameters can be set either for a particular user or for a particular program using the SET PARAMETER statement. Other ABAP programs can then retrieve the set parameters using the GET PARAMETER statement. The most frequent use of SPA/GPA parameters is to fill input fields on screens (see below).
    ABAP Memory
    ABAP memory is a memory area that all ABAP programs within the same internal session can access using the EXPORT and IMPORT statements. Data within this area remains intact during a whole sequence of program calls. To pass data to a program which you are calling, the data needs to be placed in ABAP memory before the call is made. The internal session of the called program then replaces that of the calling program. The program called can then read from the ABAP memory. If control is then returned to the program which made the initial call, the same process operates in reverse. For further information, refer to Data Clusters in ABAP Memory.
    Filling Input Fields on an Initial Screen
    Most programs that you call from other programs have their own initial screen that the user must fill with values. For an executable program, this is normally the selection screen. The SUBMIT statement has a series of additions that you can use to fill the input fields of the called program:
    Filling the Selection Screen of a Called Program
    You cannot fill the input fields of a screen using additions in the calling statement. Instead, you can use SPA/GPA parameters. For further information, refer to Filling an Initial Screen Using SPA/GPA Parameters.
    Message was edited by:
            sunil kumar
    Message was edited by:
            sunil kumar

  • How to pass Data from one form to the other

    Hi all
    Can any one suggest me how to pass data from one form to the other form, which i zoomed from the original one?
    I tried to do this by passing parameter in Event Procedure but i am getting error msg when i am opening the zoomed form.
    If any one of u have any idea, give me a reply
    Thank you
    Suhasini

    If you choose the second alternative you should erase these global variables after the second form is opened
    You can erase the global variable using:
    erase('global_var')
    Greetings,
    Sim

  • SAP threading-how to pass data between different batch job programs?

    Hi everyone,
        now i have one problem about performance tuning using threading in SAP programs: split one big program into two programs - one is main program and the other is sub program. using batch jobs, we can submit multi jobs of sub program at the same time.
        does anybody know how to pass data between different batch jobs? I don't want to use temp files. can ABAP memory can implement this?
        thanks!

    Passing Data Between Programs
    [http://help.sap.com/saphelp_47x200/helpdata/en/9f/db9df735c111d1829f0000e829fbfe/frameset.htm|http://help.sap.com/saphelp_47x200/helpdata/en/9f/db9df735c111d1829f0000e829fbfe/frameset.htm]

  • I need help understanding how the Apple components integrate to create a system across all my devices?

    I need help understanding how the Apple components connect to create a whole system across all my devices?
    Is there a resource that describes current system and associated functionality?
    For example:
    Buy A, B, C to achieve "X" 
    You will need:
    an internet provider which supports <specs>
    add D to achieve "Y"
    You will need:
    an internet provider which supports <specs>
    add "E" to achieve "Z"
    You will need:
    an internet provider which supports <specs>
    For example, I am looking at the Gen 6 Airport extreme.  For intended performance do I need broadband? if so what are the specs, or will basic internet service suffice?  Do I need the internet provider's modem or does the Airport extreme replace that?  And then I think, if I am doing this, I should also look at Apple TV....What do I need and Why?  Then I look at the New Desk top coming out in the fall, and I think well, if I wait and get this, what does this component do for the system, and what becomes redundant? What does this awesome desktop do for my ability to sit and use a new macbook air when I travel  or sit on the couch in my PJs?
    If there was a place that plainly stated "if you buy the new dektop you can configure a system including only these components and achieve <this result> and by adding <additional components> you will achieve this result.
    I have been to the genius store a few times, but I come out of there more confused unless I have SPECIFIC questions or already know what to buy. 
    A "System Configuration App" would be a really great sales tool--Just saying.

    I have no idea what "fully optimized" means.
    No Apple device will let you watch broadcast TV. The Apple TV is a good option for watching streaming TV from iTunes, NetFlix and Hulu. If you want to watch from other sources, you may need to look at other devices.
    Any Mac computer or iPad will allow you to surf the web.
    What business software?
    Time Capsule is a good option for back ups.
    Update what across all devices?
    For accessing documents from all devices, a service like Dropbox is your best bet.
    I have no idea what "step as far away from an internet provider as possible" means. If you want Internet access, you need an Internet provider.
    Lighting fast speed for what? Processor? The specs are listed for all devices in the Online Store. Internet? We're back to the service provider.
    Technology changes. The only way to keep pace with it beyond a couple of years is to buy new stuff.
    The bottom line is you need to look at the specs for devices availble and at your budget and decide what best meets your needs. If you are unable to do that on your own, there are lot of technology consultants out there who will, for a fee, look at your exact situation, make recommendations and even handle the purchase and set up. Perhaps that would be the best route for you.
    Best of luck.

  • Need to understand how the PGI date is being calculated

    Hi,
    Need to understand how the PGI date is being calculated.
    Does the PGI date get recalculated if the cusotme delivery date is changed.
    Thanks,
    Raki

    Hi,
    Thanks for the information and please let us know is there any calculation logic exist for that?
    I have changed delivery date in the sales order and based on that-
    - Transportation planning/material availability/loading/schedule line and confirmed quantity date was chaged.
    Is this the - GI date - Transist time= PGI?
    Thanks,

  • Performace tuning: how to pass data between different batch job programs?

    Hi everyone,
        now i have one problem about performance tuning using threading in SAP programs: split one big program into two programs - one is main program and the other is sub program. using batch jobs, we can submit multi jobs of sub program at the same time.
        does anybody know how to pass data between different batch jobs? I don't want to use temp files. can ABAP memory can implement this?
        thanks!

    Wei,
    Yes we can transfer the data by using
    SAP Memory OR ABAP Memory.
    Ex:  V_count TYPE i.
      V_count = 100.
    LOOP AT  itab.
    IF v_count EQ 25.
    Here For every batch job
      EXPORT data TO MEMORY ID 'ABC'
       Function module
        JOB_OPEN
       JOB_SUBMIT
       JOB_CLOSE.
      ENDIF.
    ENDLOOP .
    IN your 2nd program.
    INITIALIZATION.
    IMPORT data FROM MEMORY IF 'ABC'.
    FREE memory if .---When you free the memory you will get recent data.
    Don't forget to reward if useful.

  • Help me,  How to read data from USB ???

    Help me, How to read data from USB ???

    If its a disk on key or some portable hard drive than once its connected to the usb and recognized by the system you can access it through java like you would access your hard drive.

  • How to pass data from offline form to webdynpro java

    Hi,
    Please suggest me how to pass data from offline from to webdynpro java node?
    i am using the below code to pass data from offline form(after entering values in the form) to node . i am using form upload ui element to upload offline form and after that i am providng a button to update data.But still i am not able to see data in the node.Any suggestions on this.below code is wriiten on action of the button.
    wdContext.currentContextElement().setPDFSource(null);
           try
                if(null!=wdContext.currentContextElement().getAttributePointer("Resource"))
           IWDResource fileResource = wdContext.currentContextElement().getResource();
         if("PDF".equalsIgnoreCase(fileResource.getResourceType().getFileExtension()))
           byte[] b = new byte[wdContext.currentContextElement().getResource().read(false).available()];
           wdContext.currentContextElement().getResource().read(false).read(b)                     wdContext.currentContextElement().setPDFSource(b);
           WDInteractiveFormHelper.transferPDFDataIntoContext                 (wdContext.currentContextElement().getPDFSource(), wdContext.nodeVn_TestData());                                                               
                     else
                          wdComponentAPI.getMessageManager().reportException("Please enter correct file");
                else
                     wdComponentAPI.getMessageManager().reportException("Error while uploading file"); 
           catch (Exception e) {
                wdComponentAPI.getMessageManager().reportException
                ("Error in uploading the Adobe Form :"+e.getLocalizedMessage(),false);
    Regards,
    Pavani

    If you choose the second alternative you should erase these global variables after the second form is opened
    You can erase the global variable using:
    erase('global_var')
    Greetings,
    Sim

  • How to pass data from one internal session to another

    Hi SAP Experts,
    How to pass data from one internal session to another and from One external session to another external session. I used import and export parmeter and SPA/GPA parameters. What is the other way to pass data?
    Please tel me urgently
    Thank you
    Basu

    Memory Structures of an ABAP Program
    In the Overview of the R/3 Basis System you have seen that each user can open up to six R/3 windows in a single SAPgui session. Each of these windows corresponds to a session on the application server with its own area of shared memory.
    The first application program that you start in a session opens an internal session within the main session. The internal session has a memory area that contains the ABAP program and its associated data. When the program calls external routines (methods, subroutines or function modules) their main program and working data are also loaded into the memory area of the internal session.
    Only one internal session is ever active. If the active application program calls a further application program, the system opens another internal session. Here, there are two possible cases: If the second program does not return control to the calling program when it has finished running, the called program replaces the calling program in the internal session. The contents of the memory of the calling program are deleted. If the second program does return control to the calling program when it has finished running, the session of the called program is not deleted. Instead, it becomes inactive, and its memory contents are placed on a stack.
    The memory area of each session contains an area called ABAP memory. ABAP memory is available to all internal sessions. ABAP programs can use the EXPORT and IMPORT statements to access it. Data within this area remains intact during a whole sequence of program calls. To pass data to a program which you are calling, the data needs to be placed in ABAP memory before the call is made. The internal session of the called program then replaces that of the calling program. The program called can then read from the ABAP memory. If control is then returned to the program which made the initial call, the same process operates in reverse.
    All ABAP programs can also access the SAP memory. This is a memory area to which all sessions within a SAPgui have access. You can use SAP memory either to pass data from one program to another within a session, or to pass data from one session to another. Application programs that use SAP memory must do so using SPA/GPA parameters (also known as SET/GET parameters). These parameters are often used to preassign values to input fields. You can set them individually for users, or globally according to the flow of an application program. SAP memory is the only connection between the different sessions within a SAPgui.
    The following diagram shows how an application program accesses the different areas within shared memory:
    In the diagram, an ABAP program is active in the second internal session of the first main session. It can access the memory of its own internal session, ABAP memory and SAP memory. The program in the first internal session has called the program which is currently active, and its own data is currently inactive on the stack. If the program currently active calls another program but will itself carry on once that program has finished running, the new program will be activated in a third internal session.
    Data Clusters in ABAP Memory
    You can store data clusters in ABAP memory. ABAP memory is a memory area within the internal session (roll area) of an ABAP program and any other program called from it using CALL TRANSACTION or SUBMIT.
    ABAP memory is independent of the ABAP program or program module from which it was generated. In other words, an object saved in ABAP memory can be read from any other ABAP program in the same call chain. ABAP memory is not the same as the cross-transaction global SAP memory. For further information, refer to Passing Data Between Programs.
    This allows you to pass data from one module to another over several levels of the program hierarchy. For example, you can pass data
    From an executable program (report) to another executable program called using SUBMIT.
    From a transaction to an executable program (report).
    Between dialog modules.
    From a program to a function module.
    and so on.
    The contents of the memory are released when you leave the transaction.
    To save data objects in ABAP memory, use the statement EXPORT TO MEMORY.
    Saving Data Objects in Memory
    To read data objects from memory, use the statement IMPORT FROM MEMORY.
    Reading Data Objects from Memory
    To delete data clusters from memory, use the statement FREE MEMORY.
    Deleting Data Clusters from Memory
    please read this which provide more idea about memory
    Message was edited by:
            sunil kumar

  • How to pass data in realtime jobs throgh XML ??

    How to pass data in realtime jobs throgh XML in Data Services  ??

    http://wiki.scn.sap.com/wiki/display/EIM/Realtime+at+a+Glance

  • How to pass data from list to internal table

    Sir,
    Please tell me how to pass data from list display to internal table. Some fields in the list display are input fields .These are added at run time and these added values should be stored in the internal table

    Follow this code sample:
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
        I_CALLBACK_PROGRAM                = W_REPID
        I_CALLBACK_PF_STATUS_SET          = 'PF_STATUS'
        I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
    FORM USER_COMMAND USING P_UCOMM TYPE SY-UCOMM
                            P_SELFLD TYPE SLIS_SELFIELD.
    case p_ucomm.
    when '<Some user Action>'.
      Data ref1 type ref to cl_gui_alv_grid.
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
    E_GRID = ref1.
    call method ref1->check_changed_data
    * Your internal table will have the data
    endcase.
    ENDFORM.
    Regards,
    Ravi

  • How to pass data between two internal sessions using ABAP memory?

    Hi,
    How to pass data between two internal sessions using ABAP memory?
    It would be fine if you could explain with an example.
    And also let me clear about the data passing between two main sessions and two external sessions with specific examples.
    Thanks.

    Hi ,
      check the example.
    Reading Data Objects from Memory
    To read data objects from ABAP memory into an ABAP program, use the following statement:
    Syntax
    IMPORT <f1> [TO <g 1>] <f 2> [TO <g 2>] ... FROM MEMORY ID <key>.
    This statement reads the data objects specified in the list from a cluster in memory. If you do not use the TO <g i > option, the data object <f i > in memory is assigned to the data object in the program with the same name. If you do use the option, the data object <f i > is read from memory into the field <g i >. The name <key> identifies the cluster in memory. It may be up to 32 characters long.
    You do not have to read all of the objects stored under a particular name <key>. You can restrict the number of objects by specifying their names. If the memory does not contain any objects under the name <key>, SY-SUBRC is set to 4. If, on the other hand, there is a data cluster in memory with the name <key>, SY-SUBRC is always 0, regardless of whether it contained the data object <f i >. If the cluster does not contain the data object <f i >, the target field remains unchanged.
    In this statement, the system does not check whether the structure of the object in memory is compatible with the structure into which you are reading it. The data is transported bit by bit. If the structures are incompatible, the data in the target field may be incorrect.
    PROGRAM SAPMZTS1.
    DATA TEXT1(10) VALUE 'Exporting'.
    DATA ITAB LIKE SBOOK OCCURS 10 WITH HEADER LINE.
    DO 5 TIMES.
      ITAB-BOOKID = 100 + SY-INDEX.
      APPEND ITAB.
    ENDDO.
    EXPORT TEXT1
           TEXT2 FROM 'Literal'
      TO MEMORY ID 'text'.
    EXPORT ITAB
      TO MEMORY ID 'table'.
    SUBMIT SAPMZTS2 AND RETURN.
    SUBMIT SAPMZTS3.
    The first part of this program is the same as the example in the section Saving Data Objects in Memory. In the example, the programs SAPMZTS1 and SAPMZTS2 are called using SUBMIT. You can create and maintain the programs called using the SUBMIT statement by double-clicking their names in the statement. For further information about the SUBMIT statement, refer to Calling Executable Programs (Reports)
    Example for SAPMZTS2:
    PROGRAM SAPMZTS2.
    DATA: TEXT1(10),
          TEXT3 LIKE TEXT1 VALUE 'Initial'.
    IMPORT TEXT3 FROM MEMORY ID 'text'.
    WRITE: / SY-SUBRC, TEXT3.
    IMPORT TEXT2 TO TEXT1 FROM MEMORY ID 'text'.
    WRITE: / SY-SUBRC, TEXT1.
    Example for SAPMZTS3:
    PROGRAM SAPMZTS3.
    DATA JTAB LIKE SBOOK OCCURS 10 WITH HEADER LINE.
    IMPORT ITAB TO JTAB FROM MEMORY ID 'table'.
    LOOP AT JTAB.
      WRITE / JTAB-BOOKID.
    ENDLOOP.
    The output is displayed on two successive screens. It looks like this:
    and
    The program SAPMZTS2 attempts to read a data object TEXT3 from the data cluster "text", which does not exist. TEXT3 therefore remains unchanged. The existing data object TEXT2 is placed in TEXT1. In both cases, SY-SUBRC is 0, since the cluster "text" contains data.
    The program SAPMZTS3 reads the internal table ITAB from the cluster "table" into the internal table JTAB. Both tables have the same structure, namely that of the ABAP Dictionary table SBOOK.
    Pls. reward if useful.....

  • Passing date to procedure help

    Hello, this maybe simple question, but I couldn't figure out why I am getting
    ORA-01843: not a valid month.. Here is what I did:
    exec proc(to_date('01/01/2007','MM/DD/YYYY'),to_date(01/30/2007,'MM/DD/YYYY'))NLS setting is: DD-MON-RR
    procedure proc (date1 in date, date2 in date)
    v_date_period varchar2;
    select date_period into v_date_period from t1 where start_date = to_date(date1,'MM/DD/YYYY') and end_date = to_date(date2,'MM/DD/YYYY');
    start_date and end_date are in date MM/DD/YYYY format in the table, but the above code is failed b/c of the above error.
    One thing I noticed that when dates are passed into the procedure, they come in DD-MON-RR format and the comparion never works in cursor. start_date and end_date are in MM/DD/YYYY format. but it works only when to_date(date1,'DD-MON-RR') and to_date(date2,'DD-MON-RR'). How is it working when start_date and end_date are in MM/DD/YYYY format???
    another question is, when I say To_date, does it always convert any date to NLS setting? I used
    to_date('01/01/2007', 'dd/mm/yyyy'), but it doesn't have any effect when it goes to the procedure.. still comes as DD-MON-RR.
    what mistake i am doing? I would appreciate your ans. Thanks,

    I think I got it now. I really didn't need that extra
    conversion within the procedure. It works now. Then let's make sure it's clear for you.
    You are right to consider the NLS_DATE_FORMAT settings, that's good, as most people are unaware of it and really have no understanding whatsoever as to what it does. Perhaps your understanding of it is not quite up to scratch just yet...
    The setting relates to how oracle converts between dates and strings when no format is specified explicitly. e.g.
    SQL> select to_char(sysdate) from dual;
    TO_CHAR(SYSDATE)
    04/03/2008 10:00:11
    SQL> alter session set nls_date_format = 'YYYY MON DD';
    Session altered.
    SQL> select to_char(sysdate) from dual;
    TO_CHAR(SYS
    2008 MAR 04
    SQL> select to_char(sysdate, 'DD/MM/YYYY') from dual;
    TO_CHAR(SY
    04/03/2008
    SQL>Likewise if you convert the other way from a string to a date...
    Firstly with implicit conversion, which will assume the NLS_DATE_FORMAT setting format for the string...
    SQL> select to_date('2008 JAN 01') from dual;
    TO_DATE('20
    2008 JAN 01And then if you explicitly convert specifying the format...
    SQL> select to_date('01/01/2008','DD/MM/YYYY') from dual;
    TO_DATE('01
    2008 JAN 01However if you try and implicitly convert (using the NLS setting) but the string isn't of the correct format...
    SQL> select to_date('01/01/2008') from dual;
    select to_date('01/01/2008') from dual
    ERROR at line 1:
    ORA-01843: not a valid month
    SQL>So now let's look at what you were doing...
    select date_period into v_date_period
    from t1
    where start_date = to_date(date1,'MM/DD/YYYY')
    and end_date = to_date(date2,'MM/DD/YYYY');Your date1 and date2 are already of a DATE datatype. This means that they are already stored in the oracle internal date format. Note: ALL dates are stored the same internally regardless of how they are displayed. e.g.
    SQL> select sysdate, dump(sysdate) from dual;
    SYSDATE
    DUMP(SYSDATE)
    04/03/2008 10:35:20
    Typ=13 Len=8: 216,7,3,4,10,35,20,0
    SQL> alter session set nls_date_format = 'YYYY MON DD HH24:MI'
      2  ;
    Session altered.
    SQL> select sysdate, dump(sysdate) from dual;
    SYSDATE
    DUMP(SYSDATE)
    2008 MAR 04 10:36
    Typ=13 Len=8: 216,7,3,4,10,36,50,0
    SQL>However, you are using the to_date function. This expects the first parameter to be a string and the second parameter is an optional string specifying the format of the first string.
    So it was expecting:
    to_date(<string>,<string>)and you gave it
    to_date(<date>,<string>)When oracle comes across this sort of thing, rather than produce an error it recognises that it is able to do an implicit conversion of datatypes so internally it is doing
    to_date(to_char(<date>),<string>)Note: because it is an implicit conversion within the "to_char" it is using the NLS settings to do this.
    You said your NLS setting was DD-MON-RR, so this is the same as...
    to_date(to_char(<date>,'DD-MON-RR'),<string>)Now look at your code again with the implicit conversions in place...
    select date_period into v_date_period
    from t1
    where start_date = to_date(to_char(date1,'DD-MON-RR'),'MM/DD/YYYY')
    and end_date = to_date(to_char(date2,'DD-MON-RR'),'MM/DD/YYYY');Hmmm, so the to_date function is getting it's first parameter as a string in the format 'DD-MON-RR' and the second parameter is telling it that the first parameter is in the format 'MM/DD/YYYY'.
    The two dates you passed were:
    '01/01/2007'
    and
    '01/30/2007'
    But after the implicit conversion your code looks like...
    select date_period into v_date_period
    from t1
    where start_date = to_date('01-JAN-07','MM/DD/YYYY')
    and end_date = to_date('30-JAN-07','MM/DD/YYYY');As you can see there are numerous problems with this. The first one Oracle errored on was the fact that 30 is not a valid Month as defined by your format string.
    Hopefully that clarifies things a little more for you and you'll understand a little more about the differences between strings, dates and implicit and explicit conversion between the two using format strings and the NLS setting.
    ;)

  • Please help me on how to pass date condition Dynamically.

    Hi Experts,
    I have the following control table.
    ID S_OWNER  SOURCE_TABLE     A_OWNER    ARC_TABLE             CONDITION_COLUMN     PERIOD_VALUE   PERIOD_UNIT
    1    wedb     Auction_table    wedb     Arc_Auction_table     Auction_date            15               Days
    1    wedb     Sales_table      wedb     ArcSales_table             Sales_date            180              Days
    1    hr       Accounts_table   hr       Arc_Accounts_table     Account_date             2             Years
    2    concor   Concur_table     con      Arc_Concur_table        Last_update_date        4               MonthsLike this 1000 entries are there in the control_table.
    I want to pass all the columns from my control table dynamically.
    I am able to pass all the columns dynamically,except the PERIOD_VALUE.
    I have stucked up how to implement this condition.
    My aim is to get the data which is <= sysdate-PERIOD_VALUES based on PERIOD_UNIT.
    For Example:
    For Auction_date column I want to get the data which 15 days old.
    For Sales_date column I want to get the data which 180 days old.
    For Account_date column I want to get the data which 2 yers old.
    For Last_update_date column I want to get the data which 4 months old.
    The conditions something like this.
    condition_column<=(sysdate-15 days)
    condition_column<=(sysdate-180 days)
    condition_column<=(sysdate-2 years)
    condition_column<=(sysdate-4 months)This is my procedure.
    CREATE OR REPLACE PROCEDURE WEDB.procedure_control(
       P_ID IN NUMBER)
    IS
       CURSOR C
       IS
            SELECT ID,S_OWNER,SOURCE_TABLE,A_OWNER,ARC_TABLE,CONDITION_COLUMN,PERIOD_VALUE,PERIOD_UNIT
              FROM wedb.CONTROL
             WHERE ID = p_id
          ORDER BY ID, SOURCE_TABLE;
          rec C%ROWTYPE;
    BEGIN
       FOR I IN C
       LOOP
        EXECUTE IMMEDIATE
                   'INSERT INTO '
                || rec.A_OWNER
                || '.'
                || rec.ARC_TABLE
                || '(SELECT * FROM '
                || rec.S_OWNER
                || '.'
                || rec.SOURCE_TABLE
                || ' WHERE '
                || rec.CONDITION_COLUMN
                || '<=I want to pass dynamic condition'
                || ')';
             EXECUTE IMMEDIATE
                   'DELETE FROM '
                || rec.S_OWNER
                || '.'
                || rec.SOURCE_TABLE
                || ' WHERE '
                || rec.CONDITION_COLUMN
                || '<= I want to pass dynamic condition'
                || '';
          COMMIT;
       END LOOP;
    EXCEPTION
       WHEN OTHERS
       THEN
          ROLLBACK;
          DBMS_OUTPUT.PUT_LINE (
             'An error was encountered - ' || SQLCODE || ' -ERROR- ' || SQLERRM);
    END procedure_control;
    /Please help me how to implement this.
    Thanks in advance.

    I have added ||')' paranthasis for each CASE stament to avoiid the error.
    Now I am getting the below error
    ORA-00903: invalid table name
    ORA-06512: at line 42
    I am using below code.
    Please find my below code.
    DECLARE
       stmt   LONG;
       CURSOR C
       IS
            SELECT GROUP_ID,
                   SOURCE_TABLE_OWNER_NAME,
                   SOURCE_TABLE_NAME,
                   ARCHIVE_TABLE_OWNER_NAME,
                   ARCHIVE_TABLE_NAME,
                   CONDITION_COLUMN_NAME,
                   RETENTION_VALUE,
                   RETENTION_UNIT,
                   FLAG
              FROM APPS_GLOBAL.control_table1
             WHERE GROUP_ID = 1
          ORDER BY GROUP_ID, source_table_name;
       rec    c%ROWTYPE;
    BEGIN
       FOR rec IN C
       LOOP
    stmt := 'INSERT INTO '
             || rec.ARCHIVE_TABLE_OWNER_NAME
             || '.'
             || rec.ARCHIVE_TABLE_NAME
             || '(SELECT * FROM '
             || rec.SOURCE_TABLE_OWNER_NAME
             || '.'
             || rec.SOURCE_TABLE_NAME
             || ' WHERE '
             || rec.CONDITION_COLUMN_NAME
             || '<=';
    CASE LOWER (rec.RETENTION_UNIT)
        WHEN 'd'
        THEN
         stmt:= stmt||'sysdate -'||rec.RETENTION_VALUE||')';
         ELSE
         stmt := stmt||'add_months(sysdate,'|| rec.RETENTION_VALUE||'*-12)'||')';
    END CASE;
    execute immediate stmt;
       END LOOP;
       COMMIT;
    END;
    /The values for the field RETENTION_UNIT in my control_table1 are D and Y.
    Before making the date comparison condition it was working fine.
    If I made it as dynamic why I am getting the error.
    If I use condition as below it's working fine.
    EXECUTE IMMEDIATE
                   'INSERT INTO '
                || I.ARCHIVE_TABLE_OWNER_NAME
                || '.'
                || I.ARCHIVE_TABLE_NAME
                || '(SELECT * FROM '
                || I.SOURCE_TABLE_OWNER_NAME
                || '.'
                || I.SOURCE_TABLE_NAME
                || ' WHERE '
                || I.CONDITION_COLUMN_NAME
                || '<=ADD_MONTHS(SYSDATE,-24)'
                || ')';Please help me .
    Thanks.

Maybe you are looking for