TO_DATE function problem

Hello World,
I was using To_date function to update a record, and the year it is updating is getting messed up.I tried like this:
update MyTable set created_dt =
to_date('99-9-19','yy-mm-dd')
where rec_id = 106
Then the year in the database shows 2099 instead of 1999.This is happening when I was trying to update year upto 50. i.e,if I try to update with ,
to_date('50-9-19','yy-mm-dd') , it updates the year to 2050.
But if I update with year 49, it updates 1949.
When I update using the following statement,it is updating fine
update W2_01_REC set created_dt ='19-sep-99' where rec_id = 106.
With the above statement it updates the year to 1999
Could anybody tell me why it is updating differently with different statements as above.
And where we can set the date break point for such updates ot inserts in database.
Thank you in advance

Dear Gopal,
See if the following solves your problem (note the change in the format model specification):
update MyTable set created_dt =
to_date('99-09-19','RR-MM-DD')
where rec_id = 106 ;
Best of luck!
null

Similar Messages

  • ** How to use TO_DATE function in Stored Proc. for JDBC in ABAP-XSL mapping

    Hi friends,
    I use ABAP-XSL mapping to insert records in Oracle table. My Sender is File and receiver is JDBC. We use Oracle 10g database. All fields in table are VARCHAR2 except one field; this is having type 'DATE'.
    I use Stored procedure to update the records in table. I have converted my string into date using the Oracle TO_DATE function. But, when I use this format, it throws an error in the Receiver CC. (But, the message is processed successfully in SXMB_MONI).
    The input format I formed like below:
    <X_EMP_START_DT hasQuot="No" isInput="1" type="DATE">
    Value in Payload is like below.
    <X_EMP_START_DT hasQuot="No" isInput="1" type="DATE">TO_DATE('18-11-1991','DD-MM-YYYY')</X_EMP_START_DT>
    Error in CC comes as below:
    Error processing request in sax parser: Error when executing statement for table/stored proc. 'SP_EMP_DETAILS' (structure 'STATEMENT'): java.lang.NumberFormatException: For input string: "TO_DATE('18"
    Friends, I have tried, but unable to find the correct solution to insert.
    Kindly help me to solve this issue.
    Kind Regards,
    Jegathees P.
    (But, the same is working fine if we use direct method in ABAP-XSL ie. not thru Stored Procedure)

    Hi Sinha,
    Thanks for your reply.
    I used the syntax
    <xsl:call-template name="date:format-date">
       <xsl:with-param name="date-time" select="string" />
       <xsl:with-param name="pattern" select="string" />
    </xsl:call-template>
    in my Abap XSL.  But, its not working correctly. The problem is 'href' function to import "date.xsl" in my XSLT is not able to do that. The system throws an error. Moreover, it is not able to write the command 'extension-element-prefixes' in my <xsl:stylesheet namespace>
    May be I am not able to understand how to use this.
    Anyway, I solved this problem by handling date conversion inside Oracle Stored Procedure. Now, its working fine.
    Thank you.

  • To_Date function in the Where Clause

    Hello All,
    I'm having an issue using the to_date function that has me quite perplexed.
    I have two varchar2 fields, one with a date value in the format Mon, DD YYYY, the other has a time value in the format HH:MI PM.
    When I run my query one of the columns I retrieve looks like this TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM'). The two fields are concatenated together and converted to a date. This works fine.
    My problem occurs when I attempt to apply the same logic to the where clause of the aforementioned query. e.g. when I add the following criteria to my query and TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM') <= sysdate I get an ORA-01843: not a valid month error.
    To further illustrate my problem here are the two queries:
    Select d4.adate, e4.atime, TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM')
    from ....
    where ....
    The above query works.
    Select d4.adate, e4.atime, TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM')
    from ....
    where ....
    and TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM') <= sysdate
    The second query does not work.
    The tables used and the limiting criteria are identical, except for the last one.
    Does anyone have any ideas why this could be happening.
    er

    Hello,
    Check this out. It does work. Do cut n paste sample
    data from your tables.
    SQL> desc test
    Name Null? Type
    ID NUMBER
    DDATE VARCHAR2(20)
    DTIME VARCHAR2(20)
    SQL> select * from test;
    ID DDATE DTIME
    1 Jan, 10 2006 12:32 PM
    2 Mar, 11 2005 07:10 AM
    3 Apr, 13 2006 03:12 AM
    4 Nov, 15 2003 11:22 PM
    5 Dec, 20 2005 09:12 AM
    6 Oct, 30 2006 10:00 AM
    7 Jan, 10 2006 12:32 PM
    8 Apr, 11 2005 07:10 AM
    9 May, 13 2006 03:12 AM
    10 Sep, 15 2003 11:22 PM
    11 Oct, 20 2005 09:12 AM
    12 Dec, 30 2006 10:00 AM
    12 rows selected.
    SQL> select id, ddate, dtime,
    2 to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM') AA,
    A,
    3 to_char(to_date(ddate||dtime,'Mon, DD YYYYHH:MI
    MI PM'),'Mon, DD YYYYHH:MI PM') BB
    4 from test;
    ID DDATE DTIME
    DTIME AA BB
    1 Jan, 10 2006 12:32 PM
    12:32 PM 10-JAN-06 Jan, 10 200612:32 PM
    2 Mar, 11 2005 07:10 AM
    07:10 AM 11-MAR-05 Mar, 11 200507:10 AM
    3 Apr, 13 2006 03:12 AM
    03:12 AM 13-APR-06 Apr, 13 200603:12 AM
    4 Nov, 15 2003 11:22 PM
    11:22 PM 15-NOV-03 Nov, 15 200311:22 PM
    5 Dec, 20 2005 09:12 AM
    09:12 AM 20-DEC-05 Dec, 20 200509:12 AM
    6 Oct, 30 2006 10:00 AM
    10:00 AM 30-OCT-06 Oct, 30 200610:00 AM
    7 Jan, 10 2006 12:32 PM
    12:32 PM 10-JAN-06 Jan, 10 200612:32 PM
    8 Apr, 11 2005 07:10 AM
    07:10 AM 11-APR-05 Apr, 11 200507:10 AM
    9 May, 13 2006 03:12 AM
    03:12 AM 13-MAY-06 May, 13 200603:12 AM
    10 Sep, 15 2003 11:22 PM
    11:22 PM 15-SEP-03 Sep, 15 200311:22 PM
    11 Oct, 20 2005 09:12 AM
    09:12 AM 20-OCT-05 Oct, 20 200509:12 AM
    12 Dec, 30 2006 10:00 AM
    10:00 AM 30-DEC-06 Dec, 30 200610:00 AM
    12 rows selected.
    SQL> select id, ddate, dtime,
    to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
    2 from test
    3 where id > 3
    4 and to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
    ') <= trunc(sysdate);
    ID DDATE DTIME
    DTIME TO_DATE(D
    4 Nov, 15 2003 11:22 PM
    11:22 PM 15-NOV-03
    5 Dec, 20 2005 09:12 AM
    09:12 AM 20-DEC-05
    7 Jan, 10 2006 12:32 PM
    12:32 PM 10-JAN-06
    8 Apr, 11 2005 07:10 AM
    07:10 AM 11-APR-05
    10 Sep, 15 2003 11:22 PM
    11:22 PM 15-SEP-03
    11 Oct, 20 2005 09:12 AM
    09:12 AM 20-OCT-05
    6 rows selected.
    SQL> select id, ddate, dtime,
    to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
    2 from test
    3 where id > 3
    4 and to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
    ') <= sysdate;
    ID DDATE DTIME
    DTIME TO_DATE(D
    4 Nov, 15 2003 11:22 PM
    11:22 PM 15-NOV-03
    5 Dec, 20 2005 09:12 AM
    09:12 AM 20-DEC-05
    7 Jan, 10 2006 12:32 PM
    12:32 PM 10-JAN-06
    8 Apr, 11 2005 07:10 AM
    07:10 AM 11-APR-05
    10 Sep, 15 2003 11:22 PM
    11:22 PM 15-SEP-03
    11 Oct, 20 2005 09:12 AM
    09:12 AM 20-OCT-05
    6 rows selected.
    -SriSorry Sri, but I fail to see what you mean. How is what you're doing any different than what I'm doing?

  • TO_DATE Function Is not working

    Hi Friends,
    select * from view_date where to_date(my_date) between '01-dec-06' and '31-dec-06';
    This query is not responding...
    I have the the date field in character in the view so i need to convert it to date ,so that iam using to_date function and its not responding.
    Without using to_date iam getting the results but not the exact results,it includes all the record sets.
    Help me in this

    TO_DATE converts a string to a date. TO_CHAR converts a date to a string. What is my_date?
    Edit: Just realised you said "my_date" is a string.
    Try
    select * from view_date
    where   TO_DATE(my_date,'???')
            between TO_DATE('01-dec-2006','dd-mon-yyyy') and TO_DATE('31-dec-2006','dd-mon-yyyy');or if you are dealing with literals you can use the more compact ANSI format:
    select * from view_date
    where   TO_DATE(my_date,'???') between DATE '2006-12-01' and DATE '2006-12-31';Avoid 2-digit years. You have no idea the problems that caused a few years back.
    Message was edited by:
    William Robertson
    Oops, typed stuff the wrong way around, need coffee...

  • Oracle date field not comparing properly with to_date function

    Hi, i'm facing a very weird problem. I'm triyng to retrieve a range of records in between two dates. However, it doesn't seem to understand. What am i doing wrong?
    let's say my table (MYRECORD) has this (where id is varchar and date is DATE and not timestamp) :
    ID DATE
    1 22-JAN-08
    2 22-JAN-08
    3 21-JAN-10
    4 11-FEB-10
    5 11-FEB-10
    So, let's say iwanna get the records from 21st Jan 2010 :
    select
    date as ori_date from MYRECORD where
    date = to_date('21/01/2010','DD/MM/YYYY')
    1.)
    it is not returning any record at all. I'm having problems with between dates and the to_date function as well,
    so i'm trying to get the 'equal' part working first. I can't use to_char because at the end of the day,
    i need to compare between dates.
    what am i doing wrong? has this got anything to do with what kind of format is set up on the oracle server?
    running :
    SELECT value FROM v$nls_parameters WHERE parameter ='NLS_DATE_FORMAT'
    returns DD-MON-RR
    2.) how do we compare dates from the table according to our own specified format from our passed string? I only have READONLY access to this database
    so i can't set anything up.

    please run this
    select To_date(date, 'DD/MM/YYYY HH24:MI:SS') as ori_date from MYRECORDprobably you have hour minute second info in your table, to_date('01012010','DDMMYYYY') means hour, minute and second is 00:00:00 so it wont be equal.The database field type is actually 'DATE' and not datetime. I've also ran the sql you provided to show its timestamp, but it's not showing anything as far as timestamp is concerned. It's showing only the date. So does this mean it's a real date only information?
    However, it might be more efficient to do two comparisons, especially if there's an index on dt:
    WHERE   dt >= TO_DATE ('21/01/2010', 'DD/MM/YYYY')
    AND     dt <  TO_DATE ('22/01/2010', 'DD/MM/YYYY')
    Ok. If we change the range to compare it on the same day, it won't work;
    WHERE   dt >= TO_DATE ('21/01/2010', 'DD/MM/YYYY')
    AND     dt <=  TO_DATE ('21/01/2010', 'DD/MM/YYYY')this also happens if we're using BETWEEN
    this is real weird. It's supposed to work...i don't recall having this kind of issue on other databases. If that's the case,
    each time a user passes me a date string i have to somehow add another day onto its 'to' comparison date in order for things to work.
    but..i don't want to since i don't want to accidentally include the extra day's results!
    Edited by: 803998 on Oct 21, 2010 8:14 PM
    Edited by: 803998 on Oct 21, 2010 8:33 PM

  • Case sensitive field in to_date function

    update "Ab_Order" set "OrderDate" = to_date("Order Date String", 'yyyy/mm/dd)
    Here the OrderDate column is of type Date
    "Order Date String" is varchar2. Iam trying to copy the data from "Order Date String" which contains data in this format '2011/04/24' to OrderDate column to perform some date functions
    when I try to run this query it gives a error: ORA-01830: date format picture ends before converting entire input string
    So I tried to run this query by creating a test table wit 2 columns : update testtable set column1 = to_date(field1, 'yyyy/mm/dd')
    where column1 is date field and field1 is varchar2 and this worked.
    So Iam assuming this is the problem with case sensitive fieldnames . As far as i know we should include case sensitive fields in double quotes. Is there anything else to do wit the to_Date function. Can anyone please let me know how to do that.

    Hi,
    Welcome the the forum!
    882431 wrote:
    update "Ab_Order" set "OrderDate" = to_date("Order Date String", 'yyyy/mm/dd)It looks like you're missing a single-quote right before the last ')'.
    Here the OrderDate column is of type Date
    "Order Date String" is varchar2. Iam trying to copy the data from "Order Date String" which contains data in this format '2011/04/24' to OrderDate column to perform some date functions
    when I try to run this query it gives a error: ORA-01830: date format picture ends before converting entire input stringThat error occurs when when you have characters in the 1st argument that do not correspond to anything in the 2nd argument. For example:
    TO_DATE ( '30-Aug-2011 12:00'
         , 'dd-Mon-yyyy'
         )In this example, TO_DATE doesn;t know what to do with the ' 12:00' at the end of the 1st argument. According to the 2nd arguemnt, there's only supposed to be 11 characters in the string. So it raises the ORA-01830 error.
    So I tried to run this query by creating a test table wit 2 columns : update testtable set column1 = to_date(field1, 'yyyy/mm/dd')
    where column1 is date field and field1 is varchar2 and this worked.
    So Iam assuming this is the problem with case sensitive fieldnames . As far as i know we should include case sensitive fields in double quotes. Is there anything else to do wit the to_Date function. Can anyone please let me know how to do that.Case sensitive column names are a bad idea because they cause so amny problems, but I don't think this is one of those problems. It's more likely that you need to use SUBSTR (or some other string manipulation function) on "Order Date String" before using it in TO_DATE.
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables, so people can re-create the problem and test their ideas.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Always say which version of Oracle you're using.

  • Info on TO_DATE function

    After seeing many questions on TO_DATE function,I think it will be better to post
    this useful information on to_date function.please correct me if i am wrong
    anywhere in the post.
    TO_DATE :
    SYNTAX:TO_DATE(i/pstring[,i/pstringfmt[,nlsparam]])Note:Apart from third party tools which have their own default settings,the output of to_date is in the format specified by NLS_DATE_FORMAT parameter in NLS_DATABASE_PARAMETERS view.
    Note: The format that we are specifying in to_date function is the format of the i/p string
    and not the format of the o/p date.
    Ex:
    SQL> select to_date('12-JAN-2008','DD-MON-YYYY') from dual;
    TO_DATE('
    12-JAN-08
    SQL> select to_date('12-01-2008','DD-MM-YYYY') from dual;
    TO_DATE('
    12-JAN-08
    SQL> select to_date('12/01/2008','DD/MM/YYYY') from dual;
    TO_DATE('
    01-DEC-08Q) So, for to_date we have to give the format of i/p string. But in some cases, even if i give a format other than the format of i/p string, I am getting the o/p.
    Ex1. SELECT to_date('01.JAN.2008','DD-MON-YYYY') from dual;
    Ex2. SELECT to_date('01/JAN/2008','DD-MON-YYYY') from dual;
    Ex3. SELECT to_date('01-JAN-2008','DD-MM-YYYY') from dual;
    Ex4. SELECT to_date('01-JANUARY-2008','DD-MM-YYYY') from dual;A)The answer for 1 and 2 is, Oracle will not match separators(./-) in the string and format mask.
    It only matches corresponding values. space can be a separators in the format mask.
    Ex:select to_date('2008-01-01','YYYY MM DD')  from dualIn case if the i/p string does not match with the format mask, Oracle substitutes the format mask element with its alternatives and even after this, if it cannot convert the i/p string to the given format mask, then it throws an error.
    Alternate Format masks Table:
    Format Mask Alternate Format Mask
    Element       allowed in i/p String
    MM       MON,MONTH
    MON     MONTH
    MONTH MON
    YY       YYYY
    RR        RRRR
    RR         RRIn Ex3 and Ex4, we have MM in the format mask and MON (JAN), MONTH (JANUARY) in i/p string.
    According to the above table, Oracle makes an implicit substitution of alternate format mask MON or MONTH
    and hence it does not give an error. But this statement SELECT TO_DATE (’01-01-2008’,’DD-MON-YYYY’)
    FROM DUAL will always error out because according to the above given table, if you have ‘MON’ in the format mask, then only MON (JAN) or MONTH (JANUARY) is allowed in the i/p string.
    Q) Since format mask is optional, if i do not give any format mask, then How Oracle will convert the given string to a date?
    A) If we do not specify any format mask, then Oracle assumes that the string is in default date format and tries to convert it into a date.If the i/p string is not in the default date format, then it will give an error.
    Ex: Assume that the default date format is ‘DD-MON-RR’.
    Now if you execute a statement like, SELECT to_date(’01-01-2009’) from dual, it will error out since it is not in the default format and also not convertable by implicit substitution according to the implicit substitution table.
    Q)If i have time fields in the format mask and if i did not give them in the i/p string like select to_date('10-JAN-2008','DD-MON-YYYY HH24:MI:SS') from dual ,will it error out?
    A)You can omit the time fields in the i/p string, beause if nothing is provided then Oracle will implicitly take time as 00:00:00 and hence it will not give an error.
    Q)If i give some thing like select to_date('2008-05-01','DD-MM-YYYY') from dual, it errors out but if i give select to_date('2008-05','DD-MM-YYYY') from dual, then there is no problem. what is the reason for it?
    A)On seeing the format mask DD-MM-YYYY, it takes first 2 digits (20) as DD ,the next 2 digits(08) as month, the next 2 digits for year(05).After coming this far, still there is some portion(01) of the string that is not matched and hence it throws an error and once we remove ‘01’ as given in the question, it works absolutely fine.
    Edited by: Sreekanth Munagala on Feb 25, 2009 3:45 AM

    I think what Boneist is saying, and I agree, is that the answer to the first Q is misleading.
    Sreekanth Munagala wrote:
    Q)Some people have a misconception that a statement like to_date('01-01-2008','DD-MM-YYYY') will always convert the string '01-01-2008' into a date with the given format 'DD-MM-YYYY'.
    A)It might or might not .It all depends on value of NLS_DATE_FORMAT parameter in NLS_DATABASE_PARAMETERS view.Well,if the value of the parameter is 'DD-MM-YYYY'
    then the answer is 'YES' else the answer is 'NO'.The Answer should simply be "It won't". with the reason being that "the DATE datatype does not have a display format, only an internal format which is consistent regardless of how you want to display it. The format specified in the TO_DATE function relates to the format of the input string; how the date returned from that function is _displayed_ is completely independant of, and unrelated to, the TO_DATE function."

  • 9i R2.9.9 to_date function

    I exported user tables from Oracle 8i rel 2 ver 8.1.6 to
    Oracle 9i rel2.9.2 Enterprise Server on Win 2000 Server SP2
    When importing the character set was WE8ISO8859P1 and also the NChar Character set.
    The 9i Db the character set was WE8ISO8859P1 and NChar Character set was AL16UTF16.
    Every thing went fine except the to_date function gave incorrect results on the forms,reports and PLSQL*.
    I changed the NChar Character set to WE8ISO8859P1 by updating props$ and
    exported and reimported the data, but the problem persisted.
    'Alter database national character set' would not accept WE8ISO8859P1 .
    How can I fix this odd problem?

    I exported user tables from Oracle 8i rel 2 ver 8.1.6 to
    Oracle 9i rel2.9.2 Enterprise Server on Win 2000 Server SP2
    When importing the character set was WE8ISO8859P1 and also the NChar Character set.
    The 9i Db the character set was WE8ISO8859P1 and NChar Character set was AL16UTF16.
    Every thing went fine except the to_date function gave incorrect results on the forms,reports and PLSQL*.
    I changed the NChar Character set to WE8ISO8859P1 by updating props$ and
    exported and reimported the data, but the problem persisted.
    'Alter database national character set' would not accept WE8ISO8859P1 .
    How can I fix this odd problem?

  • The to_date function doesn't work ?

    Hello
    I don't know why my to_date function doesn't work on my pc.
    my statement is pretty complex so i just tried simple one
    select to_date('10-Jan-2006','dd-mon-yyyy') from dual;
    but even this one doesn't work it says it is invalid month
    howcome?
    is it because my Windows XP (not english version) doesn't recognise month Jan?
    i tried it another place it worked
    so is there any language pack / patch i need to install? ?
    so does OS matters?
    or how to fix this..please help me

    By default SQL Developer picks up it's language settings up from (on Windows) the Regional and Language Options. You can see what it has set by querying the NLS_SESSION_PARAMETERS view.
    Assuming you don't want to change to using DD-MM-YYYY formats for your months or change your regional settings on your PC, you need to tell SQL Developer which language you want, which you can do by adding the following lines to the file sqldeveloper\jdev\bin\sqldeveloper.conf:
    AddVMOption -Duser.language=en
    AddVMOption -Duser.country=US

  • How to use quarter format in "to_date()" function?

    Hi,
    I'm trying to use to_date() function with quarter format. How do I specify the format?
    For example to convert '2002 quarter 1' using the to_date function.
    I tried to_date('20021', 'YYYYQ'), and I got ORA-01820 cannot appear in date input format.
    Please help, thank you!!!

    You cannot use Q when inputting data, only when retrieving data. When inputting, you must enter a valid date. Oracle has to store a date and if you just enter a quarter, it can't figure out what date to store. See the examples below:
    SQL> -- test table:
    SQL> CREATE TABLE test_table
      2    (test_date DATE)
      3  /
    Table created.
    SQL> -- the wrong way to input:
    SQL> INSERT INTO test_table (test_date)
      2  VALUES (TO_DATE ('2002-1', 'YYYY-Q'))
      3  /
    VALUES (TO_DATE ('2002-1', 'YYYY-Q'))
    ERROR at line 2:
    ORA-01820: format code cannot appear in date input format
    SQL> -- the right way to input:
    SQL> INSERT INTO test_table (test_date)
      2  VALUES (TO_DATE ('27-OCT-2002', 'DD-MON-YYYY'))
      3  /
    1 row created.
    SQL> -- to output:
    SQL> COLUMN "Year and Quarter" FORMAT A16
    SQL> SELECT test_date,
      2         TO_CHAR (test_date, 'YYYY-Q') AS "Year and Quarter"
      3  FROM   test_table
      4  /
    TEST_DATE   Year and Quarter
    27-OCT-2002 2002-4
    1 row selected.

  • Has anyone had a problem with TapMedia File Manage on iPhone 5. I reported a WIFI functionality problem to the developer and asked for support. Instead they have been very unprofessional by name calling me instead of logically evaluate and troubleshoot th

    Has anyone had a problem with TapMedia File Manage installed on iPhone 5? I reported a WIFI functionality problem to the developer and asked for support. Instead the company has been very unprofessional by name calling me instead of logically evaluate and troubleshoot the problem

    Hi AKE1919,
    Welcome to the Support Communities!
    The following information should help you with this:
    How to report an issue with your iTunes Store, App Store, Mac App Store, or iBookstore purchase
    http://support.apple.com/kb/HT1933?viewlocale=en_US
    Cheers,
    Judy

  • To_date function not fetching the desired result.....

    Hi Gurus,
    I get varied results from the below 2 queries, I am pessimistic about using to_char instead prefer using to_date, but query doesn't seem to fetch the complete data while using the to_date but with to_char it works. Please can someone make this to_date used query below work for me.
    Main table structure:
    Column Name     ID     Pk     Null?     Data Type     Default     Histogram     Encryption Alg     Salt
    MINISTRY_CODE     1          Y     VARCHAR2 (15 Byte)          Yes          
    BILL_MONTH     2          Y     DATE          Yes          
    CUBIC     3          Y     NUMBER          Yes          
    GALLONS     4          Y     NUMBER          Yes          
    AMOUNTS     5          Y     NUMBER          Yes          
    MTR_TYPE     6          Y     CHAR (1 Byte)          Yes          1st query:
    SELECT ministry_code,
    DECODE(mtr_type, 'C','Billed Cubic',
    'G','Billed Gallons',
    'A','Billed OMR',
    'R','Collected',
    'U','Total Unpaid Bills') mtr_type,
    SUM(CASE
    WHEN mtr_type NOT IN ('C','G','A','R','U') THEN 0 WHEN to_char(bill_month,'MMYYYY') = '012011' AND mtr_type = 'C' THEN cubic
    WHEN mtr_type NOT IN ('C','G','A','R','U') THEN 0 WHEN to_char(bill_month,'MMYYYY') = '012011' AND mtr_type = 'G' THEN (gallons)
    WHEN mtr_type NOT IN ('C','G','A','R','U') THEN 0 WHEN to_char(bill_month,'MMYYYY') = '012011' AND mtr_type = 'A' THEN amounts
    WHEN mtr_type NOT IN ('C','G','A','R','U') THEN 0 WHEN to_char(bill_month,'MMYYYY') = '022011' AND mtr_type = 'R' THEN amounts
    WHEN mtr_type NOT IN ('C','G','A','R','U') THEN 0 WHEN to_char(bill_month,'MMYYYY') <= '022011' AND mtr_type = 'U' THEN amounts ELSE 0 END) January
    FROM tmp_paew_month_gafu1 WHERE ministry_code IN
    (SELECT DISTINCT ministry_code FROM tmp_paew_month_gafu GROUP BY ministry_code)
    GROUP BY ministry_code,mtr_type
    ORDER BY 1,3 DESCSAMPLE OUTPUT:
    MINISTRY_CODE MTR_TYPE JANUARY
    001 Billed Gallons 5326252
    001 Billed Cubic 24210.2363636364
    001 Total Unpaid Bills 16402.5
    001 Billed OMR 13287.36
    001 Collected 10410.508
    002 Total Unpaid Bills 12089.99
    002 Billed Cubic 0
    002 Billed OMR 0
    002 Billed Gallons 0
    002 Collected 0
    003 Total Unpaid Bills 27418.711
    2nd query:
    SELECT ministry_code,
    DECODE(mtr_type, 'C','Billed Cubic',
    'G','Billed Gallons',
    'A','Billed OMR',
    'R','Collected',
    'U','Total Unpaid Bills') mtr_type,
    SUM(CASE
    WHEN mtr_type NOT IN ('C','G','A','R','U') THEN 0 WHEN to_char(bill_month) = to_date('012011','MMYYYY') AND mtr_type = 'C' THEN cubic
    WHEN mtr_type NOT IN ('C','G','A','R','U') THEN 0 WHEN to_date(bill_month) = to_date('012011','MMYYYY') AND mtr_type = 'G' THEN (gallons)
    WHEN mtr_type NOT IN ('C','G','A','R','U') THEN 0 WHEN to_date(bill_month) = to_date('012011','MMYYYY') AND mtr_type = 'A' THEN amounts
    WHEN mtr_type NOT IN ('C','G','A','R','U') THEN 0 WHEN to_date(bill_month) = to_date('022011','MMYYYY') AND mtr_type = 'R' THEN amounts
    WHEN mtr_type NOT IN ('C','G','A','R','U') THEN 0 WHEN to_date(bill_month) <= to_date('022011','MMYYYY') AND mtr_type = 'U' THEN amounts ELSE 0 END) January
    FROM tmp_paew_month_gafu1 WHERE ministry_code IN
    (SELECT DISTINCT ministry_code FROM tmp_paew_month_gafu GROUP BY ministry_code)
    GROUP BY ministry_code,mtr_type
    ORDER BY 1,3 DESCSample OUTPUT:
    MINISTRY_CODE MTR_TYPE JANUARY
    001 Total Unpaid Bills 106062.002
    001 Billed OMR 0
    001 Billed Cubic 0
    001 Billed Gallons 0
    001 Collected 0
    002 Total Unpaid Bills 42023.243
    002 Collected 0
    002 Billed Gallons 0
    002 Billed Cubic 0
    002 Billed OMR 0
    003 Total Unpaid Bills 133260.435

    What is the sense of to_date(bill_month) in the second query?
    bill_month is already a date. to_date function will expect a character parameter and convert it in a date value.
    So what will happen? First the bill_month will be implicitely converted to a character value.
    Second this character value will be converted back to a date. You gave no format string. So both conversions will be made will your setting of nls_date_format.
    I can only guess what you really want. Perhaps you want to trunc the bill_month with trunc(bill_month,'MM').
    Please give us
    - table create script
    - insert statements for test data
    - required output for these test data
    - description of your requirements
    Edited by: hm on 22.11.2012 23:16

  • Equivalent of to_date function in Ms SQL and using it in Evaluate function

    Hi,
    I am trying to find out a function in MS SQL which is equivalent to to_date function in oracle. Please find below the advanced filter i am trying to use in OBIEE.
    Evaluate('to_date(%1,%2)' as date ,SUBSTRING(TIMES.CALENDAR_MONTH_NAME FROM 1 FOR 3)||'-'||cast(TIMES.CALENDAR_YEAR as char(4)),'MON-YYYY')>=Evaluate('to_date(%1,%2)' as date,'@{pv_mth}'||'@{pv_yr}','MON-YYYY') and Evaluate('to_date(%1,%2)' as date ,SUBSTRING(TIMES.CALENDAR_MONTH_NAME FROM 1 FOR 3)||'-'||cast(TIMES.CALENDAR_YEAR as char(4)),'MON-YYYY') <=timestampadd(sql_tsi_month,4,Evaluate('to_date(%1,%2)' as date,'@{pv_mth}'||'@{pv_yr}','MON-YYYY'))
    The statement above works fines with oracle DB with to_date function. The same statement throws an error with MS SQL since to_date is not a built in function.
    With MS SQL I tried with CAST, not sure how to pass parameters %1 and %2.
    Please help me how to use Evaluate function and passing parameters along with to_date funtion in MS SQL.
    Regards!
    RR

    Hi,
    please refer to this thread for useful information on using to_char and to_date functions of oracle in MS SQL server:
    http://database.ittoolbox.com/groups/technical-functional/sql-server-l/how-to-write-to-to_char-and-to_date-sql-server-351831
    Hope this helps.
    Thanks,
    -Amith.

  • To_date function in cursor in oracle 8i

    Please tell me how to use to_date in cursor in oracle 8i. when i m using to_date in where clause in cursor it's giving error to_date function is out of scope.

    CURSOR C1 IS
    SELECT A.XO_NO,to_char(A.XO_DATE,'dd-mm-yyyy') XO_DATE,A.TO_CITY,A.FILE_CODE F_CODE,A.ARR_DATE,A.DEP_DATE,A.VCH_TYPE_CODE,
    A.VCH_NO,A.REMARKS,A.AMOUNT,A.COMP_CODE,to_char(A.SERVICE_DATE,'dd-mm-yyyy')SERVICE_DATE,
    B.AGENT_CODE,B.ROOM_TYP_CODE,
    (B.NO_OF_SINGLE+B.NO_OF_DOUBLE*2+B.NO_OF_EX_BED+B.NO_OF_TWIN*2) NO_OF_PAX,
    B.PER_SR SNGL_BED,B.PER_DR DOUBLE_BED,B.PER_EB TWIN,B.PER_DR EXTRA_BED,B.MEAL_PLAN,
    B.EXCH_RATE,A.FILE_CODE,C.COMP_NAME
    FROM XOS_MS A,QUOT_HOTEL_DS B,AC_COMPANY_MS C
    WHERE A.COMP_CODE=B.COMP_CODE
    AND A.XO_NO=B.XO_NO
              AND A.COMP_CODE=C.COMP_CODE
    AND TRUNC(A.XO_DATE)=TO_DATE('21/03/2005','DD/MM/YYYY');

  • Sql query to_date function

    hi all,
    I am working on a project where some sql scripts are already been developed by
    someone else.
    In the code i found
    Select col_name
    from table_name
    where txn_dt between to_date(to_date('05-dec-2007') - 6) and to_date('05-dec-2007');
    I am wondering whats the usage of 2 to_date function in the where clause.
    This can be achieved using this as well:
    Select col_name
    from table_name
    where txn_dt between to_date('05-dec-2007') - 6 and to_date('05-dec-2007');
    Can anybody tell me this diff if there is any?
    Thanks
    Shane

    to_date(to_date('05-dec-2007') - 6)This is an error. Not a syntax error, but a runtime error waiting to happen.
    The inner to_date is fine (except it should have a format mask) but the outer to_date is expecting a character type and it's getting a date. So it has to be converted.
    All this depends on the nls settings which could change.
    Ideally, the code should read:
    Select col_name
    from table_name
    where txn_dt between to_date('05-dec-2007','dd-mon-yyyy') - 6 and to_date('05-dec-2007','dd-mon-yyyy');
    (on second thought...if the nls settings match this date format, it should convert without error in both to_date functions, but still...why do it?)
    Edited by: SomeoneElse on Dec 12, 2008 9:12 AM

