Comparing dates problem

Hi,
When I try to execute a query that contains:
WHERE to_date(CALL_DATE, 'dd.mm.yyyy') = to_date('01.02.2005', 'dd.mm.yyyy')
I get an empty table when using JDBC but it works when using an editor (like SQL Navigator). Any ideas. Thanks

Is CALL_DATE actually a column of type DATE? If so, doing TO_DATE(call_date, <<format mask>>) forces Oracle first to implicitly cast call_date to a string using the NLS_DATE_FORMAT for the session, then explicitly casts this string back to a date using the supplied format mask. At best, this is a terribly inefficient approach (particularly if call_date is indexed). At worst, it causes all sorts of tough to debug issues.
If call_date is actually a DATE, your WHERE clause should be
WHERE call_date = TO_DATE( '01.02.2005', 'DD.MM.YYYY' )Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC

Similar Messages

  • Business rule + compare date + problem in jspx

    Hi all ,
    i am useing Jdeveloper11.1.1.3 .
    i need to compare birthDate and employmentDate. birthDate must be greater than employmentDate at least 15 years.
    there is a business rule method in entity object impl file :
    * Validation method for InsuredPerson.
    public boolean validateInsuredPerson() {
    //start date must be greater than birthdate _ at lease 15 year (180 month)
    Date birthDate=getBirthDate();
    birthDate = (Date)birthDate.addMonths(180);
    Date startDate=getStartDateEmployment();
    if(birthDate.compareTo(startDate)==1) {
    return false;
    return true;
    when false eraise an error message wil genarate.
    when i test it in appmodule every thing is ok but by runnig jspx page :
    birthDate is --> 1970-05-05
    employmentDate --> 1991-05-05
    consider edit birthdate from 1970-05-05 to 1980-05-05
    so 1991-1980= 11 is < 15 --> error raise
    but in jspx year of birthdate changed to 1995 ==> 1980+15
    any body know why?or another way to develop it.
    Regards,

    I change my codes now it is ok .
    public boolean validateInsuredPerson() {
    //start date must be greater than birthdate _ at lease 15 year
    int birthYear=getBirthDate().dateValue().getYear();
    int startYear=getStartDateEmployment().getValue().getYear();
    int diff=startYear-birthYear;
    if(diff<15) {
    return false;
    return true;
    }

  • Comparing dates problem, need help?

    the checks are not working correctly, and I am missing something. Code is below.
    for the start date check.
    1. if I put in 28-OCT-2006, I get my error message. Why wont it let me enter today and how do I fix it?
    2. If the start and stop date are the same, my SAVE button code fires. WHy? and then it still ends up commiting.
    thanks,
    HERE IS THE START DATE TEXT
    SET_ITEM_PROPERTY('DRUG_ID', Enabled, PROPERTY_FALSE);
    declare
    alert_NO varchar2(10);
    startDate date;
    systemDate date;
    begin
    startDate := :DRUG_PRICE.START_DATE;
    systemDate := sysDATE;
    --this displays at the buttom of form
    -- MESSAGE('StartDate Must be >= Today');
    if(startDate < systemDate ) then
    --this displays at the buttom of form
    MESSAGE('StartDate Must be >= Today');
    --calls the appropriate alert
    alert_NO := show_alert('STARTSYS');
    RAISE FORM_TRIGGER_FAILURE;
    end if;
    end;
    HERE IS MY SAVE BUTTON
    declare
    alert_NO varchar2(10);
    startDate date;
    stopDate date;
    begin
    startDate := :DRUG_PRICE.START_DATE;
    stopDate := :DRUG_PRICE.STOP_DATE;
    --this displays at the buttom of form
    MESSAGE('Error with the Dates');
    if(startDate > stopDate ) then
    -- calls the appropriate alert
    alert_NO := show_alert('START');
    RAISE FORM_TRIGGER_FAILURE;
    elsif (startDate <= stopDate) then
    MESSAGE('Drug Price Added Successfully.');
    commit;
    end if;
    end;

    Is this forms?
    Anyway, regarding your question, you're comparing the input date against sysdate and maybe you're sending a trunc date so sysdate is always bigger (it includes day, month,year, hour, minute and seconds). Since you're sending a truncate date you're comparing now against today 12:00:00 a.m.
    Ex:
    select sysdate from dual;
    SYSDATE
    28.10.06 23:31
    select case when to_Date('28/10/2006', 'dd/mm/yyyy')<sysdate then 'a' else 'b' end FROM DUAL;
    CAS
    a

  • Table_comparison - how to compare data at a high level

    Hi,
    I have to do data validation at a high level between two tables that I am loading.
    I am trying to use table_comparion transform but the problem is that my target table is at a much lower level than at which I want to compare data. So it has many more columns (both key and data fields) than what I want to compare.
    Does the output of query transform ( which I am using as input into table_comparion) be in the exact same format as comparion table? If not, then can somebody suggest me something else.
    Or how can I compare output of two query transforms ?
    Thanks,
    Saurabh Bansal

    Dear Saurabh,
    Not sure if you have already got the solution to this. If yes please close the thread.
    If not, i would suggest you can use the validation rule to compare the two tables and then based on the PASS or FAIL result can check what needs to be done on the output.
    Do post back if you have got the solution or you need any furthur help or else close the question.
    regards,
    Den

  • How to compare dates using javascript?

    Hi,
    I have to compare dates using javascript. The dates are in format "mm/dd/yy" for eg "10/09/06".
    I have written a script to compare the dates but the problem I 'm facing is with the year.
    For example if I compare "10/09/06" with "10/04/98", then "10/04/98" is coming out to be greater than "10/09/06" because it is considering year "98" to be greater than "06".
    Please advice/suggest.
    Thanks in advance...

    Dude, you're here in a Java forum, not in a Javascript forum. Those are two entirely different languages.
    The answer in Java is to use java.text.SimpleDateFormat to convert String to Date and use java.util.Date and/or java.util.Calendar to compare dates.

  • Compare date in SQL statement

    yup.. how can i compare date in SQL statement??
    pls give me a completed example.

    I'd think this is a formatting problem. Why not try:
    PreparedStatement ps = myConnection.prepareStatement(
    "SELECT * FROM Receipt WHERE to_date(Date) > ? ");
    ps.setDate(1,TodayDate);
    ResultSet rs = ps.executeQuery();
    HTH,
    Ken

  • Best way to compare data of 2 tables present on 2 different servers

    Hi,
    We are doing data migration and I wil like to compare data between 2 tables which are present on 2 different server. I know to find the difference i can go for minus or full outer join and by creating the database link.
    But my problem is the volume of the data. The tables under consideration has approximately 40-60 columns and number of rows in each tables are around 60-70 million. Also both the tables are on 2 diffferent servers.
    I would like to know
    1] What will be the best way to compare the data and print the difference from performance perepective? I know that if I am going for DB links then its will definitely impact the performance as the tables are across 2 different servers.
    2] Is it advisable to go for using SQL - PL/SQL for this kind of senario or dump the data in flat files and use C or C++ code to find the difference.
    Regards,
    Amol

    Check this at asktom.oracle.com. Search for "Marco Stefanetti" and follow the few posts between Marco and Tom. As far as your tables being on separate servers, you could consider dumping the data to file and using external table or using CTAS ( create table as select ) to get both tables locally.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2151582681236

  • How to compare data from 2 different time periods

    Hi folks,
    I have a question on approach to a problem. I want to be able to compare data from a common db, but for 2 different time periods. For example I want to see the number of occurences of an instance in my data for today and compare it against occurences a week ago today. What's the best approach for this kind of problem? Is this done with 2 separate queries from 2 sub reports and then compared some how? Any comments on this approach or an other are appreciated.
    TIA bvd

    Follow these steps:
    1) Bring your first time period in your main report.  This will be your first query.
    2) Bring your second time period in a subreport.  This will be your second query.
    3) Bring the values from your subreport into your main report using shared variables.
    4) Lastly, compare the results using formulas in your main report.
    I hope this information proves useful.
    Regards,
    Zack H.

  • Compare dates coming form Source system & update higher one in target syste

    hi all,
             Mt reqt is to compare dates coming from source system & update highere one
    Ex--) E1EDP01 has been repeated 3 times in Idoc segemnt E1EDP20 , then date with higher one need to be updated in target system
    like 14/12/08
          15/12/08
          16/12/08
    Here 16/12/08 need to be updated first & then the other ones one by one.
    Anybody guide me in comparing these dates functionality .
    Send me the code !
    Regards
    Chaithanya

    Hi Michael,
                     I was unable to trace the exact issue of how to track  E1EDP01 Dates & compare it.
    I had created UDF to compare dates coming from E1EDP01 Segment
    following is my code --->
    // This UDF return 1 value for highest date and 0 for not highest date.
    DateFormat mydateformat = new SimpleDateFormat("ddMMyyyy");
    Date mydate1 = null;
    Date heightDt = null;
    for (int i=0; i <a.length; i++)
      if (a<i>.equals(ResultList.CC)) continue;
      try{
         mydate1 = mydateformat.parse(a<i>);
         if (i==0)
          heightDt  = mydateformat.parse(a<i>);
         if  (heightDt .before(mydate1))
         heightDt  = mydate1;
    catch(Exception e){}
    //result.addValue(  mydateformat.format(heightDt));
    for (int i=0; i <a.length; i++)
    try{
    mydate1 = mydateformat.parse(a<i>);
    if  (heightDt .equals(mydate1))
    result.addValue( "1");
    else
    result.addValue( "0");
    catch(Exception e){}
    My Problem here is in my Idoc if there are  Multiple E1EDP20 segments & here date would be repeated 4 times . I have to compare highest date out of 4 & send it to the target system.
    which I have done it, but here my problem is  the segment E1EDP01 is repeated & iam unable to find highest date individually to the node level.
    Sorry I should have explained this before only.
    Can Anyone guide me in comparing the date at segment level.
    Regards
    Chaithanya

  • SQL date problems

    I have an old sql statement which is centered around dates as a contraint. When I run it through Oracles software (MYSQL plus), I am returned the correct records. But when running I run it through my web-app, nothing is returned to me. I guess the JDBC driver will interpret the sql statement a little differently. I know the problem is with the clause dealing with the dates, but am unaware of how to resolve it. Is there a better way of comparing dates? I am looking to find dates greater than tommorow's date. Here it is:
    Thanks
    AND (b.aq_follw_dte < to_char(sysdate+1,'dd-mon-yy')
    OR b.m_follw_dte < to_char(sysdate+1,'dd-mon-yy')
    OR b.me_follw_dte < to_char(sysdate+1,'dd-mon-yy')
    OR b.ec_follw_dte < to_char(sysdate+1,'dd-mon-yy')
    OR b.cxr_follw_dte < to_char(sysdate+1,'dd-mon-yy')
    OR b.hs_follw_dte < to_char(sysdate+1,'dd-mon-yy')
    OR b.bp_follw_dte < to_char(sysdate+1,'dd-mon-yy')
    OR b.ps_follw_dte < to_char(sysdate+1,'dd-mon-yy')
    OR b.cd_follw_dte < to_char(sysdate+1,'dd-mon-yy')
    OR b.other_follw_dte < to_char(sysdate+1,'dd-mon-yy')
    OR b.ts_follw_dte < to_char(sysdate+1,'dd-mon-yy')
    OR b.sal_follw_dte < to_char(sysdate+1,'dd-mon-yy')
    OR b.ir_follw_dte < to_char(sysdate+1,'dd-mon-yy')
    OR b.br_follw_dte < to_char(sysdate+1,'dd-mon-yy'))

    This is far too Oracle centric.
    You'd be much better off using java.sql.PreparedStatement and let its setDate() method escape those Dates for you correctly:
    Calendar calendar   = new GregorianCalendar();
    java.util.Date tomorrow = calendar.add(Calendar.DAY_OF_YEAR, 1);
    java.sql.Date tomorrowAsSql = new java.sql.Date(tomorrow.getTime());
    String sql = "the rest of your query here"
    + "AND (b.aq_follw_dte < ?) "
    + "OR b.m_follw_dte < ?) "
    + "OR b.me_follw_dte < ?) "
    + "OR b.ec_follw_dte < ?) "
    + "OR b.cxr_follw_dte < ?) "
    + "OR b.hs_follw_dte < ?) "
    + "OR b.bp_follw_dte < ?) "
    + "OR b.ps_follw_dte < ?) "
    + "OR b.cd_follw_dte < ?) "
    + "OR b.other_follw_dte < ?) "
    + "OR b.ts_follw_dte < ?) "
    + "OR b.sal_follw_dte < ?) "
    + "OR b.ir_follw_dte < ?) "
    + "OR b.br_follw_dte < ?))";
    PreparedStatement statement = connection.prepareStatement(sql);
    statement.setDate(1, tomorrow);
    statement.setDate(2, tomorrow);
    // One setDate for each ? bind parameter
    ResultSet result = statement.executeQuery();Now you don't have to worry about how to escape Dates, and this code works with any database.

  • Performance question when compare date with date or char with char

    Hello from Germany (Frankfurt) !
    I am working on Oracle 9.2.0.8.0
    and have to solve following problem:
    Comparison of a date and char fields.
    Now two ways to do it.
    Either I compare char with char and convert date to char,
    or I compare date with date and convert char to date.
    Now the performace question. Which operation takes more effort for the database?
    So why not to try and to see the results?
    First create table:
    CREATE TABLE TEST (
    char_date VARCHAR2(8),
    real_date DATE
    NOLOGGING;
    Then insert 1.000.000 rows
    BEGIN
    for x in 1..1000000
    loop
    insert into test (char_date, real_date) VALUES('19990101', TO_DATE('2006.01.01', 'YYYY.MM.DD'));
    end loop;
    COMMIT;
    END;
    Collect statistics
    EXEC dbms_stats.gather_table_stats('TESTER', 'TEST');
    Now run some selects for date to char conversion:
    Elapsed: 00:00:00.00
    SQL> select * from test t where TO_DATE(char_date, 'YYYYMMDD') > real_date;
    no rows selected
    Elapsed: 00:00:03.02
    SQL> select * from test t where TO_DATE(char_date, 'YYYYMMDD') > real_date;
    no rows selected
    And some selects for char to date conversion:
    Elapsed: 00:00:03.02
    SQL> select * from test t where char_date > TO_CHAR(real_date, 'YYYYMMDD');
    no rows selected
    Elapsed: 00:00:02.05
    SQL> select * from test t where char_date > TO_CHAR(real_date, 'YYYYMMDD');
    no rows selected
    Elapsed: 00:00:02.05
    SQL>
    As you see when I compare char with char and convert date to char it seems to be faster (almost 1 second)
    Is the test correct?
    I still not sure, what gets better performance...
    Any idea?
    Thanks!

    Depends on whether you want the right results or not.
    Why don't you run the following two queries and see if the difference in results tells you anything?:
    with t as (select to_date('01/02/2007', 'dd/mm/yyyy') date_col from dual
               union all
               select to_date('02/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/03/2006', 'dd/mm/yyyy') from dual)
    select *
    from   t
    where  date_col < to_date('04/03/2006', 'dd/mm/yyyy');
    with t as (select to_date('01/02/2007', 'dd/mm/yyyy') date_col from dual
               union all
               select to_date('02/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/03/2006', 'dd/mm/yyyy') from dual)
    select *
    from   t
    where  to_char(date_col) < '04/03/2006';

  • Upload data problem

    Hello eveybody
    Im facing next problem
    I have uploaded a CSV file coming from a Excell spreadshet using APEX into my database (Oracle DB 10GR1)
    all work good in the process.
    But when I compare data to select rows from table the database not locate the rows in table.
    By example the item Codigo, have a value of 'ABCD' then if I write select * from table where codigo = 'ABCD', the select dont return the rows that have this value in item Codigo.
    Any idea ?
    Thanks everybody and regards to all.

    selezeus wrote:
    Hello eveybody
    Im facing next problem
    I have uploaded a CSV file coming from a Excell spreadshet using APEX into my database (Oracle DB 10GR1)
    all work good in the process.
    But when I compare data to select rows from table the database not locate the rows in table.
    By example the item Codigo, have a value of 'ABCD' then if I write select * from table where codigo = 'ABCD', the select dont return the rows that have this value in item Codigo.
    Any idea ?
    Thanks everybody and regards to all.Perhaps there are leading/trailing spaces on the column or it's stored in mixed case format?
    If so ...
    select * from table where trim(upper(codigo)) = 'ABCD' Should bring back the data.

  • Compare data between two tables

    Hey Experts
    I am having two tables both are having same structure.
    Both r having 210 columns
    I want to compare data between these two tables.
    I used follwoing query
    select * from t1
    MINUS
    select * from t2but even if thr is diff in 1columns .. i need to search 210 columns which is the exact columns and data
    how can i find the exact columns out of these 210 columns ?

    SShubhangi wrote:
    but even if thr is diff in 1columns .. i need to search 210 columns which is the exact columns and data
    how can i find the exact columns out of these 210 columns ?This is not a trivial problem to solve. Consider a much simpler data set. In table 1 (four columns) we have
    1 A B C
    2 D E F
    3 A B Dand in In table 2 (four columns) we have
    2 X Y Z
    3 A B ENow
    select * from table1 minus select * from table2gives
    1 A B C
    2 D E F
    3 A B Dwhereas
    select * from table2 minus select * from table1gives
    2 X Y Z
    3 A B ENow clearly the first row in Table1 (ID=1) doesn't match any row in Table2 but it's only two columns out from the last row in Table2 (ID=3). However, the row in Table1 with ID=3 only doesn't match on one column.
    So, how do you represent the output?
    Clearly what you want can only be achieved if there are some columns which ought to be the same in both tables i.e. key columns. In which case you can use a full outer join link teh two tables, and case statements to display only the values which don't match:
    select t1.id as t1_id
             , t2.id as t2_id
             , case when t1.col1 != t2.col1 then r1.col1 end as t1_col1
            , case when t1.col1 != t2.col1 then r1.col1 end as t2_col1
            , case when t1.col2 != t2.col2 then r1.col2 end as t1_col2
            , case when t1.col2 != t2.col2 then r1.col2 end as t2_col2
            , case when t1.col3 != t2.col3 then r1.col3 end as t1_col2
            , case when t1.col3 != t2.col4 then r1.col4 end as t2_col2
    from table1 t1
          full outer join table2 t2
         on t1.id = t2.id;Handling nulls is left as an exercise for the reader :)
    I agree that typing all this would be extremely tedious for a table with 210 columns, but that's why Nature gave us the ability to generate SQL statements from teh data dictionary.
    Cheers, APC

  • Comparing data in the database with the input text

    hi there i have problem with the comparing data in the database with the input text. here is the piece of code of mine:
    //declaration
    datasourcedb.connect();
    String stcode = req.getParameter("txtCode");
    ResultSet rs = null;
    String action = req.getParameter("action");
    ResultSet portquery = null;
    if (action.equals("SELL"))
    -->portquery = datasourcedb.query("SELECT stockcode FROM portfolio where stockcode =\'"+ stcode + "\'");
    -->portquery.next();
    -->if((portquery.wasNull()) == true)
    disp = req.getRequestDispatcher("error.jsp"); }
    else */
    Status = "Sell";
    datasourcedb.close();
    with the code that i marked with --> it doesnt work since i have to compare the input text stcode with stockcode in the db. could anyone tell me how to compare it?
    regards
    virginia

    i have try to change into this code:
    if (action.equals("SELL"))
    portquery = datasourcedb.query("SELECT distinct stockcode FROM portfolio where stockcode =\'"+ stcode + "\' + and userName = \'"+ user + "\'");
    if(portquery.next()) {
    Status = "Sell";}
    else {               
    disp = req.getRequestDispatcher("error.jsp");
    but so far the coding doesnt give any result.... could anyone help me? since the coding does not reach status n the disp

  • "System error: Move error" on comparing DATE rows with literal timestamps

    say, I have a table consisting of a DATE and a TIMESTAMP column:
      create table test (
      d date,
      ts timestamp
    now the problem:
    when I try to retrieve values using a statement like this (using MaxDB's SQL Studio or via JDBC):
      select * from test
      where  d >= {ts '2007-06-18 12:19:45'}
    it produces the following error:
      General error;-9111 POS(36) System error: Move error
    So, I am not able to compare DATE columns with timestamp values?
    In contrast, the following combinations all work flawlessly:
      select * from test
      where  d >= {ts '2007-06-18 12:19:45'}
      select * from test
      where ts >= {d '2007-06-18'}
      select * from test
      where  ts >= {ts '2007-06-18 12:19:45'}
    Thus, the opposite direction (comparing a TIMESTAMP column to a literal date value) apparently poses no problem to the MaxDB database engine.
    Unfortunately, I cannot just resort to "truncating" the timestamp values and using the {d ...}-Syntax, because I am using Apache's Torque object-relational mapper which generates the statement like this and feeds the JDBC API with it. Anyway, I deem this a bug in MaxDB, especially with respect to the quite obscure error message.
    I can reproduce this issue on both MaxDB 7.5 and 7.6 server, using client software (SQL Studio), version 7.5 and 7.6 as well.
    Does anybody know this problem?
    TIA,
    Alex

    Hi,
    this is a new bug and we will fix it with one of the next versions of MaxDB.
    You can watch the proceeding in our internal bug tracking system:
    http://www.sapdb.org/webpts?wptsdetail=yes&ErrorType=0&ErrorID=1151609
    Thank you for reporting it.
    Kind regards
    Holger

Maybe you are looking for

  • Installing itunes on windows 7 64 bit pc

    I have tried several times to install iTunes on my Windows 7 64 bit PC, and I get the following error: I am trying to use iTunes to backup my 3GS phone data so I can upgrade to an iPhone 4GS, but can't install iTunes.  Can anyone help?

  • Error Message - Files found in Library not imported

    Every time that I open iPhoto it gives me an error message saying "1918 photos have been found in the iPhoto Library folder that were not imported". If I select "Yes" to import it will cause the program to crash and say that it closed unexpectedly. T

  • OBIEE 11G Performance Threshold

    OBIEE 11g / Teradata Is it worth the time and effort to build OBIEE Dashboards / Reports from a database having 500 million records. If not then what is an acceptable number i.e. 100 million? Thanks in advance.

  • Total Quantity in BOM

    I am creating new BOM like F1 as finished Goods(Parent Item) C1 as Child Item(Raw Materials) C2 as child Item(Raw Materials) then I want to sum all Raw materials without save the BOM document.means how many raw materials using ? before adding the doc

  • Project Professional 2013: Reports / texbox BUG

    I am using the reporting functions for a Project Status Report and found a quite annoying issue. As I need textboxes for general statements in my reports I discoverd that the navigation and correction keys (arrow-keys, backspace key, delete key, etc)