Error in to_date

Hi,
I am getting an error on the below query, in the "to_date" function part.
select *
  from rf_bankaccount_avg t
where t.month_year between
       to_char(to_date((SELECT ADD_MONTHS(LAST_DAY(SYSDATE), -7) + 1 AS FROM dual),'mm-yyyy')) and
       to_char(to_date((select last_day(sysdate - to_char(sysdate, 'DD')) from dual),'mm-yyyy'))
   and t.account_type = 1
   and t.addnl_factype_no = '0'
   and t.ret_factype = 'A'
   and t.company_bankcode = '';i am getting the error "ORA-01841: (full) year must be between -4713 and +9999, and not be 0"
Edited by: 872435 on Apr 2, 2012 2:25 AM

Hi,
You can see many mistakes more clearly if you format your code.
The part that is apparantly raising this error is:
to_char ( to_date ( ( SELECT  ADD_MONTHS ( LAST_DAY (SYSDATE)
                                        , -7
                          ) + 1     AS
                FROM    dual
            , 'mm-yyyy'
     ) There's a mistake around the keyword "AS". Either you meant to have a column alias after it, or you didn't mean to have the keyword "AS" at all.
You can see other mistakes, here, too. For example, you're calling TO_DATE on something that is already a DATE, and you're calling TO_CHAR with only 1 argument.
Whatever you're trying to do, this is a very awkward way to do it.
What are you trying to do?
Are you trying to see if t.month_year is in the 6 months ending with last month? (That is, when the query is run any time in April, 2012, do you want to find rows where t.month_year is between October, 2011 and March, 2012, inclusive?) Assuming t.month_year is a DATE, that's just
WHERE   t.month_year >= ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'), -6)
AND     t.month_year <              TRUNC (SYSDATE, 'MONTH')This assumes that t.month_year is a DATE. If it's some other data type, the solution is a little more complicated. That's to be expected; storing date information in any data type other than DATE makes things more complicated.

Similar Messages

  • ERROR IN TO_DATE FORMAT

    Hi everyone,
    As you know exists an error: ORA-01855 AM/A.M. or PM/P.M
    This error gets when you try to execute some query like this:
    SELECT TO_DATE('01-01-2009 8:01:09 P.M.','DD-MM-YYYY HH:MI:SS PM') FROM DUAL
    In this query the value of varchar is "01-01-2009 8:01:09 P.M.", finishing with P.M., that is the letter P and M follows of a dot.
    If you execute this query the error 01855 will show. Also if you change the "PM" in the format part by "P.M." the error follows showing.
    SELECT TO_DATE('01-01-2009 8:01:09 P.M.','DD-MM-YYYY HH:MI:SS P.M.') FROM DUAL
    But if you execute this query , but only changing the "P.M." in the value part by "PM" this display the correct result.
    SELECT TO_DATE('01-01-2009 8:01:09 PM','DD-MM-YYYY HH:MI:SS PM') FROM DUAL;
    Having of an input value a varchar2 with '01-01-2009 8:01:09 P.M.' as value,
    How can I convert in the format 'DD-MM-YYYY HH:MI:SS AM'?,
    This must be without deleting the dots in the "P.M." part?
    Any help will be very appreciated.
    Thank you in advance.
    Best Regards

    Your post is very confusing but I ran the following queries and both worked successfully on a 10.2.0.3 environment:
    SQL &gt; SELECT TO_DATE('01-01-2009 8:01:09 P.M.','DD-MM-YYYY HH:MI:SS P.M.') FROM DUAL;
    TO_DATE('01-01-2009
    01/01/2009 20:01:09
    SQL &gt; SELECT TO_DATE(REPLACE('01-01-2009 8:01:09 P.M.','.',''),'DD-MM-YYYY HH:MI:SS PM') FROM DUAL;
    TO_DATE(REPLACE('01
    01/01/2009 20:01:09
    SQL &gt;The first one, is one that in your post says generates an error. The second replaces the periods with nothing. However, this is conditional on no other periods being used in your date format.
    HTH!

  • Oracle error from to_date in WHERE clause but not in SELECT clause

    If I issue a query like:
    select * from view_1
    where to_date(col1, 'mm/dd/yyyy') > sysdate
    I get an ora-01858 error.
    If I issue a query like
    select to_date(col1, 'mm/dd/yyyy') from view_1
    I don't get any error.
    I've verified the data both visually and using several recommended methods( checking with translate or regular expression), but I can't seem to find any problems with the data.
    Any suggestions for what I should try next?
    cheers,
    dz

    Hi user552575,
    Very strangeNothing mystical, especially if you say that VStudyPatientData is some view. You didn't post its underlying query so one can only guess about what is going on with your queries.
    This is my hypothetical scenario and my guess of what might happen. Consider:
    SQL> create table TStudyPatientData
      2    (SomeKey,
      3     StudyDatasetItemId,
      4     StudyPatientDataValue) as
      5   select rownum,
      6          4232,
      7          '01/12/2008'
      8     from dual
      9  connect by level <= 3;
    Table created.
    SQL> -- Now, let's insert row with incorrect date
    SQL> insert into TStudyPatientData values (4, 4232, 'AA/12/2008');
    1 row created.Here is what we have in TStudyPatientData:
    SQL> select * from TStudyPatientData;
       SOMEKEY STUDYDATASETITEMID STUDYPATIE
             1               4232 01/12/2008
             2               4232 01/12/2008
             3               4232 01/12/2008
             4               4232 AA/12/2008Now, let's create one extra "lookup" table and our hypothetical view:
    SQL> create table SomeTable (x, y) as
      2  select 4232, 4 from dual;
    Table created.
    SQL> create or replace view VStudyPatientData as
      2  select a.*
      3    from TStudyPatientData a
      4   where a.SomeKey <
      5         (select b.y
      6            from SomeTable b
      7           where b.x = a.StudyDatasetItemId);
    View created.It's clear that our simple view will return three rows (row with SomeKey = 4 won't be returned):
    SQL> select * from VStudyPatientData;
       SOMEKEY STUDYDATASETITEMID STUDYPATIE
             1               4232 01/12/2008
             2               4232 01/12/2008
             3               4232 01/12/2008Now, let's see what happens about your queries. This one will succeed:
    SQL> select to_date(StudyPatientDataValue, 'MM/DD/YYYY')
      2    from VStudyPatientData
      3   where StudyDatasetItemId = 4232
      4     and StudyPatientDataValue is not null;
    TO_DATE(S
    12-JAN-08
    12-JAN-08
    12-JAN-08But this one fails, just as in your case:
    SQL> select *
      2    from VStudyPatientData
      3   where StudyDatasetItemId = 4232
      4     and StudyPatientDataValue is not null
      5     and to_date(StudyPatientDatavalue, 'MM/DD/YYYY') > sysdate;
    ERROR:
    ORA-01858: a non-numeric character was found where a numeric was expected
    no rows selectedSo how did this happen? Once we have query execution plans, the answer is obvious. Let's start with "good" query:
    SQL> explain plan for
      2  select to_date(StudyPatientDataValue, 'MM/DD/YYYY')
      3    from VStudyPatientData
      4   where StudyDatasetItemId = 4232
      5     and StudyPatientDataValue is not null;
    Explained.
    SQL> @utlxpls
    PLAN_TABLE_OUTPUT
    | Id  | Operation            |  Name              | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |                    |       |       |       |
    |*  1 |  FILTER              |                    |       |       |       |
    |*  2 |   TABLE ACCESS FULL  | TSTUDYPATIENTDATA  |       |       |       |
    |*  3 |   TABLE ACCESS FULL  | SOMETABLE          |       |       |       |
    Predicate Information (identified by operation id):
       1 - filter("SYS_ALIAS_1"."SOMEKEY"< (SELECT "B"."Y" FROM "SOMETABLE"
                  "B" WHERE "B"."X"=:B1))
       2 - filter("SYS_ALIAS_1"."STUDYPATIENTDATAVALUE" IS NOT NULL AND
                  "SYS_ALIAS_1"."STUDYDATASETITEMID"=4232)
       3 - filter("B"."X"=:B1)
    Note: rule based optimization
    20 rows selected.Take a close look at FILTER operation (with Id = 1). It filters out rows which do not satisfy subquery within a view (where a.SomeKey < (select ... )). Thus, row with incorrect date (AA/12/2008) is simply filtered out.
    But what happens with "bad" query? Let's see:
    SQL> explain plan for
      2  select *
      3    from VStudyPatientData
      4   where StudyDatasetItemId = 4232
      5     and StudyPatientDataValue is not null
      6     and to_date(StudyPatientDatavalue, 'MM/DD/YYYY') > sysdate;
    Explained.
    SQL> @utlxpls
    PLAN_TABLE_OUTPUT
    | Id  | Operation            |  Name              | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |                    |       |       |       |
    |*  1 |  FILTER              |                    |       |       |       |
    |*  2 |   TABLE ACCESS FULL  | TSTUDYPATIENTDATA  |       |       |       |
    |*  3 |   TABLE ACCESS FULL  | SOMETABLE          |       |       |       |
    Predicate Information (identified by operation id):
       1 - filter("SYS_ALIAS_1"."SOMEKEY"< (SELECT "B"."Y" FROM "SOMETABLE"
                  "B" WHERE "B"."X"=:B1))
       2 - filter(TO_DATE("SYS_ALIAS_1"."STUDYPATIENTDATAVALUE",'MM/DD/YYYY')>S
    YSDATE@! AND "SYS_ALIAS_1"."STUDYPATIENTDATAVALUE" IS NOT NULL AND
                  "SYS_ALIAS_1"."STUDYDATASETITEMID"=4232)
       3 - filter("B"."X"=:B1)
    Note: rule based optimization
    21 rows selected.Please notice the second step of the plan (with Id = 2) and the corresponding filtering predicates (especially the one I've marked bold). As we can see, TO_DATE(...) > SYSDATE predicate is evaluated at very first stage, before subquery filtering is done.
    In general, Oracle tries to evaluate single-table predicates first, before evaluating joins and subqueries. In our case, this means that Oracle tries to apply TO_DATE(...) to every row in TStudyPatientData, and it throws exception as soon as it reaches 'AA/12/2008' value.
    Of course, this is hypothetical scenario - I haven't seen your view text so the best I can do is guess.
    However, as you can see, everything is possible with views and, without seeing query plans, it can be hard to understand what is going on.
    Regards.

  • Error while using xdofx calculations in xdoxslt function

    Hi All,
    I have a requirement to subtract two dates in the rtf and display the difference in years and months. Among the two dates, one is in Date datatype and the other one is in varchar2(dff attribute).Following are the details:
    1.Start_date(Date data type) - appears as YYYY-MM-DD in the XML when the tag is printed as it is without any manipulations.
    2.End_Date(Varchar2 - dff attribute) - appears as YYYY/MM/DD HH:MI:SS in the XML whent the tag is printed as it is wihtout doing any manipulation.
    As the first step am trying to convert the varchar2 to canonical date format and then converting it to required format compatible for using date_diff function. But am facing issues. Please help me with this. The following is the code am trying to use.
    To convert end date to date format of our choice : <?xdofx:to_date(replace(substr(EndDate,1,10),’/’,’-’)||’T00:00:00.000+05:30’,'YYYY-MM-DD')?>
    To subtract end date and start date to fetch difference in years: <?xdoxslt:date_diff('y',StartDate,xdofx:to_date(replace(substr(EndDate,1,10),’/’,’-’)||’T00:00:00.000+05:30’,'YYYY-MM-DD'),$_XDOLOCALE, $_XDOTIMEZONE)?>
    Am getting an error which says xdofx used bot not declared. If I remove it, I get an error saying to_Date function not found. I belive we're not supposed to mix xdofx and xdoxslt together. Please let me know how this can be achieved.
    Am using 10.1.3.4.2 version of BIP.
    Regards,
    Divya

    according to Extended Function Support in RTF Templates - 11g Release 1 (11.1.1)
    <?xdoxslt:date_diff('y', 'YYYY-MM-DD', 'YYYY-MM-DD', $_XDOLOCALE, $_XDOTIMEZONE)?>
    This function provides a method to get the difference between two dates in the given locale. The dates must be in "yyyy-MM-dd" format. This function supports only the Gregorian calendar. The syntax is as follows: <?xdoxslt:date_diff('format', 'YYYY-MM-DD', 'YYYY-MM-DD', $_XDOLOCALE, $_XDOTIMEZONE)?> where format is the time value for which the difference is to be calculated. Valid values are:
    y - for year
    m - for month
    w - for week
    d - for day
    h - for hour
    mi - for minute
    s - for seconds
    ms - for milliseconds
    very strange for hour, minute .... and "The dates must be in "yyyy-MM-dd" format."
    but for your case
    display the difference in years and months.
    it's ok
    so
    1.Start_date(Date data type) - appears as YYYY-MM-DD in the XML when the tag is printed as it is without any manipulations.
    2.End_Date(Varchar2 - dff attribute) - appears as YYYY/MM/DD HH:MI:SS in the XML whent the tag is printed as it is wihtout doing any manipulation.
    Start_Date and End_Date must be in "yyyy-MM-dd"
    for "Start_date" - that's ok
    for End_Date we must reformat as
    concat(substring(//End_Date,1,4),'-', substring(//End_Date,6,2),'-', substring(//End_Date,9,2))
    so as result:
    - for months:
    Diff is <?xdoxslt:date_diff('m', //Start_Date, concat(substring(//End_Date,1,4),'-', substring(//End_Date,6,2),'-', substring(//End_Date,9,2)), $_XDOLOCALE, $_XDOTIMEZONE)?>
    which gives output as
    Diff is 1
    for test case
    <Start_Date>2013-01-11</Start_Date>
    <End_Date>2013/02/11 11:00:00</End_Date>
    - for years:
    Diff is <?xdoxslt:date_diff('y', //Start_Date, concat(substring(//End_Date,1,4),'-', substring(//End_Date,6,2),'-', substring(//End_Date,9,2)), $_XDOLOCALE, $_XDOTIMEZONE)?>
    which gives output as
    Diff is 3
    for test case
    <Start_Date>2013-01-11</Start_Date>
    <End_Date>2016/02/11 11:00:00</End_Date>

  • SQL query returning error in 1 db and not in other db

    database1
    Select AMT_OFF,
    COMMENT_TXT,
    COOP_AMT_OFF,
    DEAL_NO,
    DETAIL_ID,
    DETAIL_TYPE,
    MAX_QTY,
    MIN_QTY,
    PACK_QTY,
    PACK_TYPE,
    PCT_OFF,
    SEQ_NO,
    SITE_NO,
    VENDOR_ITEM
    From dealdtl
    WHERE (deal_no, site_no, seq_no) IN
    (select deal_no, site_no, seq_no
    from deal_sku
    where sku_no = 29747
    and apply_site_no = 1201
    and deal_no = dealdtl.deal_no
    and site_no = dealdtl.site_no
    and seq_no = dealdtl.seq_no)
    and min_qty <= decode(pack_type, 'P',1,'U',10)
    and (site_no, deal_no) IN
    (select site_no, deal_no
    from dealhdr
    where vendor_id = 'VNMIKE'
    --and site_no = dealdtl.site_no
    --and deal_no = dealdtl.deal_no 
    and start_dt <= to_date('12-SEP-08', tmxgbl.date_format)
    and stop_dt >= to_date('12-SEP-08', tmxgbl.date_format)
    query produces an error on to_date function ORA-01858 non numeric character found where numeric expected
    all the tables have no data in them
    i.e. if i do a
    select site_no, deal_no
    from dealhdr --0 rows
    select deal_no, site_no, seq_no
    from deal_sku--0 rows
    Select AMT_OFF,
    COMMENT_TXT,
    COOP_AMT_OFF,
    DEAL_NO,
    DETAIL_ID,
    DETAIL_TYPE,
    MAX_QTY,
    MIN_QTY,
    PACK_QTY,
    PACK_TYPE,
    PCT_OFF,
    SEQ_NO,
    SITE_NO,
    VENDOR_ITEM
    From dealdtl--o rows
    However, when the same query is executed in a different database, it does not bring up an error, same data condition 0 rows on all three tables.
    On both databases tmxgbl.date_format returns the same 'mm/dd/rr' formaty mask
    can somebody explain the reason for this please?
    Thanks
    Vijay

    still no error on the database that doesn not throw an error
    Select AMT_OFF,
    COMMENT_TXT,
    COOP_AMT_OFF,
    DEAL_NO,
    DETAIL_ID,
    DETAIL_TYPE,
    MAX_QTY,
    MIN_QTY,
    PACK_QTY,
    PACK_TYPE,
    PCT_OFF,
    SEQ_NO,
    SITE_NO,
    VENDOR_ITEM
    From dealdtl
    WHERE (deal_no, site_no, seq_no) IN
    (select deal_no, site_no, seq_no
    from deal_sku
    where sku_no = 29747
    and apply_site_no = 1201
    and deal_no = dealdtl.deal_no
    and site_no = dealdtl.site_no
    and seq_no = dealdtl.seq_no)
    and min_qty <= decode(pack_type, 'P',1,'U',10)
    and (site_no, deal_no) IN
    (select site_no, deal_no
    from dealhdr
    where vendor_id = 'VNMIKE'
    --and site_no = dealdtl.site_no
    --and deal_no = dealdtl.deal_no 
    and start_dt <= to_date('09/12/08', chr(39)||tmxgbl.date_format||chr(39))
    and stop_dt >= to_date('09/12/08', chr(39)||tmxgbl.date_format||chr(39))
    --and start_dt <= to_date('12-SEP-08', 'CRAP')
    --no error                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Problem with to_date('date_char') in a where clause

    A little confused with this plsql error.
    This code works...
    select to_date(value,'dd/mm/yy') from kip_lov where domain='MODULE START1'
    If I try to put the "to_date(value,'dd/mm/yy')" expression in the where clause I get an invalid year error,
    select to_date(value,'dd/mm/yy') from kip_lov where domain='MODULE START1'
    AND to_date(value,'dd/mm/yy') = SYSDATE
    "Error report:
    SQL Error: ORA-01841: (full) year must be between -4713 and +9999, and not be 0"
    The variable "value" is a varchar2 in the format dd/mm/yy.
    Note: the following code also works fine,
    select to_date(value,'dd/mm/yy') - sysdate from kip_lov where domain='MODULE START1'
    I have modified my lov table so that it uses the date type now and it works fine. Just curious as to why the above example does not work.
    Sam.

    check your table description and values first, is there any dd/mm/yy or mm/dd/yy confliction
    A scenario which runs.
    SQL> desc trya
    Name Null? Type
    UPDATED_ON DATE
    UPD VARCHAR2(8)
    SQL> select * from trya
    2 ;
    UPDATED_O UPD
    31-JUL-06 31/07/06
    31-JUL-06 31/07/06
    31-JUL-06 31/07/06
    31-JUL-06 31/07/06
    31-JUL-06 31/07/06
    31-JUL-06 31/07/06
    31-JUL-06 31/07/06
    31-JUL-06 31/07/06
    31-JUL-06 31/07/06
    31-JUL-06 31/07/06
    31-JUL-06 31/07/06
    UPDATED_O UPD
    31-JUL-06 31/07/06
    31-JUL-06 31/07/06
    13 rows selected.
    SQL> SELECT * FROM trya WHERE TO_CHAR(TO_DATE(upd,'dd/mm/yy'))=SYSDATE;
    no rows selected
    SQL> SELECT * FROM trya WHERE TO_DATE(upd,'dd/mm/yy')=SYSDATE;
    no rows selected
    SQL>
    NO error on both syntax
    rgds,
    Rup

  • Date datatype in source and destinattion. But format is different in source

    Hi
    I have a proc that loads data from source table to destination table.
    In the source table, I see the date is stored as yyyy/mm/dd. When i try to load from this source to destination, I get the following error:
    SQLCODE -1861 SQLERRM ORA 01861 Literal string does not match the format string.Is there a way that I load from source to destination irrespective of the way date format used in source?
    I cant do :
    insert into destinationtable(datecol)
    (select date1 from sourcetable)I get the above mentioned error.
    Any help???

    Hi,
    So date1 is a VARCHAR2 column, that's supposed to represent a date in 'yyyy/mm/dd' format, but sometimes contains text that is not in that format: is that the problem?
    Here's a package function I've used for similar problems:
    --          **   t o _ d t   **
    --          to_dt attempts to convert in_txt to a DATE using in_fmt_1_txt.
    --          If that fails, it tries again, using in_fmt_2_txt.
    --          If that fails, it tries again, using in_fmt_3_txt, and so on.
    --          As soon as one conversion works, the function returns the DATE,
    --          and the remaining formats are not tried.
    --          If all the formats given fail, then NULL is returned.
    FUNCTION     to_dt
    (     in_txt          VARCHAR2                    -- string to be converted
    ,     in_fmt_1_txt     VARCHAR2     DEFAULT     'DD-Mon-YYYY'     -- 1st format to try
    ,     in_fmt_2_txt     VARCHAR2     DEFAULT NULL          -- 2nd format to try
    ,     in_fmt_3_txt     VARCHAR2     DEFAULT NULL          -- 3rd format to try
    ,     in_fmt_4_txt     VARCHAR2     DEFAULT NULL          -- 4th format to try
    ,     in_fmt_5_txt     VARCHAR2     DEFAULT NULL          -- 5th format to try
    RETURN     DATE
    DETERMINISTIC
    IS
         fmt_cnt          PLS_INTEGER     := 5;          -- Number of in_fmt_ arguments
         fmt_num          PLS_INTEGER     := 1;          -- Number of argument being tried
         return_dt     DATE           := NULL;     -- To be returned
    BEGIN
         WHILE     return_dt     IS NULL
         AND     fmt_num      <= fmt_cnt
         LOOP
              BEGIN     -- Block to trap conversion errors
                   return_dt := TO_DATE ( in_txt
                                       , CASE     fmt_num
                                              WHEN  1     THEN  in_fmt_1_txt
                                              WHEN  2     THEN  in_fmt_2_txt
                                              WHEN  3     THEN  in_fmt_3_txt
                                              WHEN  4     THEN  in_fmt_4_txt
                                              WHEN  5     THEN  in_fmt_5_txt
                                    END
              EXCEPTION
                   WHEN OTHERS
                   THEN
                        NULL;
              END;     -- Block to trap conversion errors
              fmt_num := fmt_num + 1;
         END LOOP;
         RETURN     return_dt;
    END     to_dt
    ;The best solution, though, is to clean up the source table.
    Identify the rows where date1 is not in 'yyyy/mm/dd' format.
    If you can figure out what the correct data should be, UPDATE to that value.
    If you can't figure out what the correct data should be, UPDATE to NULL.

  • Converting date format yyyy-mm-dd to mm/dd/yyyy

    Hi,
    I need help converting the above date format. In the database the date is stored as a VARCHAR with the format yyyy-mm-dd
    but I would like it changed to DATE with the format mm/dd/yyyy. I tried the following and I keep getting invalid month
    select To_date(date_value, 'mm/dd/yyyy') as date_value from table
    When I try to convert it to char first before converting to date I get an invalid number error
    select to_date(to_char(date_value, 'mm/dd/yyyy'), 'mm/dd/yyyy') as date_value from table
    What do I do?
    Thanks for your help!!!

    Hi,
    The second argument of TO_DATE tells what format the first argument is already in.
    So you want:
    select  To_date (date_value, 'yyyy-mm-dd') as date_value
    from    table_x;Format is a quality of strings, not DATEs. Once you have converted your string to a DATE, is is stored in the same internal format as all the other DATEs. Use TO_CHAR to display it in any format you like.
    For example:
    SELECT     TO_CHAR ( TO_DATE (date_value, 'yyyy-mm-dd')
              , 'mm/dd/yyyy'
    FROM     table_x;Things are much easier if you store dates in DATE columns.

  • Task PLP_ARIncrActivityLoad Failing

    Hi Experts,
    I am trying to configure BI Apps financial analytics on JDE EnterpriseOne 8.12. There is a task PLP_ARIncrActivityLoad which is failing and in informatica session log the error is *[TO_DATE]: invalid string for converting to Date*. Has anybody faced similar problem or know how to resolve as I can not change anything in the mapping. Please help me resolve the issue on the urgent basis.
    Thanks in advance

    Hi,
    you can configure process explorer to keep finished processes in view abit longer. That way you could find out whether the scheduled executable launches by watching process explorer when a taks is to be started.
    using process monitor, filter for events caused by the specific processname. The Process tree fucntion also allows viewing a list of processes that have ran during the trace.
    Another way around it would be embedding the current scheduled executable in some script or batch file and make it write away start and stop times  to a logfile. that way you could also be sure the scheduled task itself does launch.
    MCP/MCSA/MCTS/MCITP

  • Start and End Date Validation

    OK I am lost and searched and made changes to what I am doing, but not sure I have datasets correct or something written wrong.
    I have two date fields on my form. A Start Date and an End Date
    I put some validation that says the Start Date/Time cannot be greater than the End Date/Time or so I think that is what it is saying. But if I put and end date in the form with a time that is an hour after the start date, it throws the error
    Here are my details and maybe I am just storing data wrong or something
    ENDDATE Validation: PL/SQL Error:
    if to_date(:P6_DTGSTART) > to_date(:P6_DTGEND)
    raise_application_error (-20001,'End Date must be Greater than Start Date.');
    end if;
    When I look at the data stored in the Database in SQL Workshop this is what I see
    DTGSTART 11/29/2010
    DTGEND
    The input on the form is a Date Picker with format: DD-MON-YYYY HH24:MI
    So the entry in the form would like like:
    Start Date/Time 29-NOV-2010 09:25
    End Date/Time 29-NOV-2010 10:25
    The End date can be the same date but the time has to be greater than the start date/time
    Thanks
    Wally

    It is working better for sure, but after it is saved, I can go back and make the end date less than the start date and it accepts the save. I don't really anticipate this happening, but trying to plan for all eventualities.

  • Rrplease give me assistance to build correct query

    Hi,
    I wrote query for getting rows from previous year April to now onwards(current date).But it won't works.I don't know how to solve this problem.Please help to change this query
    SELECT IN_TOTCHLD, IN_TOTHS
    FROM PLSPLIDT_TB
    WHERE
    to_char(to_date(DT_DATE,'dd/mm/yyyy')) between
    case when
    TO_CHAR(TO_DATE('29/04/2009','DD/MM/YYYY'),'mm')<4 then to_date('Apr' || to_char(to_number( to_char('29/04/2009','YYYY')) - 1),'MonYYYY')
    when
    TO_CHAR(TO_DATE('29/04/2009','DD/MM/YYYY'),'mm')>=4 then to_date('Apr' || to_char(to_number(to_char('29/04/2009','YYYY'))),'MonYYYY')
    end
    AND TO_CHAR(TO_DATE('29/04/2009','DD/MM/YYYY'))
    Regards,
    Rajendar.
    Edited by: Rajendar Are on Apr 28, 2009 11:52 PM

    hi Vinay,
    DT_DATE DATE(7)
    In my table all this fields are stored like this format *04/22/2009 12:00:00 AM*
    my java parmeter give rptdate=*29/04/2009* as java string
    Query
    SELECT IN_TOTCHLD
    FROM PLSDTA_DTLS_TB
    WHERE TO_DATE(DT_DATE,'DD-MM-YYYY') BETWEEN
    (CASE WHEN TO_CHAR(to_date(rptdate,'DD-MM-YYYY'),'MM') <=3 THEN
    TO_DATE('01-04-' || TO_CHAR(rptdate,'YYYY') - 1,'DD-MM-YYYY')
    ELSE TO_DATE('01-04-' || TO_CHAR(rptdate,'YYYY'),'DD-MM-YYYY')
    END)
    AND TO_DATE(rptdate,'DD-MM-YYYY')
    yet it gives error at
    TO_DATE('01-04-' || TO_CHAR(rptdate,'YYYY') - 1,'DD-MM-YYYY')
    ELSE TO_DATE('01-04-' || TO_CHAR(rptdate,'YYYY'),'DD-MM-YYYY')
    above 2 lines.
    regards,
    Rajendar

  • Sql query to get number of days monthwise

    Hi,
    i am new to sql, can anyone please tell me query to find number of working days between two dates month wise.
    say
    firstdate last date
    21/03/2011 25/06/2011
    march april may june
    9 22 23 18

    Hi,
    918373 wrote:
    even a result like,
    stud_id month amount
    1234 MAR-11 xyz
    1234 JUL-11 ...Please post the exact output that you want.
    Do you want 'xyz' in the output, or do you want a number like 42 (2 hours * 6 weekdays in March 2011, plus 5 hpours * 6 weekdays = 12 + 30 = 42)?
    If you want 42, then post 42. Spend 5 minutes (if it comes to that much) with a calendar and a calculator to get the exact results you want.
    >
    >
    is much better,
    in that case i want it as a view, so that i can get further details from the view....Substituting your table and column names, into the query I posted earlier and replacing COUNT (*) with SUM (no_of_hours), the query is
    WITH     cntr     AS
         SELECT     LEVEL - 1     AS n
         FROM     (
                  SELECT  MAX (enddate - startdate)     AS days_in_range
                  FROM    class_dets
         CONNECT BY     LEVEL     <= 1 + days_in_range
    SELECT       x.stud_id
    ,       TO_CHAR ( TRUNC (x.startdate + c.n, 'MONTH')
                , 'fmMonth YYYY'
                )               AS month
    ,       SUM (no_of_hours)          AS total_hours
    FROM       class_dets  x
    JOIN       cntr        c  ON   x.enddate >= x.startdate + c.n
    WHERE       TO_CHAR ( x.startdate + c.n
                  , 'DY'
                , 'NLS_DATE_LANGUAGE=ENGLISH'     -- If necessary
                )      NOT IN ('SAT', 'SUN')
    GROUP BY  x.stud_id
    ,            TRUNC (x.startdate + c.n, 'MONTH')
    ORDER BY  x.stud_id
    ,            TRUNC (x.startdate + c.n, 'MONTH')
    ;The output, with the sample data you posted, is:
    `  STUD_ID MONTH                                     TOTAL_HOURS
          1234 March 2011                                         42
          1234 April 2011                                        147
          1234 May 2011                                          154
          1234 June 2011                                         154
          1234 July 2011                                          72
          1234 August 2011                                        46
          1234 September 2011                                     14
          1235 June 2011                                          36
          1235 July 2011                                          84
          1235 August 2011                                        92
          1235 September 2011                                     88
          1235 October 2011                                       12
          1236 June 2012                                          56
          1236 July 2012                                         154
          1236 August 2012                                        14Aside from pivoting, is that what you want?
    i edited the your query,
    WITH     all_dates     AS
         SELECT     start_date + LEVEL - 1     AS a_date
         FROM     (
                   SELECT     TO_DATE ((select startdate from class_dets where stud_id=1236), 'DD/MM/YYYY')     AS start_date
                   ,     TO_DATE ((select enddate from class_dets where stud_id=1236), 'DD/MM/YYYY')     AS end_dateInstead of the 2 lines above, the query I posted had
    SELECT  MAX (enddate - startdate)     AS days_in_rangeWhy did you make that change?
    The first argument to TO_DATE is supposed to be a string. You're calling TO_DATE with this as the first argument
    (select startdate from class_dets where stud_id=1236)which is a DATE, not a string.
                   FROM     dual
         CONNECT BY     LEVEL     <= end_date + 1 - start_date
    SELECT     TO_CHAR ( TRUNC (a_date, 'MONTH')
              , 'fmMonth YYYY'
              )               AS month
    ,     COUNT (*) * (select fee from class_dets where stud_id=1236) * (select no_of_hours from class_dets where stud_id=1236)               AS amount
    FROM     all_dates
    WHERE     a_date - TRUNC (a_date, 'IW')     < 5
    GROUP BY TRUNC (a_date, 'MONTH')
    ORDER BY TRUNC (a_date, 'MONTH')
    it works very well, but instead of specifying stud_id as 1236,
    but when i say,
    WITH     all_dates     AS
         SELECT     start_date + LEVEL - 1     AS a_date
         FROM     (
                   SELECT     TO_DATE ((select startdate from class_dets where stud_id=cd.stu_id), 'DD/MM/YYYY')     AS start_date
                   ,     TO_DATE ((select enddate from class_dets where stud_id=cd.stud_id), 'DD/MM/YYYY')     AS end_date
                   FROM     dual
         CONNECT BY     LEVEL     <= end_date + 1 - start_date
    SELECT     cd.stud_id,TO_CHAR ( TRUNC (a_date, 'MONTH')
              , 'fmMonth YYYY'
              )               AS month
    , count(*)
    ,     COUNT (*) * (select fee from class_dets where stud_id=1236) * (select no_of_hours from class_dets where stud_id=1236)               AS amount
    FROM     all_dates,class_dets cd
    WHERE     a_date - TRUNC (a_date, 'IW')     < 5
    GROUP BY TRUNC (a_date, 'MONTH'),cd.stud_id
    ORDER BY TRUNC (a_date, 'MONTH'),cd.stud_id
    i get error
                   SELECT     TO_DATE ((select startdate from class_dets where stud_id=cd.stu_id), 'DD/MM/YYYY')     AS start_date
    ERROR at line 6:
    ORA-00904: "CD"."STU_ID": invalid identifierThere's no column called stu_id in class_dets. There is a column called stud_id (with 2 'd's).
    >
    what should i do?
    (sorry about the query format...how display query in a formatted way? )This site noramlly compresses whitespace.
    Whenever you post formatted text (including, but not limited to, code) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Check my coding

    Hello Everybody,
    Please check my coding & solved my error.
    CREATE OR REPLACE PACKAGE BODY DISA_OWNER.PS_MDM_STAGING_COLOR_C
    IS
        NAME:       PS_MDM_INTERFACE_COLOR_C
        PURPOSE:    The package is used to process Merchandise Hierarchy into
                       DISA.XREF_LEGACY_GOLD_SUB_DEPT, DISA.XREF_LEGACY_GOLD_SUB_CLASS
                    and GOLD.INTOBJ
        REVISIONS:
        Ver        Date        Author             Description
        1.0        06/15/2011  Chada Changchit    Created this package body.
        -- Global constants
        gk_package_name            CONSTANT VARCHAR2(30) := 'ps_mdm_staging_color_c';
        -- Log information
        lr_run_log_rec            run_log%ROWTYPE;
        ln_run_log_id            run_log.run_log_id%TYPE;
        ln_end_log_status        NUMBER;
        lr_error_log_rec        error_log%ROWTYPE DEFAULT NULL;
        v_log_success            disa_params.char_val%TYPE := get_param_char ('RUN LOG SUCCESS');
        v_log_failure            disa_params.char_val%TYPE := get_param_char ('RUN LOG FAILURE');
    BEGIN
    PROCEDURE  process_all
    IS
        NAME:       PROCESS_ALL (Procedure)
        PURPOSE:    This is the driving procedure for processing Merchandise Hierarchy
                    into DISA.XREF_LEGACY_GOLD_SUB_DEPT, DISA.XREF_LEGACY_GOLD_SUB_CLASS
                    and GOLD.INTOBJ based on AUDIT_STATUS.
        REVISIONS:
        Ver        Date        Author             Description
        1.0        06/15/2011  Chada Changchit    Created this procedure.
        -- Log information (seperate from package variables)
        lra_run_log_rec          run_log%ROWTYPE;
        lna_run_log_id           run_log.run_log_id%TYPE;
        lna_end_log_status       NUMBER;
        lra_error_log_rec        error_log%ROWTYPE DEFAULT NULL;
    BEGIN
        --  Set Run Log ID
        BEGIN
            lra_run_log_rec.module_name := 'PS_MDM_INTERFACE_COLOR_C.PROCESS_ALL';
            lra_error_log_rec.specific_location := 'Creating RUN_LOG entry';
            lna_run_log_id := ps_disa_log_util.log_run_start (lra_run_log_rec);
        EXCEPTION
            WHEN OTHERS THEN
                RAISE;
        END;
         -- Load and process class
        lra_error_log_rec.specific_location := 'Load and process class';
        load_color;
        -- Log Successful Run
        lra_run_log_rec.end_code := v_log_success;
        lna_end_log_status       := ps_disa_log_util.log_run_end (lra_run_log_rec);
        COMMIT;     
    EXCEPTION
        WHEN OTHERS THEN
            -- Set error Codes for Logging
            lra_error_log_rec.run_log_id  := lna_run_log_id;
            lra_error_log_rec.module_name := lra_run_log_rec.module_name;
            lra_run_log_rec.end_code      := v_log_failure;
            -- This line is used to notify the shell script of a failure.
            DBMS_OUTPUT.put_line ('FAILED');
            IF lra_error_log_rec.error_code IS NULL THEN
                lra_error_log_rec.error_code := SQLCODE;
            END IF;
            IF lra_error_log_rec.error_text IS NULL THEN
                  lra_error_log_rec.error_text := substr (SQLERRM, 1, 255);
            END IF;
            IF lra_error_log_rec.specific_location IS NULL THEN
                  lra_error_log_rec.specific_location := 'When Others';
            END IF;
            -- Log Error
            disa_err.handler (lra_error_log_rec,
                             pb_logerr => TRUE,
                             pb_reraise => TRUE,
                             pb_mark_end => TRUE
    END process_all;
    PROCEDURE load_COLOR_C
    IS
        NAME:       load_prod_division (Procedure)
        PURPOSE:    This is the driving procedure for loading prod_division into
                    DISA.mdm_staging_proddiv_c staging table.
        REVISIONS:
        Ver        Date        Author                 Description
        1.0        06/15/2011  Chada Changchit      Created this procedure.
        v_audit_log_id        audit_log.audit_log_id%TYPE;
        v_parent            mdm_staging_proddiv_c.object_parent%TYPE;
        v_line_seq            INTEGER := 1;
        CURSOR prod_COLOR_cur IS
        SELECT color_code, color_desc
        FROM   item_COLOR;
        CURSOR filter_prod_COL_cur IS
        SELECT prod_COLOR_FILE_TYPE, prod_COLOR_AUDIT_STATUS
        FROM   product_COLOR_mst
        WHERE  prod_COLOR_FILE_TYPE in (0, 10);
    BEGIN
        TMR.CAPTURE(1);
        dbms_output.put_line('load_prod_COLOR began.');
        -- Set Run Log ID
        BEGIN
            v_audit_log_id := ps_disa_audit.create_audit_log('ITEM_COLOR', 'COLOR', null,
                                    null, null, ps_disa_audit.FILE_LOADING);
            lr_run_log_rec.module_name := 'PS_MDM_INTERFACE_COLOR_C.LOAD_AUDIT_STATUS(' ||
                                            v_audit_log_id || ')';   
            lr_error_log_rec.specific_location := 'Creating RUN_LOG entry';
            ln_run_log_id := ps_disa_log_util.log_run_start (lr_run_log_rec);
        EXCEPTION
            WHEN OTHERS THEN
                RAISE;
        END;
        SAVEPOINT load_AUDIT_STATUS_savepoint;
        -- Load prod_division into mdm_staging_proddiv_c table
        lr_error_log_rec.specific_location := 'Load prod_COLOR into DISA.mdm_staging_COLOR_C table.';
        FOR pd_rec IN prod_color_cur LOOP   
            INSERT INTO mdm_staging_color_c(AUDIT_LOG_ID, LINE_SEQ, STAGING_STATUS_ID, COLOR_CODE, COLOR_DES)
            VALUES (v_audit_log_id, v_line_seq, PS_DISA_STAGING.PROCESSING, pd_rec.COLOR_CODE, pd_rec.COLOR_DEC);
            v_line_seq := v_line_seq + 1;
        END LOOP;
       END load_color_c;
    PROCEDURE process_COLOR_C (
        p_audit_log_id        IN   audit_log.audit_log_id%TYPE
    IS
        NAME:       process_prod_division (Procedure)
        PURPOSE:    This is the driving procedure for processing prod_division into
                    GOLD.INTOBJ interface table.
        REVISIONS:
        Ver        Date        Author                 Description
        1.0        06/15/2011  Chada Changchit      Created this procedure.
        v_rec_count   INTEGER;
    BEGIN
        TMR.CAPTURE(2);
        dbms_output.put_line('process_color_c began.');
        -- Set Run Log ID
        BEGIN
            PS_DISA_AUDIT.set_audit_log_status(p_audit_log_id, ps_disa_audit.DATA_INTERFACING);
            lr_run_log_rec.module_name := 'PS_MDM_INTERFACE_COLOR_C.PROCESS_PROD_COLOR(' ||
                                            p_audit_log_id || ')';   
            lr_error_log_rec.specific_location := 'Creating RUN_LOG entry';
            ln_run_log_id := ps_disa_log_util.log_run_start (lr_run_log_rec);
        EXCEPTION
            WHEN OTHERS THEN
                RAISE;
        END;
        SAVEPOINT process_pd_savepoint;
        -- count the number of records we expect to insert
        lr_error_log_rec.specific_location := 'Count records.';
        SELECT    COUNT(*)
        INTO    v_rec_count
        FROM    mdm_staging_color_c
        WHERE    audit_log_id = p_audit_log_id
        AND        staging_status_id = PS_DISA_STAGING.PROCESSING;
        -- Interface into GOLD.
        lr_error_log_rec.specific_location := 'Process prod_color into GOLD.INTOBJ table.';
        INSERT INTO INTVARIANTE
            (VAFTYPEX,VAFUAREX,VAFCDI,VAFVALEX,VAFCIS,VAFLANGUE,VAFLIBC,VAFLIBL.VAFACT,VAFFLAG,VAFLGFI,VAFTRT,VAFDTRT,VAFDCRE,VAFDMAJ,VAFUTIL,VAFFICH,VAFNLIG,VAFNERR,VAFMESS)
        SELECT PROD_COLOR_CODE,                 --OBFCEXTIN        Object interface #
            COLOR_DES                       --OBFCEXT        Object #
            1,                                        --OBFIDSTR        Merchandise structure #
            2,                                        --OBFIDNIV        Object depth
            'US',                                    --OBFLANGUE        Language #
            DESCRIPTION,                            --OBFODESC        Object description
            OBJECT_PARENT,                            --OBFCEXTINP    Parent interface #
            1,                                        --OBFPRINT        Visible or hidden level
            TO_DATE('01/01/2011', 'mm/dd/yyyy'),    --OBFDDEB        Link start date
            5,                                        --OBFFLAG        Flag
            v_rec_count,                            --OBFLGFI        File total number of lines
            0,                                        --OBFTRT        Processing indicator
            TRUNC(sysdate),                            --OBFDTRT        Processing date
            sysdate,                                --OBFDCRE        Date of creation
            sysdate,                                --OBFDMAJ        Date of last update
            'PROD_COLOR',                                --OBFUTIL        Last user
            'PROD_COLOR_'||AUDIT_LOG_ID,                --OBFFICH        Filename
            LINE_SEQ,                                --OBFNLIG        File line #
            null,                                    --OBFNERR        Error message #
            null,                                    --OBFMESS        Error message
            TO_DATE('12/31/2049', 'mm/dd/yyyy')        --OBFDFIN        Link end date
        FROM mdm_staging_color_c
        WHERE audit_log_id = p_audit_log_id
        AND    staging_status_id = PS_DISA_STAGING.PROCESSING;
        -- Mark the interfaced item as processed.
        lr_error_log_rec.specific_location := 'Mark prod_division items as processed.';
        UPDATE mdm_staging_color_c
        SET staging_status_id = PS_DISA_STAGING.PROCESSED
        WHERE audit_log_id = p_audit_log_id AND
            staging_status_id = PS_DISA_STAGING.PROCESSING; 
    PROCEDURE load_color
    IS
        NAME:       load_dept (Procedure)
        PURPOSE:    This is the driving procedure for loading department into
                    DISA.mdm_staging_dept_c staging table.
        REVISIONS:
        Ver        Date        Author                 Description
        1.0        06/15/2011  Chada Changchit      Created this procedure.
        v_audit_log_id        audit_log.audit_log_id%TYPE;
        v_line_seq            INTEGER := 1;  
        -- Load department into mdm_staging_dept_c table
        lr_error_log_rec.specific_location := 'Load department into DISA.mdm_staging_color_c table.';
        FOR dept_rec IN color_ccur LOOP
            INSERT INTO mdm_staging_color_c(AUDIT_LOG_ID, LINE_SEQ, STAGING_STATUS_ID, COLOR_CODE, COLOR_DEC)
            VALUES (v_audit_log_id, v_line_seq, PS_DISA_STAGING.PROCESSING, COLOR_CODE,COLOR_DEC);
            v_line_seq := v_line_seq + 1;
        END LOOP;
    PROCEDURE process_color (
        p_audit_log_id        IN   audit_log.audit_log_id%TYPE
    IS
        NAME:       process_dept (Procedure)
        PURPOSE:    This is the driving procedure for processing department into
                    GOLD.INTOBJ interface table.
        REVISIONS:
        Ver        Date        Author                 Description
        1.0        06/15/2011  Chada Changchit      Created this procedure.
        v_rec_count        INTEGER;
    BEGIN
        TMR.CAPTURE(4);
        dbms_output.put_line('process_dept began.');
        -- Set Run Log ID
        BEGIN
            PS_DISA_AUDIT.set_audit_log_status(p_audit_log_id, ps_disa_audit.DATA_INTERFACING);
            lr_run_log_rec.module_name := 'PS_MDM_INTERFACE_COLOR_C.PROCESS_COLOR(' ||
                                            p_audit_log_id || ')';   
            lr_error_log_rec.specific_location := 'Creating RUN_LOG entry';
            ln_run_log_id := ps_disa_log_util.log_run_start (lr_run_log_rec);
        EXCEPTION
            WHEN OTHERS THEN
                RAISE;
        END;
        SAVEPOINT process_dept_savepoint;
        -- count the number of records we expect to insert
        lr_error_log_rec.specific_location := 'Count records.';
        SELECT    COUNT(*)
        INTO    v_rec_count
        FROM    mdm_staging_color_c
        WHERE    audit_log_id = p_audit_log_id
        AND        staging_status_id = PS_DISA_STAGING.PROCESSING;
        -- Interface into GOLD.
        lr_error_log_rec.specific_location := 'Process department into GOLD.INTOBJ table.';
        -- Mark the interfaced item as processed.
        lr_error_log_rec.specific_location := 'Mark department items as processed.';
        UPDATE mdm_staging_color_c
        SET staging_status_id = PS_DISA_STAGING.PROCESSED
        WHERE audit_log_id = p_audit_log_id AND
            staging_status_id = PS_DISA_STAGING.PROCESSING; 
        -- Set Run Log ID
        BEGIN
            v_audit_log_id := ps_disa_audit.create_audit_log('COLOR_CODE', 'COLOR_DEC', null,
                                    null, null, ps_disa_audit.FILE_LOADING);
            lr_run_log_rec.module_name := 'PS_MDM_INTERFACE_COLOR_C.LOAD_SUB_DEPT(' ||
                                            v_audit_log_id || ')';   
            lr_error_log_rec.specific_location := 'Creating RUN_LOG entry';
            ln_run_log_id := ps_disa_log_util.log_run_start (lr_run_log_rec);
        EXCEPTION
            WHEN OTHERS THEN
                RAISE;
        END;
        SAVEPOINT load_color_savepoint;
        END LOOP;
        FOR filter_subdept_rec IN filter_subclass_cur LOOP
            INSERT INTO mdm_staging_subclass_c(AUDIT_LOG_ID, LINE_SEQ, STAGING_STATUS_ID, COLOR_CODE,COLOR_DEC)
            VALUES (v_audit_log_id, v_line_seq, PS_DISA_STAGING.FILTERED, COLOR_CODE,COLOR_DECL);
            v_line_seq := v_line_seq + 1;
        END LOOP;
    PROCEDURE process_COLOR_C (
        p_audit_log_id        IN   audit_log.audit_log_id%TYPE
    IS
        NAME:       process_sub_dept (Procedure)
        PURPOSE:    This is the driving procedure for processing sub-department into
                    GOLD.INTOBJ interface table.
        REVISIONS:
        Ver        Date        Author                 Description
        1.0        06/15/2011  Chada Changchit      Created this procedure.
        v_rec_count        INTEGER;
    BEGIN
        TMR.CAPTURE(6);
        dbms_output.put_line('process_color began.');
        -- Set Run Log ID
        BEGIN
            PS_DISA_AUDIT.set_audit_log_status(p_audit_log_id, ps_disa_audit.DATA_INTERFACING);
            lr_run_log_rec.module_name := 'PS_MDM_INTERFACE_COLOR_C.PROCESS_COLOR(' ||
                                            p_audit_log_id || ')';   
            lr_error_log_rec.specific_location := 'Creating RUN_LOG entry';
            ln_run_log_id := ps_disa_log_util.log_run_start (lr_run_log_rec);
        EXCEPTION
            WHEN OTHERS THEN
                RAISE;
        END;
        SAVEPOINT process_color_savepoint;
        -- Merge sub-department into DISA.xref_legacy_gold_sub_dept table
        lr_error_log_rec.specific_location := 'Merge sub-department into DISA.xref_legacy_gold_color table.';
        MERGE INTO xref_legacy_gold_color
        USING (
            SELECT COLOR_CODE,COLOR_DES;
            FROM mdm_staging_color_c
            WHERE staging_status_id = PS_DISA_STAGING.PROCESSING
        ) a
        ON(xref_legacy_gold_color.color_code= a.color_code)
        WHEN NOT MATCHED THEN
            INSERT (COLOR_CODE,COLOR_DEC) VALUES (a.COLOR_CODE, a.COLOR_DEC)
        WHEN MATCHED THEN
            UPDATE SET
                COLOR_CODE = a.COLOR_CODE,
                LAST_UPDATE_SOURCE = user,
                LAST_UPDATE_DATE = sysdate;
        -- count the number of records we expect to insert
        lr_error_log_rec.specific_location := 'Count records.';
        SELECT    COUNT(*)
        INTO    v_rec_count
        FROM    mdm_staging_color_c
        WHERE    audit_log_id = p_audit_log_id
        AND        staging_status_id = PS_DISA_STAGING.PROCESSING;
    PROCEDURE load_color
    IS
        NAME:       load_clolor(Procedure)
        PURPOSE:    This is the driving procedure for loading class into
                    DISA.mdm_staging_color_c staging table.
        REVISIONS:
        Ver        Date        Author                 Description
        1.0        06/15/2011  Chada Changchit      Created this procedure.
        v_audit_log_id        audit_log.audit_log_id%TYPE;
        v_line_seq            INTEGER := 1;
        CURSOR color_cur IS
        SELECT DISTINCT a.color_code, a.color_des, c.sobcextin
        FROM   color_c a, xref_legacy_gold_color_code b, STRUCOBJ c
        WHERE  a.color_code = b.color_des
        AND    a.color_code not IN (0, 1169)
        AND    NOT EXISTS (SELECT 1 FROM class_mst WHERE class_des = a.class_des and color_des IN (0, 990, 993))
        AND    c.sobidstr = 1
        AND    c.sobidniv = 4;
        CURSOR filter_color_cur IS
        SELECT DISTINCT a.color_code, a.color_des
        FROM   color_code a, xref_legacy_gold_color_dec b
        WHERE  a.color_code = b.color_des
        AND    a.class_num IN (0, 1169)
        OR     EXISTS (SELECT 1 FROM color_mst WHERE class_des = a.color_code and color_des IN (0, 990, 993));
    BEGIN
        TMR.CAPTURE(7);
        dbms_output.put_line('load_color began.');
        -- Set Run Log ID
        BEGIN
            v_audit_log_id := ps_disa_audit.create_audit_log('COLOR_CODE', 'COLOR_DES', null,
                                    null, null, ps_disa_audit.FILE_LOADING);
            lr_run_log_rec.module_name := 'PS_MDM_INTERFACE_COLOR_C.LOAD_CLASS(' ||
                                            v_audit_log_id || ')';   
            lr_error_log_rec.specific_location := 'Creating RUN_LOG entry';
            ln_run_log_id := ps_disa_log_util.log_run_start (lr_run_log_rec);
        EXCEPTION
            WHEN OTHERS THEN
                RAISE;
        END;
        SAVEPOINT load_class_savepoint;
        END LOOP;
    PROCEDURE process_class (
        p_audit_log_id        IN   audit_log.audit_log_id%TYPE
    IS
        NAME:       process_class (Procedure)
        PURPOSE:    This is the driving procedure for processing class into
                    GOLD.INTOBJ interface table.
        REVISIONS:
        Ver        Date        Author                 Description
        1.0        06/15/2011  Chada Changchit      Created this procedure.
        v_rec_count        INTEGER;
        SAVEPOINT process_color_savepoint;
        -- count the number of records we expect to insert
        lr_error_log_rec.specific_location := 'Count records.';
        SELECT    COUNT(*)
        INTO    v_rec_count
        FROM    mdm_staging_color_c
        WHERE    audit_log_id = p_audit_log_id
        AND        staging_status_id = PS_DISA_STAGING.PROCESSING;
        -- Interface into GOLD.
        lr_error_log_rec.specific_location := 'Process class into GOLD.INTOBJ table.';
    PROCEDURE load_color_des
    IS
        NAME:       load_sub_class (Procedure)
        PURPOSE:    This is the driving procedure for loading sub-class into
                    DISA.mdm_staging_subdept_c staging table.
        REVISIONS:
        Ver        Date        Author                 Description
        1.0        06/15/2011  Chada Changchit      Created this procedure.
        v_audit_log_id        audit_log.audit_log_id%TYPE;
        v_line_seq            INTEGER := 1;
        v_subclass_seq        INTEGER := 10001;
        CURSOR color_des_cur IS
        SELECT DISTINCT a.class_code, a.color_des, b.sobcextin
        FROM   color_c a, STRUCOBJ b
        WHERE  a.color_code = b.sobcext
        AND    a.color_code not IN (0, 1169)
        AND    NOT EXISTS (SELECT 1 FROM color_mst WHERE color_des = a.color_code and color_des IN (0, 990, 993))
        AND    b.sobidstr = 1
        AND    b.sobidniv = 5  -- class level
        ORDER BY a.class_code;
        CURSOR filter_color_des_cur IS
        SELECT DISTINCT a.color_code, a.color_des
        FROM   color_code a, STRUCOBJ b
        WHERE  a.color_code IN (0, 1169)
        OR     EXISTS (SELECT 1 FROM color_mst WHERE color_code = a.color_des and color_des IN (0, 990, 993));
    PROCEDURE process_color_des (
        p_audit_log_id        IN   audit_log.audit_log_id%TYPE
    IS
        NAME:       process_sub_class (Procedure)
        PURPOSE:    This is the driving procedure for processing sub-class into
                    GOLD.INTOBJ interface table.
        REVISIONS:
        Ver        Date        Author                 Description
        1.0        06/15/2011  Chada Changchit      Created this procedure.
        v_rec_count        INTEGER;
    BEGIN
        TMR.CAPTURE(10);
        dbms_output.put_line('process_color_des began.');
        -- Set Run Log ID
        BEGIN
            PS_DISA_AUDIT.set_audit_log_status(p_audit_log_id, ps_disa_audit.DATA_INTERFACING);
            lr_run_log_rec.module_name := 'PS_MDM_INTERFACE_COLOR_C.PROCESS_COLOR_DEC(' ||
                                            p_audit_log_id || ')';   
            lr_error_log_rec.specific_location := 'Creating RUN_LOG entry';
            ln_run_log_id := ps_disa_log_util.log_run_start (lr_run_log_rec);
        EXCEPTION
            WHEN OTHERS THEN
                RAISE;
        END;
        SAVEPOINT process_sub_class_savepoint;
        -- Merge sub-class into DISA.xref_legacy_gold_sub_class table
        lr_error_log_rec.specific_location := 'Merge sub-class into DISA.xref_legacy_gold_color_des table.';
        MERGE INTO xref_legacy_gold_sub_class
        USING (
            SELECT color_code, color_des
            FROM mdm_staging_color_des
            WHERE staging_status_id = PS_DISA_STAGING.PROCESSING
        ) a
        ON(xref_legacy_gold_COLOR_CODE.COLOR_DES = a.COLOR_CODE)
        WHEN NOT MATCHED THEN
            INSERT (COLOR_CODE,COLOR_DEC) VALUES (a.COLOR_CODE, a.COLOR_DEC)
        WHEN MATCHED THEN
            UPDATE SET
                COLOR_CODE = a.COLOR_DEC,
                LAST_UPDATE_SOURCE = user,
                LAST_UPDATE_DATE = sysdate;
        -- count the number of records we expect to insert
        lr_error_log_rec.specific_location := 'Count records.';
        SELECT    COUNT(*)
        INTO    v_rec_count
        FROM    mdm_staging_color_des
        WHERE    audit_log_id = p_audit_log_id
        AND        staging_status_id = PS_DISA_STAGING.PROCESSING;
    END process_color_des;
    END PS_ MDM_INTERFACE_COLOR_C ;Thank you,
    Sam
    Edited by: BluShadow on 07-Jul-2011 14:14
    added {noformat}{noformat} tags.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    869574 wrote:
    run script in Oracle toad 10.6
    Thank you,
    samNo. I, like most other people here, am busy working. If you have an issue, YOU run the script and YOU tell us what your issue is. This isn't a game where we are supposed to guess what the problem is. If you can't be bothered to post your question according the forum guidelines ({message:id=9360002}) then why on Earth should we bother to waste our time looking to help?

  • Can you merge these Statements into one statement.....if yes..........how

    Hi, I have a plsql that generates number, I would like to include one that generates date as well as strings. But adding the other select statements, I get errors
    SELECT DBMS_RANDOM.VALUE num FROM dual; [ i]this is works in my code
    works fine, but when I add this below it, then I started getting errors
    SELECT TO_DATE(TRUNC(DBMS_RANDOM.VALUE(2453742+146,2453742+176)),'J') from dual;
    or this for strings
    SELECT DBMS_RANDOM.STRING FROM DUAL;
    so can I add the two statement together
    here is my code
    declare
    Result NUMBER;
    CURSOR c_rand IS
    SELECT DBMS_RANDOM.VALUE num FROM dual;
    SELECT TO_DATE(TRUNC(DBMS_RANDOM.VALUE(2453742+146,2453742+176)),'J') from dual;
    vrm_type VARCHAR2(50);
    --CURSOR c_rand1 IS
    --SELECT DBMS_RANDOM.STRING FROM DUAL;
    begin
    dbms_loc
    k.sleep(1);
    for j in 1 .. 100 loop
    this is the error I get
    I basically want to generate, numbers, stings and dates. That is my task
    PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
    begin function package pragma procedure subtype type use
    <an identifier> <a double-quoted delimited-identifier> form
    current cursor
    Message was edited by:
    user511871

    You need a separate cursor for each select statement.
    In future try using the [PRE] and [/PRE] tages to format your code.
    Cheers, APC

  • Handling Date Format

    Hi Everyone,
    I am using DB 11g and Apex 4.1 Versions.
    We are working on a project where most of the time we would be uploading CSV through Apex and store the data in DB using some procedures developed by us and most of the time we get different date formats in the CSV which is sent by the client. It is the major issue which i encounter in my carrer.
    Please suggest me how we can handle or tell the procedure to check if one format doesn't work take another if that also doesn't work go for another.
    Any link or code or anything Please help me with this and make my career a bit more easy :)
    Thanks,
    Shoaib

    Hi, Shoaib,
    Shoaib581 wrote:
    Thanks Guys,Pay particular attention to Paul's reply. The people who enter the data are the best people to make sure it is correct. Do whatever you can to ensure valid, consistent data entry. It may be hard for users who want to use their own favorite format, but not as hard as it is to correct mistakes later.
    >
    >
    Your clarification really helped me and made many things clear for me :). Any suggestion, how we can handle if the date format comes in below formats,
    DD-MM-YY OR DD-MON-YY formats. Oracle forgives you if you use 'MON' where 'MM' was expected, so
    TO_DATE ( '1-Dec-2012'
            , 'DD-MM-YYYY'
            )returns Decemer 1, 2012: it WILL NOT raise an error.
    The converse is not true: TO_DATE (str, 'DD-Mon-YYYY') WILL raise an error if you the month part is '12'.
    Here's a package function I wrote to try various formats in turn:
    --          **   t o _ d t   **
    --     to_dt attempts to convert in_txt to a DATE using in_fmt_1_txt.
    --     If that fails, it tries again, using in_fmt_2_txt.
    --     If that fails, it tries again, using in_fmt_3_txt, and so on.
    --     As soon as one conversion works, the function returns the DATE,
    --     and the remaining formats are not tried.
    --     If all the formats given fail, then in_default_dt is returned.
    FUNCTION     to_dt
    (     in_txt          IN     VARCHAR2                    -- string to be converted
    ,     in_fmt_1_txt     IN     VARCHAR2     DEFAULT     'DD-Mon-YYYY'     -- 1st format to try
    ,     in_fmt_2_txt     IN     VARCHAR2     DEFAULT NULL          -- 2nd format to try
    ,     in_fmt_3_txt     IN     VARCHAR2     DEFAULT NULL          -- 3rd format to try
    ,     in_fmt_4_txt     IN     VARCHAR2     DEFAULT NULL          -- 4th format to try
    ,     in_fmt_5_txt     IN     VARCHAR2     DEFAULT NULL          -- 5th format to try
    ,     in_default_dt     IN     DATE          DEFAULT     NULL          -- Returned if nothing works
    RETURN     DATE
    DETERMINISTIC
    IS
         fmt_cnt          PLS_INTEGER     := 5;          -- Number of in_fmt_ arguments
         fmt_num          PLS_INTEGER     := 1;          -- Number of argument being tried
         return_dt     DATE           := NULL;     -- To be returned
    BEGIN
         FOR  fmt_num  IN  1 ..  fmt_cnt
         LOOP
              BEGIN     -- Block to trap conversion errors
                   return_dt := TO_DATE ( in_txt
                                       , CASE     fmt_num
                                              WHEN  1     THEN  in_fmt_1_txt
                                              WHEN  2     THEN  in_fmt_2_txt
                                              WHEN  3     THEN  in_fmt_3_txt
                                              WHEN  4     THEN  in_fmt_4_txt
                                              WHEN  5     THEN  in_fmt_5_txt
                                    END
                   -- If control reaches this point, then TO_DATE worked
                   RETURN     return_dt;
              EXCEPTION
                   WHEN OTHERS
                   THEN
                        IF  SQLCODE  BETWEEN -1865
                                      AND     -1839
                        THEN
                                NULL;
                        ELSE
                             RAISE;
                       END IF;
              END;     -- Block to trap conversion errors
         END LOOP;
         RETURN     in_default_dt;
    END     to_dt
    ;Once again, this will convert a string like '12/11/10' to a DATE. It will not necessarily return the same DATE that was meant by whoever entered the string.

Maybe you are looking for

  • Clearing of impersonal account items

    Hello, how can I clear impersonal account items vs. another impersonal account? Is it possible with FB05 in RFBIBL00? Regards Norbert

  • Video/Tutorial Clip playing

    Distorted/Garbled playback of sound on Video/Tutorial clips in iTunes. Picture is fine but sound is poor. Have iTunes as default media player. Am an AOL customer. Any suggestions wlecomed. Many thanks Richie

  • Cant restore from recovery mode iphone 4s

    Can't restore iphoe 4s from recovery mode. Error 21 happing every time.

  • Function SO_OBJECT_ARCHIVE_READ

    Dear Reader, I am attempting to write a program which will automatically download all files in the General folder in SAP office onto the harddrive. I use the function SO_OBJECT_DOWNLOAD to download the files after i have read them. The function SO_OB

  • Career path

    Hi all, I'm a junior-mid level Java programmer (2.5 year of Java developing). Worked mostly on backend server side using core Java, haven't actually worked on J2EE (servlets, JSP, EJB, ...) I need to look for a new opportunity as the company I'm work