Maybe you are looking for

  • Awesome not reading rc.lua

    I'm trying to give awesome3.1 a go, but it isn't reading my rc.lua. It just keeps the default everything. Really all I've changed is the theme. -- Include awesome libraries, with lots of useful function! require("awful") require("beautiful") -- {{{ V

  • Problem configuring front end host for weblogic cluster

    hi, I am using weblogic 8 sp4,I have a cluster of WLI servers for which i am trying to configure a front end host.I am using apache Http server 2.0.55 for the same. I copied the mod_wl_20.so file to the modules directory and added the following to ht

  • Is my  understanding of 'flow of message in XI'  is correct ?

    Hi Xi Experts    <u><b>Pl..crarify my understanding on XI full flow of message !</b></u>   If Adapter present : steps           1) Normal file  will be converted as SOAP XML by using adapter           2) Adaper will send this SOAP XML message to ICM

  • How To Use HR-API to Terminate An Employee

    I have a problem with the API-procedures hr_ex_employee_api.actual_termination_emp and hr_ex_employee_api.final_process_emp: To be able to rehire an employee the day after he/she has been terminated (sounds ugly, doesn't it :-), the final_process_dat

  • How to transfer microsoft user data to computer

    I went into best buy and they backed up all my info on a disc and i put the disc in and i have retrieved some of my stuff but cant figure out how to get the "microsoft user data" back on my computer which is all microsoft word power point, office etc