Month conversion to number

Need help guys,
i have below query
SELECT (SUBSTR(TO_CHAR(TO_DATE('JAN-2000','MM/YYYY'),'MM-RRRR'),1,9)) FROM DUAL;
this returns the output 01-2000.
If the month is in calender month then it will work correctly.
suppose if the month is not in calender month suppose if i pass ADJ-RRRR,then it should return ADJ-RRRR.How can achieve this using DECODE?

Hi,
user550686 wrote:
you query return invalid month.
The problem is we dont have valid months in that .We have a month name called 'ADJ'.
Thats where the query is failing.Sorry, I don't understand.
Using Sanjay's most recent data, both methods I suggested return what I expect you want.
with d as (
SELECT 'JAN-2000' col1 FROM DUAL union all
SELECT 'JAN-07' col1 FROM DUAL union all
SELECT 'ADJ-RRRR' col1 FROM DUAL union all
SELECT 'ADJ-2006' col1 FROM DUAL union all
SELECT 'FEB-2009' col1 FROM DUAL
SELECT  col1
,     NVL ( TO_CHAR ( to_dt ( col1
                            , 'MON-YYYY'
                 , 'MM-YYYY'
          , col1
          )               AS via_to_dt
,     CASE
          WHEN  UPPER (SUBSTR (col1, 1, 3))  IN ( 'JAN', 'FEB', 'MAR'
                                                         , 'APR', 'MAY', 'JUN'
                                    , 'JUL', 'AUG', 'SEP'
                                    , 'OCT', 'NOV', 'DEC'
          THEN  TO_CHAR ( TO_DATE ( col1
                                     , 'MON-YYYY'
                     , 'MM-YYYY'
          ELSE  col1
     END               AS via_case
FROM     d;Results:
COL1     VIA_TO_D VIA_CASE
JAN-2000 01-2000  01-2000
JAN-07   01-0007  01-0007
ADJ-RRRR ADJ-RRRR ADJ-RRRR
ADJ-2006 ADJ-2006 ADJ-2006
FEB-2009 02-2009  02-2009What results do you want?
If you want to read 'JAN-07' as 'JAN-2007', use 'RRRR' instead of 'YYYY' in the 2nd argument to TO_DATE. There's no point in using 'RRRR' in TO_CHAR.
If you want to equate ADJ with December, then instead of col1, use
REPLACE ( UPPER (col1)
        , 'ADJ'
        , 'DEC'
        )You won't need to use UPPER again, of course.

Similar Messages

  • Update was terminated - conversion no number

    dear all,
    while doing Me38 transaction , after updating the details i clicked on save.
    it saved. Again i press enter.
    i got the error 'express document: update was terminated received from author'.
    error analysis shows : conversion no number error.
    but this error is not coming in dev or qas server. it is coming only in production..
    how to rectify it ???
    waiting for reply,
    Thanks,
    Dhivya N.

    Hello Dhivya,
    This is conversion error occurs when we are trying to move numbers to a filed which cannot hold numbers.
    In st22 dump, you will find that number in "Short text".
    Go to "source code" in abap dump and check for the data type of the filed where the dump is encounter.
    Go to "chosen variable " in abap dump and you will be able to find the variable and its value.
    Thanks

  • Return the end of week date using month and week number

    Hi all,
    I am trying to find the date for end of the week using given month (201401, 201402...i.e, 2014 is year and 01,02 are months) and week number (01,02,03...) for the year. For example if my month is 201402 and week_number is 06 then it return the week_date
    as 2014-02-08. Can you please help me in writing a sql statement for this scenario.
    Thanks in advance,
    Nikhil

    Current month is irrelevant
    with dt as (
       select dateadd(day, (6-1)*7, '2014-01-01') as xwk
    select dateadd(day, 7-datepart(weekday, dt.xwk), xwk)
    from dt;
    Change the "6" in the with statement to the week of interest and 2014 to the year of interest...

  • How to add date with month after convert number to month?

    How to add date with month after convert number to month?
    Month Date Result
    24 21/11/09 24*(21/11/09)
    I want to add both the column and result should be 21/11/11
    Thanks
    Nihar

    Hmm,
    Because, you are using YYYY for '09'.
    SQL> ed
    Wrote file afiedt.buf
      1* select to_char(to_date('10/01/09','DD/MM/RRRR'),'DD/MM/YYYY') from dual
    SQL> /
    TO_CHAR(TO
    10/01/2009
    SQL> ed
    Wrote file afiedt.buf
      1* select to_char(to_date('10/01/09','DD/MM/YYYY'),'DD/MM/YYYY') from dual
    SQL> /
    TO_CHAR(TO
    10/01/0009Or with Add_months
    SQL> ed
    Wrote file afiedt.buf
      1* select to_char(add_months(to_date('10/01/09','DD/MM/YYYY'),36),'DD/MM/YYYY') from dual
    SQL> /
    TO_CHAR(AD
    10/01/0012
    SQL> ed
    Wrote file afiedt.buf
      1* select to_char(add_months(to_date('10/01/09','DD/MM/RRRR'),36),'DD/MM/YYYY') from dual
    SQL> /
    TO_CHAR(AD
    10/01/2012-Arun

  • How to get Quaters of the year if give month year and number of quarters

    My requirement is if i give the input month, year and number of quarters i want the previous quarters. Is there is any function module to get the quarters if we give month and year and number of quarters
    Thank you.

    Pradeep,
    Use the Fm TSTR_PERIODS_QUARTERS and pass the year into the IMPORT PARAM IT_YEARTAB-TSTR.
    U will get the begin & End dates of each quarter...
    reward if helpful,
    Karthik

  • Prorate absence Quota monthly based on number of days worked.

    Hi All,
    I need to Generate Absence Quota Prorated Monthly on the following criteria.
    4.5 days Per month.
    0 - 5 day = 0.5
    6-10 days = 1.5days
    11- 15 days = 2.5 days
    16-20days = 3 days
    21 - 25 = 3.5 days
    26 and above = 4.5 days
    54 Quota Yearly entitlement
    Negative Time evaluation -
    Time evaluation run at end of the month.
    If use Base Entilement as .15 / days and daily accural in Table T559L ,
    then without any PCR quota is generated but for 31 days it generates 4.65 days and people joining middle of the month is not as per the criteria mentioned above ie as per number of day worked.
    Can any one guide me with the steps and PCR's required if any.
    Thanks
    Sethu

    Hi Dinesh,
    Thanks for your response. I have already created and  assigned it in T559L. The below is the Rounding rule.
    Lower inc     Upper     Target     Rollout
    0.00000 X     0.75000      0.15000 X
    0.90000 X     1.50000      1.50000 X
    1.65000 X     2.25000      2.50000 X
    2.40000 X     3.00000      3.00000 X
    3.90000 X     4.65000      4.50000 X
    As per my earlier thread description when i make it daily accural and assign this rounding rule then for 31 days it calculates 4.65 days and for people joining middle or last week of the month it is not prorating as per the requirement,
    Thanks
    Sethu

  • Checking for month name and number in different language?

    I have to let people search for documents by date. The database is used by French-speakers as well as English-speakers. The search allows users to type in free text (because it's not just dates they might search by, though if they do type in something that's intended to be interpreted as a date, that's the only thing they're allowed to type in). So, I might get '23/Apr/2009' or '2009/04/23', for example. (I also have to allow them to submit 23.04.2009 and 23 04 2009 and any combination of the above!)
    I have written a function which breaks the string into three bits, and then I work out if each bit is a year, or a month, or a day with simple rules (eg, if it's a number between 1900 and 2400, it must be the year component).
    When it comes to the month, I do two things. One is obvious: is it a number between 1 and 12? The other is, is it a month name that appears in a list of 'allowed' month names. So my function does this at the start:
    v_validmonths := 'january,february,march,april <and so on>';
    v_validmonths := v_validmonths || ',janv,fevr,avr,mai, <and so on>';Then I do this:
        for x in 1 .. listlen(v_validmonths,',') loop
          v_probemonth := listgetat(v_validmonths,x,',');   
          if instr(lower(v_partone),v_probemonth) > 0 then
            v_month := extract (month from to_date(v_partone,'MON'));
          end if;
        end loop;   IE, I compare the first component of the string (v_partone) with the list of allowed month names. I repeat that for the other two parts of the supplied string. As you can see, if one of the parts of the supplied string matches an allowed month name, I then try to extract the month number into a variable, using Oracle's own extract function.
    And that's where my problem arises. Because although "aout" is valid French for August and is permitted by my list of valid months, the extract function fails to understand it. A simple select extract (month from to_date('AOUT','MON')) from dual, for example, gives an ORA01843 (invalid month).
    How can I get the code to work with French (and German, actually) months and month abbreviations whilst also being able to understand English ones? Is there an in-built function that would allow me to do this? Or is there some way neatly to say, 'yes: AOUT is in the list, and it's month 8' without me having to rely on the extract function to work it out?
    (I realise that the business requirement here is very peculiar and your first reaction will probably be "this is horrible!". I will absolutely agree with you! But this is the requirement as has been explicitly specified by the MD and I can't negotiate it away, sadly.)

    Hi,
    Many of Oracle's date functions allow a parameter where you can override the current NLS settings only for that function call.
    For example:
    SELECT  TO_DATE ( 'JUIL.'
                     , 'MON'
                     , 'NLS_DATE_LANGUAGE=FRENCH'
                     ) AS month
    FROM    DUAL;You could also create your own table of month names
    NAME     NUM     LANGUAGE
    JANVIER   1     FRENCH
    JANV       1     FRENCHand look up the names in this table, rather than in a string hard-coded in the function. This might be especially useful if you wanted to allow your own abbreviations or spellings (e.g., ignoring accent marks).
    Edited by: Frank Kulash on Dec 16, 2010 11:40 PM

  • Conversion of NUMBER(2) to SMALLINT

    One of our Oracle tables has some columns that are defined as NUMBER(2). When added to synchronisation, these field definitions appear as SMALLINT on the oracle lite database and allow a value of up to 32767, therefore breaking the Big Oracle column definition and resulting in synchronisation errors.
    We are changing our application code to validate that the value entered into the column does not exceed 99 but is there any other way to avoid this datatype conversion

    we have not yet tried R3 as this would require an app server upgrade in terms of the version of Red Hat, which has knock on effects to other services from the same app server, and we do not have time at the moment to look at the implications.
    I did not raise a bug as in our case it actually highlighted that our database design was wrong - the number(3) column related to the number of properties being built on a housing development, and we validly have sites with the number running into the thousands, so we just increased the column size in this case.
    My feeling is that it is related to the Java data type conversions on the client being different to oracle, and the point of the error was during the upload when the data was being unpacked into the in queues, and we got a 'value larger than specified precision' error

  • Char conversion to number

    Hai all,
    I have a colmn called Kilometers in table of datatype varchar and has got morethan 20,000 numeric records in it.. only numbers are getting stored in that column.. now am creating one more table with column called kiometres with datatype number..
    I want to insert the records of table A.Kilometres to B.Kilometres.. I tried the follwoing :
    insert into project_mileage (kilometres) select (to_number(kilometres,'9999999')) from project
    am getttin the error :
    ora-01722. invalid number.
    how can I get the records inserted..
    Thanks
    Kai

    If your data doesn't include other characters but numbers, you could rely on the implicit datatype conversion:
    SQL> create table a(a varchar2(3));
    Table created.
    SQL> create table b(b number(3));
    Table created.
    SQL> insert into a values ('1');
    1 row created.
    SQL> insert into a values ('2');
    1 row created.
    SQL> insert into a values ('3');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> insert into b select * from a;
    3 rows created.
    SQL> commit;
    Commit complete.
    SQL> select * from b;
             B
             1
             2
             3
    SQL>~ Madrid

  • Month conversion routine

    Hi All,
    I have a field applied month in an ODS and the ODS is being updated by a Flat file. The format of applied month is YYYYMM and when I upload the data I am noticing that the format that is displayed is YY/MMYY (example Flat file has 199810; the data after load is displayed as 19/9810).
    The infoobject applied month is referenced to 0calmonth and has Peri6 as a conversion routine with 7 as output length.
    Please help.

    Hi,
    You can use the following input formats for PERI6:
    MM.YYYY
    M.YYYY
    MM.YY
    M.YY
    http://help.sap.com/saphelp_nw04/helpdata/en/2b/e9a20d3347b340946c32331c96a64e/frameset.htm
    Best regards,
    Eugene

  • Days to Month Conversion

    Post Author: martin317
    CA Forum: Formula
    We are currently using Crystal Reports 10 and I am trying to convert the days to number of months. Is there a easy way to do this? 

    Post Author: yangster
    CA Forum: Formula
    there is no real way to achieve thiswhat you need to determine is what you consider a month to be ie 30 or 31 daystake your total days and divide by that constant and you will have roughly the number of months

  • IMessage, Start new conversations from number missing?

    I sign in with my Apple-ID. But then apperienlty you can choose which you will start new conversations from, hotmail or number, but that does not appear for me? Settings ---> Messages ---> Send and recieve.       PLEASE HELP ME

    This worked for me.  Turn off iMessage in Settings---> Messages. Then turn off iPhone. Restart iPhone then turn iMessage back on.   The phone number should reappear.

  • Date to Month Conversion at Query Level.

    Hi,
    I have Net due date in the Info provider.
    At query level i have to create a restricted keyfigure based on Net Due Month.
    Is there any way i can calculate Net due month at runtime and then create the restricted keyfigure using the net due month instead of using net due date directly(linke 01-10-2010 to 31 -10-2010 for october 2010).
    Thanks and Regards,
    MuraliManohar.

    Hi,
    Is there any way i can calculate Net due month at runtime and then create the restricted keyfigure using the net due month instead of using net due date directly(linke 01-10-2010 to 31 -10-2010 for october 2010).
    you can calculate , but as he said you can add in cube ,  may be for cal month you are taking som eother date field.
    in this case write one customer exist code .
    create one varaibel on netdue date with customer not ready input (if user wants to enter input then ct=reate user entry varaible with reday input by using customer exit).
    in routine wriet the code as when that varaible .
    l_s_range - high , low and give then take the month form that date
    like netdue date +0(6)-- gives month and year
          netdue date +0(2)-- gives month
    then rtestrict that variable with your keyfigure.
    Thanks & Regards,
    sathish

  • Conversion in Number

    Hi All,
    CREATE TABLE t2(a VARCHAR2(1000));
    INSERT INTO t2 VALUES (100000000000000000);
    COMMIT;
    SELECT to_number(a) FROM t2;
    --output - 1E17
    DROP TABLE t2 PURGE;
    Any way to display actual number i.e 100000000000000000 ,not 1E17 format.
    Thanks.

    in SQL*Plus use the option set numwidth.
    SQL> select to_number('100000000000000000') from dual;
    TO_NUMBER('100000000000000000')
                         1.0000E+17
    SQL> set numwidth 50;
    SQL> select to_number('100000000000000000') from dual;
                       TO_NUMBER('100000000000000000')
                                    100000000000000000
    SQL>

  • Slow conversions of Number(x) columns with getLong()

    JDK 1.3
    WLS 5.1.0 / SP10
    Solaris 8
    Oracle Type 4 drivers - classes12.zip
    I have thirty one threads like this one - only one is running (one cpu machine).
    This is a getLong() on a Number(10) column. Will changing the column to Long
    help?
    Any ideas why this is slow/bottleneck?
    I just discovered some OutOfMemoryErrors and will be fixing that.
    "ExecuteThread-291" daemon prio=5 tid=0x6a3bb0 nid=0x132 waiting on monitor [0xd
    b080000..0xdb0819e0]
    at oracle.sql.NUMBER._isPositive(NUMBER.java:2882)
    at oracle.sql.NUMBER._fromLnxFmt(NUMBER.java:2953)
    at oracle.sql.LnxLibThin.lnxsni(LnxLibThin.java:871)
    at oracle.sql.NUMBER.toLong(NUMBER.java:323)
    at oracle.sql.NUMBER.longValue(NUMBER.java:1812)
    at oracle.jdbc.dbaccess.DBConversion.NumberBytesToLong(DBConversion.java:181
    7)
    at oracle.jdbc.driver.OracleStatement.getLongValue(OracleStatement.java:3200
    at oracle.jdbc.driver.OracleResultSetImpl.getLong(OracleResultSetImpl.java:3
    35)
    at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:1432)
    Mike

    http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=article&group=weblogic.developer.interest.jdbc&item=6829&utag=
    ever have one of those days where you end up talking to yourself?
    mike
    "Mike Reiche" <[email protected]> wrote:
    >
    a developer tells me the code below works with type 4 drivers, but type
    2 driver
    complains about hte Oracle.Type.Cursor. What
    type should that be? Will java.sql.Other work?
    CallableStatement cstmt = con.prepareCall(callString);
    cstmt.registerOutParameter(1, OracleTypes.INTEGER);
    cstmt.setLong(2, 24);
    cstmt.registerOutParameter(3, OracleTypes.CURSOR);
    cstmt.execute();
    rs=(ResultSet)cstmt.getObject(3);

Maybe you are looking for