To_date function now fails

I have a package that ran successfully for years. This morning it fails with a ORA-01858: a non-numeric character was found where a numeric was expected.
It fails on the to_date function ie to_date(SYSDATE,'RRRRMMDD').
Why is it failing now and did not fail previously?

Kiran wrote:
then you have to write as to_Date(to_char('21/02/2012','RRRRMMDD'),'RRRRMMDD')NO!
just as sysdate is already a date and is not passed to to_date, the above is already a character string and is not passed to to_char.
And your format mask is wrong. '21/02/2012' is not in the format '21/02/2012'
It should be to_date(''21/02/2012','dd/mm/yyyy').

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 help

    Dear All,
    I need Output of the following query in the 'JANUARY' or 'JAN' i.e. 'MONTH' or 'MON' format. But following query is returning full date. Could any person help to get me output in MONTH or MON format but SQL should be using TO_DATE function.
    TO_DATE(to_char(trunc(ORDERED_DATE),'MONTH'),'MONTH') order_date
    Above query is failing to return desired output.
    Thanks

    For each DATE value, Oracle stores the following information: century, year, month, date, hour, minute, and second.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements001.htm#sthref116
    there are some conversion functions :
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions180.htm#i1009324
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions183.htm#i1003589
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions201.htm#i79761
    moreover, the human eye can only read character datatypes (not number or date datytypes) !
    which means, whenever you do a select sysdate from dual there will be an implicit conversion
    to character datatype to make it readable for you (according to nls_date_format) .
    alter session set nls_date_format = 'DD.MM.YYYY' ;
    select sysdate today from dual ;
    TODAY
    21.12.2008
    alter session set nls_date_format = 'YYYY.MM.DD' ;
    select sysdate today from dual ;
    TODAY
    2008.21.12So the same statement select sysdate today from dual ; will give different results on different systems,
    just depending on some initial settings !
    You ask why ? It's because you are using implicit conversion !!!
    Re: Sql Error

  • To_Date Function Question

    I am trying to update an Oracle table date column without success. My SQL string is "UPDATE mytable SET trans_date = " & now() & where order_id = " & user_text
    Oracle does not like now(). I found a function TO_DATE() but I get the message "Name 'to_date' is not declared."
    How would I go about sending the date to update Oracle 10g. I have installed
    Oracle Developer Tools for Visual Studio .NET 10.2.0.2.20.
    Any help is greatly appreciated.
    Thank you,
    Fred

    Hi Fred,
    Dealing with dates can sometimes be tricky.
    I would firstly advise to use bind variables (aka parameters) rather than "gluing" values into the statement. Here's a link to an older article I did for Oracle Magazine that discusses bind variables:
    http://www.oracle.com/technology/oramag/oracle/05-sep/o55odpnet.html
    If you use bind variables one method to update a date would be similar to:
    // create an oracle command object to use for sample
    OracleCommand cmd = con.CreateCommand();
    cmd.CommandText = "update test set date_column = :1";
    // create date object representing current time on client
    OracleDate d = new OracleDate(DateTime.Now);
    // create parameter object to use for insert
    OracleParameter p_date = new OracleParameter();
    p_date.OracleDbType = OracleDbType.Date;
    p_date.Value = d;
    // add parameter for the date
    cmd.Parameters.Add(p_date);
    // insert the date
    cmd.ExecuteNonQuery();If you do glue the value into the sql (again, I do not recommend this), you would use the to_date function with a character string representation of the date and the date format string. Something like:
    ... to_date('12/31/2007', 'MM/DD/YYYY') ...
    Also, if you are not familiar with dates in Oracle they also hold the time value as well. Something to keep in mind.
    Hope that helps a bit,
    Mark

  • 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."

  • Expose / Spaces function(s) fail to work with mouse buttons, ongoing issue

    Please see this now very old thread:
    http://discussions.apple.com/thread.jspa?threadID=2131775&start=0&start=0
    This is an issue as old as snow leopard itself. The problem varies in that it can effect spaces or expose. When using a non-apple mouse, one or more of these functions will fail to perform with a mouse button indefinitely as soon as a restart has taken place.
    In my particular case, whatever mouse button I assign to "show desktop" fails to function entirely after a restart has taken place. This remains true even if I re-apply the setting in system preferences, such as changing it to another button, or changing it to nothing, and back. I can still use keyboard shortcuts and screen corners to activate "show desktop". I can continue to use other expose and spaces features with the properly assigned mouse keys. Only one feature, in my case "show desktop", fails to function with -any- mouse button after a restart.
    To make this even more clear, this behavior has remained the same and consistent for the 14 months I've had snow leopard. It has even continued to exist after I recently removed and recreated my HFS+ partition, and re-installed OS 10.6, entirely from scratch. It did not exist whatsoever for the year and a month I had OS 10.5 leopard, before upgrading to 10.6. This behavior was +literally introduced upon installing snow leopard+. I have a razer death adder 1500 DPI mouse.
    Several others share the exact same symptoms, with only the affected expose/spaces function and mouse model differing. A sibling of mine experienced the +exact same issue+ with an entirely different mac model and the exact same model of mouse.
    As a relatively unimportant aside, certain "tricks" seem to fix the issue, but only temporarily (one involves moving the location of spaces and/or expose out of the utilities folder, another involves deleting "com.apple.symbolichotkeys.plist" from ~/Library/Preferences). Unfortunately, these tricks:
    A. always only fix the problem temporarily, the issue returns
    B. do not address whatever is causing the issue in the first place
    This is really frustrating quite a few people, as the linked-to thread can attest to. Along with the obvious, this frustration is magnified because:
    A. This issue +does not appear+ to involve terribly challenging technical difficulties (i.e., merely mouse button behaviors).
    B. This issue did not seem to exist before OS 10.6.
    C. This issue, with the previous two points above in mind, has remained unaddressed for 14-plus months - the entire duration of Mac OS 10.6 snow leopard. I myself originally figured a reasonable time for this issue to be addressed & resolved would be a matter of +a few days+, weeks at most, and at the very least, thought I'd be using these beloved features again +well over a year ago+.
    To put it frankly, what the %$#&? Why hasn't this been addressed yet?
    Message was edited by: -DrD-
    Message was edited by: -DrD-

    Anyone even care? I submitted this as feedback to apple, and haven't got a reply through that route, either.

  • Getting "Function Setcoloums failed" when Synchronising

    Hi All,
    I'm in desperate need of help.. I used to use a Sony W960i and synced it with my Outlook contacts. I now have a Blackberry 9700 and it wont sync with the address book in Outlook.. Everytime I try I get  "Function Setcoloums failed"..
    I'm running Outlook 2007 on Windows 7 with  DM V5.0.1
    Please help 

    Hello bernoo and welcome to the BlackBerry Support Community Forums.
    When you encounter this "Function Setcoloums failed" error, is it when you try to configure the sync? Is it when the sync starts? Or is it on a specific record while the sync occurs?
    Have you tried synchronizing the Calendar, Memos or Tasks? Do they sync?
    Thanks and have a great day!
    -HMthePirate
    Come follow your BlackBerry Technical Team on twitter! @BlackBerryHelp
    Be sure to click Kudos! for those who have helped you.Click Solution? for posts that have solved your issue(s)!

  • 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

  • I have three computers backing up onto the same Time Machine.  The Hard drive of one has now failed, and I'd like to restore certain items (principally photographs) to one of the other two computers.  How can I do this?

    I have three computers backing up onto the same Time Machine.  The Hard drive of one has now failed, and I'd like to restore certain items (principally photographs) to one of the other two computers.  How can I do this?

    "You can also browse the original backup disk for past backups by using "Browse other Time Machine Disks"--to see this choice, hold the Option key then click the Time Machine menu in the Finder (to see the menu, "Show Time Machine status in the menu bar" must be selected in Time Machine preferences."
    Mac 101: Time Machine

  • Advice on how to access photos on an iPad that were synced from a now failed laptop? The question stems from a need to return my current iPad having just taken delivery of a new unit. Thanks

    I am after some advice on how to access photos on an iPad that were synced from a now failed laptop? The question stems from a need to return my current iPad having just taken delivery of a new unit. Thanks

    If you have a dropbox account, there's a free app (probably more) that syncs photos to your dropbox account - picbox. 
    There's also PhotoSync that syncs photos to/from a number of different services and devices.

  • 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.

  • 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 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...

Maybe you are looking for

  • Pls help me, what happen to the itune or my ipod?

    the moment i plug my ipod into my computer, the itune update the songs and videos itself, but later on, i added something else into the itune, i update my ipod again, it doesn't work, it appear an error message said "The ipod cannot be updated. The d

  • I have lost the install disks that came with my 2011 macbook pro, do i need to pay for new disks?

    Hi Iv lost my install disks for my 2011 Macbook pro and i want to reformat my hard drive. Do i need to buy new discs? I cant find a download on the appstore so i guess i cant download it for free since i have already bought it. Any Ideas on how to re

  • Load report failed(crystal report) in client pc.

    Hi, we are getting error in crystal report 1.Load report failed.See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. Exception Text ************** CrystalDecisions.Shared.CrystalReportsException

  • How do i install my ipod classic without the cd

    i recently got a new ipod(classis 80 gb) and i had one before(ipod nano)-it broke-and when i plug it in nothing happens i've been trying dif things but i can't seem to get anywhere any help??????????

  • Work around

    Hi gurus, We have an extremely large model with about 500,000 discrete variables. We have found that most of them are from Transport Lot Size profile as we need to deliver lot sizes multiples. Does anyone know a work around to this issue?... we think