Using NVL for date

I am creating a view and one of the columns is this:
(b.startdate || ' To ' || b.enddate) salesDateRange
however when I was trying to handle the null value of date, I found the following problems,
case 1
(nvl(b.startdate, 'NA') || ' To ' || b.enddate) salesDateRange
when i use nvl, I am able to create the view, but when I retrieve the data, I get this error msg.
ORA-01858: a non-numeric character was found where a numeric was expected
01858. 00000 - "a non-numeric character was found where a numeric was expected"
*Cause:    The input data to be converted using a date format model was
incorrect. The input data did not contain a number where a number was
required by the format model.
*Action:   Fix the input data or the date format model to make sure the
elements match in number and type. Then retry the operation.
is nvl only available for numerical value?

user8944947 wrote:
I am creating a view and one of the columns is this:
(b.startdate || ' To ' || b.enddate) salesDateRange
however when I was trying to handle the null value of date, I found the following problems,
case 1
(nvl(b.startdate, 'NA') || ' To ' || b.enddate) salesDateRange
when i use nvl, I am able to create the view, but when I retrieve the data, I get this error msg.
ORA-01858: a non-numeric character was found where a numeric was expected
01858. 00000 - "a non-numeric character was found where a numeric was expected"
*Cause:    The input data to be converted using a date format model was
incorrect. The input data did not contain a number where a number was
required by the format model.
*Action:   Fix the input data or the date format model to make sure the
elements match in number and type. Then retry the operation.
is nvl only available for numerical value?In addition to the answers already given, you have to consider that NVL is an overloaded function, designed to deal with different datatypes. It accepts 2 arguments and the version of NVL that is used depends on the arguments given (that's the nature of overloading - look it up on the internet if you're not sure).
So, there is defined e.g.
NVL({noformat}<number arg>, <number arg>{noformat})
NVL({noformat}<varchar2 arg>, <varchar2 arg>{noformat})
NVL({noformat}<date arg>, <date arg>{noformat})
etc.In your example, as the first argument you are passing in is a date, Oracle is opting to use:
NVL({noformat}<date arg>, <date arg>{noformat})But your second argument is not a date, it's a varchar2.
However, Oracle is clever and can perform "implicit" conversions between datatypes i.e. it will try and convert datatypes without you actually telling it to. (It's generally good coding practice to do it yourself though).
So, in you case Oracle is taking your varchar2 string "NA" and trying to implicitly convert this to a date, using the only way it knows how, which is to apply a date format mask as defined by the NLS_DATE_FORMAT parameter for the session. For example, internally it will be trying to do the equivalent of:
TO_DATE('NA','DD-MON-YYYY')(assuming your NLS_DATE_FORMAT parameter is set to DD-MON-YYYY)
If we try that ourselves, we get...
SQL> select to_date('NA','DD-MON-YYYY') from dual;
select to_date('NA','DD-MON-YYYY') from dual
ERROR at line 1:
ORA-01858: a non-numeric character was found where a numeric was expected... which is the same error you were getting.
So, in order for your NVL to work you would either need to supply a DATE as the second argument (some default date to use if the first argument is null), or some varchar2 string that represents a date in the correct format as per your NLS_DATE_FORMAT setting (dangerous because if the NLS_ setting changes then your code can suddently error), or you provide the first argument as a VARCHAR2 string instead of a date (using TO_CHAR), so the the function overloading causes Oracle to choose the varchar2 argument version of NVL, for which 'NA' is a perfectly valid second argument.

Similar Messages

  • Can I use JDeveloper for Data mining

    Can I use JDeveloper for Data mining, instead of using stand-alone data miner.
    Secondly, if I can, do we require to create another schema and run all the required scripts for data miner or it is not necessary.
    Thanks in advance.

    ODM 9i provided a JDeveloper Pluggin called DM4J. In ODM 10g, this was replaced by the standalone Oracle Data Miner GUI. In 10g, you can use the API in JDeveloper, but there is no support via wizards or viewers.
    However, models that you create via the API through JDeveloper could be used in Oracle Data Miner for testing, scoring, and model detail viewing.

  • Nvl for data picker

    My report is based on two data picker items. If the value is not chose for the items, then I specify their value using nvl .
    like this
    select .......
    from.......
    where ....
    and
    hiredate >= NVL(TO_DATE(:P4_START_DATE,'DD-MON-YYYY'),date '2009-01-01')
    AND
    hiredate <= NVL(TO_DATE(:P4_END_DATE,'DD-MON-YYYY'),date '2010-03-31')
    But I get the error that day must be between 1st and last day of the month.
    I get error even if I use
    select .......
    from.......
    where ....
    and
    hiredate BETWEEN NVL(TO_DATE(:P4_START_DATE,'DD-MON-YYYY'),date '2009-01-01')
    AND NVL(TO_DATE(:P4_END_DATE,'DD-MON-YYYY'),date '2010-03-31')
    Please help me out!

    Error message means that somewhere day number is wrong
    select to_date('32-02-2010','dd-mm-yyyy') from dual; or
    select to_date('00-02-2010','dd-mm-yyyy') from dual; 1)What is the value of :P4_START_DATE when you get this error?
    2) Check your current NLS settings - try
    select to_char(sysdate,'dd-mon-yyyy') from dual2)What is the type of hiredate column?
    3)Try to replace :P4_START_DATE with 01-04-2010 - run :
    select .......
    from.......
    where ....
    and
    hiredate >= NVL(TO_DATE('01-APR-2010','DD-MM-YYYY'),to_date('2009-01-01','yyyy-mm-dd'))
    AND
    hiredate <= NVL(TO_DATE('01-APR-2010','DD-MM-YYYY'),to_date('2010-03-31','yyyy-mm-dd'))Could the error be in the other part of the query?
    try:
    select .......
    from.......
    where ....
    and
    hiredate >= NVL(TO_DATE('01-APR-2010','DD-MM-YYYY'),to_date('2009-01-01','yyyy-mm-dd'))
    AND
    hiredate <= NVL(TO_DATE('01-APR-2010','DD-MM-YYYY'),to_date('2010-03-31','yyyy-mm-dd'))
    */

  • Using translate for date in the control file !!

    Hi,
    I am having data file where in i expect date but get non-numeric character.
    I am generating control file dynamically (programatically).
    While creating control file i know that here the type of data will be date so i put datatype as date. But at one place i got non numeric character instead of date.
    Now i want to put somekind of logic built in my dynamic generation which will check whether if value within that column is character then make it null and then load data. And if it is numeric keep it as it it.
    i.e.
    if(non-numericChars)
    make value null before loading.
    else
    keep the value as it and then load it.
    I heard that with translate function we can do that. Right ?
    So if i have a line like this in my control file:
    column_Name date "MM/DD/YYYY HH:MI:SS AM"
    How should i write the above statement to put the above mentioned logic.
    Any help would be highly appreciated.
    Regards,
    Dipesh

    and Perhaps TO_DATE can help you :
    TO_DATE
    Syntax
    to_date::=
    Text description of to_date
    Purpose
    TO_DATE converts char of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 datatype to a value of DATE datatype. The fmt is a date format specifying the format of char. If you omit fmt, then char must be in the default date format. If fmt is 'J', for Julian, then char must be an integer.
    Note:
    This function does not convert data to any of the other datetime datatypes. For information on other datetime conversions, please refer to TO_TIMESTAMP, TO_TIMESTAMP_TZ, TO_DSINTERVAL, and "TO_YMINTERVAL".
    The default date format is determined implicitly by the NLS_TERRITORY initialization parameter, or can be set explicitly by the NLS_DATE_FORMAT parameter.
    The 'nlsparam' has the same purpose in this function as in the TO_CHAR function for date conversion.
    Do not use the TO_DATE function with a DATE value for the char argument. The first two digits of the returned DATE value can differ from the original char, depending on fmt or the default date format.
    Note:
    This function does not support CLOB data directly. However, CLOBs can be passed in as arguments through implicit data conversion. Please refer to "Datatype Comparison Rules" for more information.
    See Also:
    "Date Format Models"
    Examples
    The following example converts a character string into a date:
    SELECT TO_DATE(
    'January 15, 1989, 11:00 A.M.',
    'Month dd, YYYY, HH:MI A.M.',
    'NLS_DATE_LANGUAGE = American')
    FROM DUAL;
    TO_DATE('
    15-JAN-89
    The value returned reflects the default date format if the NLS_TERRITORY parameter is set to 'AMERICA'. Different NLS_TERRITORY values result in different default date formats:
    ALTER SESSION SET NLS_TERRITORY = 'KOREAN';
    SELECT TO_DATE(
    'January 15, 1989, 11:00 A.M.',
    'Month dd, YYYY, HH:MI A.M.',
    'NLS_DATE_LANGUAGE = American')
    FROM DUAL;
    TO_DATE(
    89/01/15
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/functions137a.htm#SQLRF06132
    Joel P�rez

  • Problem in using OCIBindByName  for date type column

    Hi,
    Can you please guide me about my following problem?
    I am trying to fetch the data from system table "FLOWS_020100.WWV_FLOW_ACTIVITY_LOG1$" in Oracle Express edition 10.2.0.3 database, using the OCI library on Windows with C++
    This table has a TIMESTAMP column of date type.
    I've the following query as below:
    select TIME_STAMP from FLOWS_020100.WWV_FLOW_ACTIVITY_LOG1$ where TIME_STAMP > to_date('31/OCT/12 23:59:59', 'DD-MON-YY HH24:MI:SS') order by TIME_STAMP asc;
    For this, first I am preparing the query as below:
    select TIME_STAMP from FLOWS_020100.WWV_FLOW_ACTIVITY_LOG1$ where TIME_STAMP > :PKVAL order by TIME_STAMP asc;
    Before calling OCIExecute(), I am setting the PKVAL buffer to following value:
    "to_date('31/OCT/12 23:59:59', 'DD-MON-YY HH24:MI:SS') "
    & calling the OCIBindByName function with data type as SQLT_DATE.
    But when the OCIExecute is called, my program crashes with access violation
    Can you please guide me what is the correct way to pass the date value in query to OCI? How do we bind the date values?
    Thanks in advance for your time and help.
    Best Regards.

    I had a similar problem. TO_DATE doesn't appear to function w/ BindByName or BindByPos.
    You are going to have to bite the bullet and use an actual date.
    Here's an example (I am using two dates in my query):
    int main (int argc, char **argv, char **envp)
    static text invalidQuery = (text )"SELECT f1.my_val, COUNT(f1.my_val) invalid_count, (SELECT COUNT(*) FROM my_db_table f2 WHERE f2.my_val = f1.my_val AND f2.foo_dt = :1 ) total_count FROM my_db_table f1 WHERE f1.foo_dt = :1 AND ( (f1.vld_bar_sw IS NULL OR f1.vld_bar_sw = 'N') OR (f1.vld_foo_sw IS NULL OR f1.vld_foo_sw = 'N') ) group by my_val order by my_val asc";
    OCIDate boundDateVal;
    sb2 inputYear;
    ub1 inputMonth;
    ub1 inputDay;
    char inputYearStr [] = "0000";
    char inputMonthStr [] = "00";
    char inputDayStr [] = "00";
    /* I get and validate the date as input, but you can set it however you'd like */
    inputYear = (sb2) (atoi (inputYearStr));
    inputMonth = (ub1) (atoi(inputMonthStr));
    inputDay = (ub1) (atoi(inputDayStr));
    /* Allocating Date*/
    OCIDateSetDate ( &boundDateVal, inputYear, inputMonth, inputDay );
    OCIDateSetTime( &boundDateVal, 0, 0, 0);
    returnVal = OCIBindByPos(invalidStmt, &firstInputBindHPtr, myErrorHandle, (ub4) 1,
    (dvoid *) &boundDateVal, (sword) sizeof(boundDateVal),
    SQLT_ODT, /*dty OCIDate*/
    (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
    if ( !(returnVal == OCI_SUCCESS || returnVal == OCI_SUCCESS_WITH_INFO) )
    displayErrors (returnVal, myErrorHandle, "OCIBindByPos-contactDate 1 ");
    cleanup();
    exit(1);
    }//if
    returnVal = OCIBindByPos(invalidStmt, &secInputBindHPtr, myErrorHandle, (ub4) 2,
    //(dvoid *) &InputArguments.contactDate, (sword) sizeof(InputArguments.contactDate),
    (dvoid *) &boundDateVal, (sword) sizeof(boundDateVal),
    SQLT_ODT, /*dty OCIDate*/
    (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
    if ( !(returnVal == OCI_SUCCESS || returnVal == OCI_SUCCESS_WITH_INFO) )
    displayErrors (returnVal, myErrorHandle, "OCIBindByPos-contactDate 2 ");
    cleanup();
    exit(1);
    }//if
    }//main
    ** I have had issues w/ OTN not correctly translating certain characters, so hopefully the above example is readable or you can figure out which characters may be missing.

  • [Q] Using viewCriteria for Date type

    To Query data, I used ViewCriteria.
    But it works well for Varchar2, Number type.
    But it does not work for Date type.
    for example
    If I set variables like the below, it works,
    attrName = "OrdName";
    attrValue = "Nick";
    But, If I set variables like the below, it does not work
    attrName = "AppDate";
    attrValue = "04.5.12";
    ViewCriteria vc = order.createViewCriteria();
    ViewCriteriaRow vcr = vc.createViewCriteriaRow();
    vcr.setAttribute(attrName, attrValue);
    vc.addElement(vcr);
    order.applyViewCriteria(vc);
    order.executeQuery();
    Can I solve this problem ?

    using a custom expression in the view criteria, ex.
    vcr.setAttribute("DateField", "LIKE TO_DATE('" + dateField.toString() + "', 'yyyy-mm-dd')");
    similarly, you can use other expressions to remove the default BC4J problems w/ dates (>, <, between) - At least I know you can't use = to get it to work right.
    The default handling of BC4J is to say = TO_DATE(whatever you put in the value portion) where it needs to be LIKE to work properly - for some reason - probably a patch is available for it.

  • Use formula for date range instead of parameter?

    I am designing a Crystal report that will always pull records for the next full week.
    Example:  Today is 8/4, so I need the report to pull data for dates 8/11 through 8/15.
    Currently, I am using parameters each time to run this report.
    Is there a formula that could automatically pull this date range without using parameters in my report?
    Any help is appreciated.
    Thanks.

    This is actually not too difficult.  Assuming you want to be able to run this on any date and get the "Next Full Week" starting on Monday (based on your date range above), here's what you could do:
    1.  Create a formula that I'll call {@StartDate}
    NumberVar dow := DatePart('w', CurrentDate, crMonday) - 1;  //Day of week, starting on Monday.
    NumberVar days := 7 - dow;
    CurrentDate + days
    2. Create a formula that I'll call {@EndDate}:
    {@StartDate} + 7
    3.  In the Select Expert, manually edit the selection formula to use these date formulas instead of the parameters.
    -Dell

  • Why does my Verizon iPhone 4S Data Service Switch from 3G to 2G as soon as I want to use it for "data-intensive" apps such as Netflix?

    I have an iPhone 4S that I purchased new from Verizon back in January 2012.  I've started to notice that the 3G data coverage appears and disappears according to whether or not I'm actually using the data.  For instance: When the phone is stationary and not using the data, it indicates that I have 3G data coverage.  When I click on an app like Netflix (without moving the phone from it's stationary position), data coverage either immediately or soon thereafter switches to a 2G data coverage connection (indicated with an "o" for Verizon).  Has anyone else had this same problem?  I can't say that this happens everywhere, but in particular, it happens at my work every single time I would like to be able to watch episodes of tv shows on my lunch break. 

    Yeah I'll need to call and ask because it's very possible that the tower is "congested" as I work in a large city.  Hardly seems fair that I would get a diminished data speeds due to congestion of a large city that Verizon indicates it has full coverage on all of their "data coverage" maps.  I may have made a different carrier choice had I known that this was going to happen.  I wonder if this happens with their 4G towers as well...

  • Using iPod for data transfer from windows to a Mac... is this possible?

    ok here's the situation.
    my room mate has a (video) iPod 30G colour screen and everything. she has downloaded a show (not from iTunes) on her laptop using windows. We want to use her iPod to transfer the data from that show onto my computer which is an iMac G5 Intel Core Duo.
    We connected the iPod to my computer but it was not recognized. Is this because her iPod is formatted for Windows or is there possibly another reason?
    if anyone could help that would be great.
    thanks

    From what I know, windows will not recognize the complicated data of a mac formatted device; hence not recognizing it. Macs can recognize a windows formated ipod though, so if you decide to reformat it on windows, then you can use it on both computers. If you dont though, looks like you are out of luck, sorry.
    Hope I helped.

  • Getting an error while using BAPI for data upload using FB50

    Hi,
    Can someone please help with the error below :
    To Upload Data Using FB50 , am using 'BAPI_ACC_DOCUMENT_POST' FM
    and passing values as
    obj_type = REACI
    obj_KEY = '$'
    obj_sys = t000-logsys
    getting errors errors in return as
    'Error in document: REACI $ R3_AFRICA
    G/L account 2511510 is not defined in chart of accounts CSGP(though the account exists in the COA)
    Control indicators for controlling area EU01 do not exist'.(we have not input any indicators)
    Thanks

    Control indicators for controlling area (t-code OKKP ) is a primary configuration before the company is set to production. Here we maintain which sub areas of controlling are activated. Have a look at those settings.
    Check the validity of the accounts/cost element in the KA03 to ensure the cost element is valid on the date of transaction.
    What is the error message number?

  • How to use bluetooth for data transmission

    Hi,
    we would like to use the Iphone touch for display external data over bluetooth.
    This is what we want to do:
    - Have a own App
    - Connection over bluetooth
    The simplest system could be an Temperature and Humidity sensor with microcontroler and bluetooth module. Data should be send in SPP (serial Port Profile).
    Now I have seen that SPP profile is not available on Iphone or Ipod.
    Is there a chance to connect over other way and bluetooth ?
    Do have anyone tip or know-how to do that and is there a chance
    do make app legal for App store ?
    Thanks, for many helps !

    HID Profile is a "Human Interface Device Profile", this allows connections between bluetooth keyboards, and similar devices. It's basically a "human convenience" that lets a user make input through another device.
    The PAN Profile ("Personal Area Network) is a profile that can actually transmit and receive data. The data though is limited to peer-to-peer gaming (games that can be played with others in the vicinity). A good example is the Rock Band multiplayer, where players join up using Bluetooth (and not Wi-Fi, to prevent lag).
    I believe there isn't any reverse HID applications (remotely using the HID from the iPod), most app that do that are wi-fi transmitted, since there's no need for a long, direct, connection. Examples are the Apple Remote, ADT Security, and OnStar. These all allow you to access your devices that are kept on your wireless signal (OnStar uses some sort of cell phone reception to put your car on a network).

  • How to use filter for data tables? Important topic but no docs/examples.

    I was looking at the TableRowGroup APIs:
    http://developers.sun.com/prodtech/javatools/jscreator/reference/docs/apis/webui/index.html
    and looks like it has getTableDataFilter and setTableDataFilter methods. Sounds to me, that we can use TableDataFilter to filter rows that are displayed. For example, we can provide users with a drop down list of fields to choose from, and input field to enter the value of the selected field, so that they can narrow down the rows to search for specifics row(s) they are looking for.
    I have not seen any example, or enough documentation, to figure out how to use this filter. Since JSC is new, there are not too many resources out there or on web for such specific issues. Any gurus out there?
    Thanks

    Creator Team: Data filtering tutorial is over due now. This is something that will be useful to most developers. We all want to display users some data and want to provide user ability to filter it down based on some criteria, i.e. display rows within a date range, display all rows that have certain value or a field, etc. If there is a built-in filter in TableRowGroup, why not document it adequately along with some examples and a tutorial?
    This is one of the key elements of Microsoft/VS.NET market share -- provide tons of example/tutorials/advanced code/books/3rd party books, etc. Why can't other companies follow a well-proven success element? In spite of making a better product, the can end up loosing or not gaining enough share, because of this lack of attention.

  • Using inputRangeSlider for Dates

    Hi,
    I am using JDeveloper 11g(11.1.1.6)
    I followed Duncan Mills blog : https://blogs.oracle.com/groundside/entry/using_inputnumberslider_for_dates
    I have successfully done all that the blog has stated..
    I also got the range slider on my page. However the dates are not coming properly
    As stated in the blog the inputNumberSlider component has bean methods for startDate,EndDate and Increments.
    Dis is not stated in the blog..
    How could we possibly write these methods as it requires milliseconds calculations and it has to be accurate
    Please help
    Regards,
    Benson

    Hi,
    1) the way i see it, the uiManager doesn't do anything fancy here. It just returns the number for the ranges in milliseconds (almost similar to hard-coding). I think the reason you get the dates as 01/01  must be within your implementation of the converter (worth to debug and see what exactly happens in the converter).
    2) Getting end date as current. Well, as said, the managed bean just returns long values. So the getter method of dateRangeSliderEndDate bean property returns something along the lines of
    http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html
    Calendar rightNow = Calendar.getInstance();
    long timeInMil = rightNow.getTimeInMillis()
    3) To get the date in the format you want - you change a method:
    public String getAsString(FacesContext facesContext, UIComponent uIComponent, Object valueAsObject) {
      long selectedValue =  ((Double)valueAsObject).longValue();
      return DateFormatUtils.format(selectedValue, "MM/dd");
    A quick Google search for DateFormatUtils
    DateFormatUtils (Commons Lang 2.6 API)
    Hope this is enough hand-railing for you to complete your task
    Frank

  • How to use function for 'date' - 30 mins?

    Hi,
    I need to subtract 30 mins from date-time and display value in report?
    Any function?
    Thanks!
    Edited by: user12427117 on Mar 11, 2011 10:20 AM

    Date should be in canonical format
    i.e. YYYY-MM-DDThh:mm:ss+HH:MM
    or atleast YYYY-MM-DD
    when you want to divide you should have it as '1 div 48' and not 1/48
    Havent tried this one. So cant confirm if it works for mins

  • For custom tables should we use UTC for date/time fields

    A general question.
    Can anyone confirm that SAP does seem to be moving towards storing date/time in UTC format?
    We're building custom tables and we're making it a standard to store date/time fields in UTC format.
    Regards,
    Lavaughn

    Hello Lavaughn,
    I can not speak for SAP, but from my personal experience TimeStamps are the state of the art to store time date info in db tables. Even with date/Time fields a conversion to the local timezone is necessary. Of course you can reuse your db definition on dynpros. But since UI and business logic will be divided anyway this is also not really a valid point.
    Best Regards
    Klaus

Maybe you are looking for