Problem with date to char conversion

Hi all!
I wonder why it does not work:

SELECT TO_DATE ('& & date1', 'DD-MON-RR'), TO_CHAR ('& date1 ',' DD - my ')
FROM DUAL;
KEPT date1;

Also I don't understand why I get "ORA-01722: invalid number." As far as I know what is happening when converting TO_NUMBER, which is not the case.

The only way I got that works is:
SELECT TO_DATE ('& & date1', 'DD-MON-RR'), TO_CHAR (TO_DATE ('& date1 ',' DD-MON-RR'), "JJ - LUN")
FROM DUAL;
KEPT date1;

But this way, it is heavier.

The expression TO_CHAR ('& date1 ',' DD - my ') turns into something like this:

TO_CHAR('01-Jan-09', 'DD-Mon')

This generates the error you mentioned:

SQL> select TO_CHAR('01-Jan-09', 'DD-Mon')
  2  from dual;
select TO_CHAR('01-Jan-09', 'DD-Mon')
               *
ERROR at line 1:
ORA-01722: invalid number
SQL>

Why? Just because TO_CHAR expected a numeric value to the first position. If you give him that, and then you will immediately hit the following error:

SQL> /
select TO_CHAR(42, 'DD-Mon')
                   *
ERROR at line 1:
ORA-01481: invalid number format model

The second position of TO_CHAR should hold some model valid number format, the date format template provided, does not represent.

Tags: Database

Similar Questions

  • Problem with string to Int conversion

    Dear friends,

    Problem with string to Int conversion

    I'll have a column where most of the values is digital. Only 4 values are not numeric.

    I have replaced the non-numeric values to numeric in order to maintain the data type.

    Grade.Grade DEAL WHEN "E4" THEN "24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' Grade.Grade OTHER END"

    This is the result as inactive

    Grade

    _0_

    _1_

    _10_

    _11_

    _12_

    _13_

    _14_

    15

    _16_

    _17_

    _18_

    _19_

    _2_

    _20_

    _21_

    _22_

    _23_

    _24_

    _3_

    _4_

    _5_

    _6_

    _7_

    _8_

    _9_

    Discount
    -            -            -

    Now I want to convert this value in digital and do some math

    So I changed the formula as below

    Cast (CASE Grade.Grade WHEN "E4" THEN "24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' Grade.Grade END as an INT. ELSE")


    Now I get the following error
    View display error
    Driver Odbc _ returned an error (SQLExecDirectW). _
    Error details
    Error codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    _State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 17001] Oracle error code: 1722, message: ORA-01722: invalid number in the OIC calling OCIStmtFetch. [nQSError: 17012] In bulk fetch failed. _ (HY000)
    SQL issued: SELECT cast (CASE Grade.Grade WHEN "E4" THEN "24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' Grade.Grade END as an int. ELSE") seen'Human Capital' 0 - Costing Manpower WHERE LENGTH (Grade.Grade CASE WHEN 'E1' THEN '20' WHEN 'E2' THEN '21' WHEN 'E3' THEN '22' WHEN "E4" THEN "23 ' ELSE Grade.Grade END) > 0 ORDER BY saw_0_

    Discount





    Could someone help me

    Concerning

    Mustafa

    Published by: Musnet on June 29, 2010 05:42

    Published by: Musnet on June 29, 2010 06:48

    Are you sure you don't have another non-digital value in your column. I want to get this filter temporarily just to check if your plaster works or not. If it works, then you can remove this filter.

  • Structure of the event: problem with data transfer

    Hello everyone,

    for three days I'm troubleshooting an issue in LabView with the event structures. I really hope someone can help here, because I can't find anything on the entire WEB.

    I had six groups of equal to a VI entry, each containing five checks enum (among others) where the user can specify some configuration of measurement data. I want the program to do is: to recognize if a any of these enum values has been changed and if yes, then submit the values containing the cluster in a subvi then calculates the wiring and affect the material of the ports. In addition, i need to submit the number of the enum element that was changed, so the program is able to clear the user input in the case of a breach (e.g. If the user sets two entries of enum control 1 meter and 2 Group 1 and then tries to set a third counter of entry to port 3, the program displays a message and deletes third entry as the number of entries of counter is limited to 2 per cluster).

    To resolve this problem, I used a structure of the event with 6 x 5 cases (change of enum value 1 Group 1 Group 1 enum value 2 change... and so on until the change in the value enum 5 Group 6).

    The problem is that if the user changes a value, the event structure reacts and performs the proper case; However VALUES of the cluster, the user changed are not subject to the SECOND time that an event occurs. It is a kind of a situation, "n-1". For example, if all five controls Enum of Group 1 are 'disabled' first and the user sets enum 3 of 'Meter entry', the structure of the event runs but submits the values previous to the Subvi (all enums 'Disabled'). When the user makes the second change, say that enum SWITCH1 to "Analog Input", the structure of the event is running again and passes the values of the FIRST user to the Subvi editing, then the Subvi gets data "enum 3 meter inlet and all other disabled enumerations.

    In easier words: if I have new values on my cluster "Kanal 1" (left side of the screenshot) and run the structure of the event, on the right side to "Kanal 1" indicator, I get the previous values (n-1).

    The structure of my event is in a while loop. If I create a timeout every 10 ms, and a loop of 250 ms the waiting time, I got the 80% chance that the recent changes are transferred to the Subvi correctly, in other cases I have a delay of the 1 step as described above. It seems to be directly based on the time that I specify the while to wait - but I can't explain it and I cannot accept a less than 100% chance to transfer the correct data, nor can I accept delays of a few seconds for each loop run. If I indicate timeout (infinite) get delayed 1-1 step values in all cases.

    When I specify cases of event to react on "all items value change" of the structure of the event behaves properly - but then I can't handle indicate which element has changed, as the CtlRef of output in case of a structure does not specify "enum 1, enum 2..." but only "Group 1".

    Does anyone have a solution to this? It is certainly a problem with the structure of the event, but I can't understand what to change.

    Thank you much in advance,

    Mr. Boiger

    This is because the terminal is read until the structure of the event runs.   Terminal is read, the event structure is waiting for an event.  The change in value.  Business events are running, but the value is the old value.

    Put the terminal inside the event.

    Or, you can display the connector called "New value" on the side left (stretching down from the border of the node 'CtrRef').  Use a wire one to come.

  • Problem with date and time

    HP Elite m9498d, Windows Vista 32-bit. Battery change, but the time and date again goes back to January 2002?

    Then, it might be a problem with the BIOS itself. Try to update the BIOS which for sure should solve the problem.

  • Problems with date calculation

    I have a java (and much more far vb) background and it seems that I'm really dependent functions for date calculations.  I'm trying to do a few things, but have not been able to accomplish them.

    I do not have

    Calendar.add()
    

    I briefly contemplated an add function by converting into long then do the calculation and returns a new calendar object, but the problems with this approach comes flourishes as soon as I started.  Just trying to find out if a date was yesterday was me banging my head against the wall.

    Any help please?

    I wrote this, but I don't know if there is a simpler method, go to this issue the wrong way, etc.

    public static boolean isYesterday(Calendar c) {
        Calendar today = Calendar.getInstance();
        int newDay = today.get(Calendar.DAY_OF_MONTH);
        if (newDay == 1) { //get last day of previous month
            int newMonth = today.get(Calendar.MONTH);
            int newYear = today.get(Calendar.YEAR);
            /* If jan 1, get dec of last year */
            if (newMonth == 0) { //Java Calendar.MONTH is zero-based
                newMonth = 11;
                newYear -= 1;
            today.set(Calendar.YEAR, newYear);
            }
            today.set(Calendar.MONTH, newMonth);
            newDay = DateTimeUtilities.getNumberOfDaysInMonth(newMonth, newYear);
        } else {
            newDay -= 1;
        }
        today.set(Calendar.DAY_OF_MONTH, newDay);
        return DateTimeUtilities.isSameDate(today.getTime().getTime(), c.getTime().getTime());
    }
    

    'convert to tz to the device.

    I recommend that stick you with using UTC for everything.  If you want to display to the user, then a DateField will convert the hour UTC to local time.  SImpleDateFormat.formatLocal will also print you long time UTC to local time.  So I recommend that you do not have to convert once at the local level.

    Remember that System.currentTimeMillis () is time not UTC/GMT.

    Of course, that's a good advice or not depends on your app.

    I'm not aware of any third-party code that helps, I reinvented wheels square to all my treatment to date.  But I never really looked at.

    About your code, assuming that c calendar uses the local time zone, so I think that the code works.

  • TO_CHAR fucntion problem with dates.

    Hi all

    I tested the following problem with 10g and 11g databases, and the problem is the same.

    create table aa (a date);
      insert into aa values('23-Mar-2014');
     commit;
    

    now the following query gives no results

    select count(*) from aa
    where to_char(a,'dd-Mon-yyyy') >='23-MAR-2014' and to_char(a,'dd-Mon-yyyy') <='23-Apr-2014';
    COUNT(*)
    ----------
     0
    

    and the following query gives the results

    select count(*) from aa
    where a>='23-Mar-2014' and a<='23-Apr-2014'
    
    COUNT(*)
    ----------
      1
    

    Why?

    We need the to_char working for our criteria of search dot net application.

    kindly guide us.

    Thank you

    You're hurting. Why convert a date into a string of characters and try to compare it to another string? This is false.

    Insert into aa values('23-Mar-2014');

    should be

    insert into aa values (to_date (March 23, 2014 ',' MON-DD-YYYY "");)

    and your selection should be:

    Select count (*) in aa

    where a > = to_date (March 23, 2014 ',' MON-DD-YYYY') and to_date (April 23, 2014 ',' MON-DD-YYYY "")

  • Problem with date settings

    Hi all. I have the problem with the Sub statement


    SELECT THE DOUBLE TO_DATE(:P_DATE,'DD/MM/YY')

    it get me ' 10 / 04/2012 '

    but I want 10/04/12 not as above.

    I saw that DD/MM/YY not like 'DD/MM/YYYY' still it gives me 10/04/2012 why can someone explain?

    Kind regards
    Uraja

    To_Date will always give you the output date format-based nls...

    Instead, you can try

    SELECT to_char (TO_DATE(:P_DATE,'DD/MM/YY'), ' DD/MM/YY') FROM DUAL;

    or replace nls_Date_format jj/mm/aa

  • Problem with Date calc

    I am trying to get this FormCalc calculation to work:

    Date2Num (form1. Page1_SF. EffectDates.endDate, ' DD/MM/YYYY') - Date2Num (form1. Page1_SF. EffectDates.startDate, "DD/MM/YYYY")

    Evently, I will divide by 7 to get the number of weeks, but the initial calculation won't work after the dates entered.

    Can you tell me what the problem with my forumula?

    Thank you.

    Odd. Something strange on the Date2Num format. I changed them in the calculation for "YYYY-MM-DD" and it works. Note that this is the calculation of the number of days elapsed.

    If (HasValue (form1. Page1_SF. EffectDates.endDate) & HasValue (form1. Page1_SF. EffectDates.startDate)) then
    $.rawValue = Date2Num (form1. Page1_SF. EffectDates.endDate.rawValue, 'YYYY-MM-DD') - Date2Num (form1. Page1_SF. EffectDates.startDate.rawValue, "YYYY-MM-DD")
    on the other
    $.rawValue = null
    endif
    Steve
  • problems with DATE

    Hello

    I have the following plsql:
    DECLARE
       TYPE record_t
       IS
          RECORD (
             col_1    DATE,
             col_2   VARCHAR2 (7),
             col_3    VARCHAR2 (1)
          );
    
       l_record    record_t;
       l_ref_cur   dyn_fetch.ref_cur_t;
    BEGIN
       l_ref_cur := helper.ref_cur;
    
       LOOP
          FETCH l_ref_cur INTO   l_record;
    
          EXIT WHEN l_ref_cur%NOTFOUND;
    
          ELSIF (LOWER (l_record.col_3) = 'd')
          THEN
             DELETE FROM  table_new
                   WHERE   MY_DATE = TO_DATE (l_record.col_1);
    
             DBMS_OUTPUT.put_line ('here it is: ' || l_record.col_1);
          END IF;
       END LOOP;
    
       CLOSE l_ref_cur;
    END;
    So, the problem is, that 'L_RECORD. COL_1"returns dates in the form: jj. MM YY

    It works very well with most of the files, but it does not find the file with date = 15.08.1930. Then I l_record.col_1 = 15.08.30! Maybe the problem is that oracle is not sure if she should return * 1930 or 2030 *...

    So, how can I solve this problem, I want to return the l_record.col_1 * 15.08.1930 *, NOT 15.08.30!

    Should I change the definition of the record_t type?

    Thank you!

    Your record definition defines COL_1 as a date, so there is not need to convert a date value in this column.

    Remove the TO_DATE() function inside the loop.

  • Problem with date comparison

    I have a problem with the TO_YMINTERVAL('10-00') function.


    Thank you
    Bachan.

    Published by: bah on March 23, 2010 14:47

    Please do not double post.
    Problem with TO_YMINTERVAL('10-00') function.

    Stick to your original thread, as others have already tried to help you.
    Start a new thread on the same topic is a waiste of time, as already provided entries are lost to other readers...

  • Problems with data conversion

    Hi all

    I'm doing an A - D conversion. Conversion table is given in attachment, as well as the file vi. I got three 8-bit during serial communication data and join them to form a 24-bit number (I mention this so there is no question why mets implement entry like that). As you can see in the table of conversion without exit number must be greater than Vref, however in this implementation, I get a flow of 2 * Vref.

    Can someone please help me find the error.

    Darko

    The conversion formula is implemented for bipolar data while your VI U32. You cannot represent negative numbers with U32 (unsigned integer).

    Lynn

  • problem with implicit to the conversion of the date in oracle

    Next date functions will work fine as long as string confirms for the next model of the date

    D MY separator2 R separator1

    the separator can be any sign of punctuation (/ $ % & *, ^) sapces, tabs...

    as
    Select ADD_MONTHS('21$MAY*2010',2) from DUAL;

    SELECT MONTHS_BETWEEN (23 ^ FEB & 2010', ' 11% jan(2011') FROM DUAL;)

    the two works perfectly, but it does not work in the ROUND functions (date) and TRUNC (date);

    SELECT ROUND('12-FEB-2010') FROM DUAL; -gives error

    It needs explicit conversion using TO_DATE();

    My question is why what is happening?
    Is it because we have two functions ROUND (NUMBER) and ROUND (DATE)?

    Hello

    Welcome to the forum!

    user650693 wrote:
    Next date functions will work fine as long as string confirms for the next model of the date

    All of the built-in functions will work fine as long as use you them as directed; in particular, pass arguments that have the correct data type. If a function requires a DATE for an argument, always place a DATE, not a VARCHAR2 you hope will be be implicitly converted to DATE.

    D MY separator2 R separator1

    the separator can be any sign of punctuation (/ $ % & *, ^) sapces, tabs...

    This applies to explicitly call the functions where a format string is used, for example, TO_DATE.

    as
    Select ADD_MONTHS('21$MAY*2010',2) from DUAL;

    SELECT MONTHS_BETWEEN ('23 ^ FEB & 2010', ' 11% jan(2011') FROM DUAL;)

    the two works perfectly,

    As the respondent previous said, the two work may , depends on several factors, such as your NLS parameters. It's a very bad habit to rely on such things. The 1st argument to ADD_MONTHS and two arguments to MONTHS_BETWEEN, are supposed to be DATEs, so always call these functions with the DATEs.

    but this does not work in the ROUND functions (date) and TRUNC (date);
    SELECT ROUND('12-FEB-2010') FROM DUAL; -gives error

    It needs explicit conversion using TO_DATE();

    My question is why what is happening?
    Is it because we have two functions ROUND (NUMBER) and ROUND (DATE)?

    No, it's because there is no ROUND function (VARCHAR2).
    The use of strings which are expected of the DATEs is simply asking for trouble. Sometimes, you get what you're asking.

  • Problem with Date in the Remedy to Oracle datetime conversion

    SELECT Systems_Changed,

    Impact_Summary2,

    TO_CHAR (to_date (January 1, 1970 ',' DD-MM-YYYY HH24:MI:SS') + (Time_Change_Begins / (60 * 60 * 24)), "YYYY-MM-DD HH24:MI:SS") "Time_Change_Begins."

    TO_CHAR (to_date (January 1, 1970 ',' DD-MM-YYYY HH24:MI:SS') + (Create_Date / (60 * 60 * 24)), "YYYY-MM-DD HH24:MI:SS") "Create_Date_Convert".

    OF ARADMIN. CHANGE_NOTIFICATION

    WHERE

    (((to_char (to_date (1er janvier 1970 ',' JJ-MM-AAAA HH24:MI:SS') + (Time_Change_Begins / (60 * 60 * 24)), "DD-MM-YYYY")) > =))
    ((SELECT to_char ((SYSDATE + 1), 'DD-MM-YYYY') FROM dual))

    AND ((to_char (to_date (1er janvier 1970 ',' JJ-MM-AAAA HH24:MI:SS') + (Time_Change_Begins / (60 * 60 * 24)), "DD-MM-YYYY")) <)
    (SELECT to_char (SYSDATE + 31, "DD-MM-YYYY") OF double)))


    I'm not able to get good results. Any help on this.

    nikhilreddy wrote:
    Can you tell me what are the other changes I have to do to make it work.

    Again, define doesn't work do not. After a small sample showing that it "doesn't".

    SY.

  • Problem with data services blackBerry Smartphones

    I want to use internet on my phone that by wifi, so obviosly I disabled data on implemented mobile network services. Problem is when I'm home or anywhere where I can connect to a wifi network, I get a message saying that there is no problem, and if it persists, I must contact my provider. I'm something wrong, is the solution?

    For some strange reason, you can now navigate with your data disabled Services.  It is a new feature in OS 7 (or 7.1, I don't remember which operating system, it has been introduced).  There was a time where you need to Data Services is enabled for surfing, even just with a Wi - Fi.

    However, I am happy that things are working for you now.

  • Facing problem with date and time.

    * - Original title - BIOS

    Mr President.

    I have Compaq CQ2100IL Desktop pc for awhile I was faced with the problem of the date and time, so I posted this question to Microsoft, so they gave me a solution change my CMOS battery, so I did it, but despite this I get this error again then I tried and got answer to update my BIOS , I tried to find a version update on the HP site but did not find, so please help me in this matter.

    Hi Vikas,

    You can contact HP here: http://h10025.www1.hp.com/ewfrf/wc/contacthp?cc=us&dlc=en&lc=en&os=4062&product=3890751&sw_lang=

    Warning in the BIOS: BIOS change / semiconductor (CMOS) to complementary metal oxide settings can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the configuration of the BIOS/CMOS settings can be solved. Changes to settings are at your own risk.

    Let us know if you need assistance with any windows problem. We will be happy to help you.

Maybe you are looking for