Select where timestamp between date1 and date 2

try a lot of variations but still dont work
this was my last shot, then i come here ask for help
the field DATAHORAS is timestamp
data1 and dat2 will come from a form
To_Date(S.DATAHORAS, 'dd/mm/yyyy hh24:mi:ss')
Between Cast(To_Date(:data1) As TimeStamp) And Cast(To_Date(:data2) As TimeStamp)
thanks in advanced

No. You don't need to. But....
Edit: I was originally using a stupid example using DUAL which was completely misleading - sorry.
Originally I used the example below to show that you don't have to do an explicit conversion.
Things will still work comparing timestamps and dates.
SQL> select systimestamp, sysdate, sysdate+1
  2  from dual
  3  where systimestamp between sysdate and sysdate + 1;
SYSTIMESTAMP                        SYSDATE              SYSDATE+1
09-FEB-10 13.58.35.712017 +00:00    09-FEB-2010 13:58:35 10-FEB-2010 13:58:35But then I added an explain plan to show that implicit conversions were going on:
1  explain plan for
  2  select systimestamp, sysdate, sysdate+1
  3  from dual
  4* where systimestamp between sysdate and sysdate + 1
SQL> /
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 4192335797
| Id  | Operation        | Name              | Rows  | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT |                   |     1 |     1   (0)| 00:00:01 |
|*  1 |  FILTER          |                   |       |            |          |
|   2 |   INDEX FULL SCAN| SYS_IOT_TOP_57625 |     1 |     1   (0)| 00:00:01 |
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
   1 - filter(SYS_EXTRACT_UTC(SYSTIMESTAMP(6))<=SYS_EXTRACT_UTC(SYSDATE@
              !+1) AND SYS_EXTRACT_UTC(SYSTIMESTAMP(6))>=SYS_EXTRACT_UTC(SYSDATE@!))
15 rows selected.
SQL>However, this example is misleading because it's not the same implicit conversion you get with a proper table with a timestamp column:
SQL> create table t1
  2  (col1 timestamp);
Table created.
SQL> ed
Wrote file afiedt.buf
  1   explain plan
  2   for
  3   select *
  4   from   t1
  5   where col1 between to_date('08-JAN-2010','DD-MON-YYYY')
  6*             and     to_date('09-JAN-2010','DD-MON-YYYY')
SQL> /
Explained.
SQL>
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 3617692013
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT  |      |     1 |    13 |     2   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T1   |     1 |    13 |     2   (0)| 00:00:01 |
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
   1 - filter("COL1">=TIMESTAMP' 2010-01-08 00:00:00' AND
              "COL1"<=TIMESTAMP' 2010-01-09 00:00:00')
Note
   - dynamic sampling used for this statement
18 rows selected.
SQL>Which is really what you want.
It has an implicit conversion on the date parameters and no implicit conversion on the column which would prevent index usage if there were an index.
Interestingly if you explicitly convert the dates to a timestamp, then you can get an extra filter predicate comparing the two parameters:
SQL> explain plan
  2  for
  3  select *
  4  from   t1
  5  where col1 between cast(to_date('08-JAN-2010','DD-MON-YYYY') as timestamp)
  6             and     cast(to_date('09-JAN-2010','DD-MON-YYYY') as timestamp);
Explained.
SQL>
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 3332582666
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT   |      |     1 |    13 |     2   (0)| 00:00:01 |
|*  1 |  FILTER            |      |       |       |            |          |
|*  2 |   TABLE ACCESS FULL| T1   |     1 |    13 |     2   (0)| 00:00:01 |
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
   1 - filter(CAST(TO_DATE(' 2010-01-08 00:00:00', 'syyyy-mm-dd
              hh24:mi:ss') AS timestamp)<=CAST(TO_DATE(' 2010-01-09 00:00:00',
              'syyyy-mm-dd hh24:mi:ss') AS timestamp))
   2 - filter("COL1">=CAST(TO_DATE(' 2010-01-08 00:00:00', 'syyyy-mm-dd
              hh24:mi:ss') AS timestamp) AND "COL1"<=CAST(TO_DATE(' 2010-01-09
              00:00:00', 'syyyy-mm-dd hh24:mi:ss') AS timestamp))
Note
PLAN_TABLE_OUTPUT
   - dynamic sampling used for this statement
23 rows selected.oracle version 11.1.0.6
Sorry about the mistakes in previous version of this reply.
Edited by: DomBrooks on Feb 9, 2010 2:25 PM

Similar Messages

  • How to achieve that "SELECT * FROM table WHERE age BETWEEN 18 AND 23 AND n"

    How to achieve the SQL like that "SELECT * FROM table WHERE age BETWEEN 18 AND 23 AND name = 'Will' " with BDB C-API
    The primary key in the primary database is 'age' ,and the secondary key in the secondary index is 'name' ,in a lot of examples ,there are all simple , but how to do that complex one.thx~

    but this means that the prepared statement is created
    each time I call my method and so I'm not sure that
    the optimizer will find it easy to cope with.You are right, the optimizer won't find that easy to deal with (presuming that is even relevant for your driver/database.) But most optimizers won't do anything with statements that change and that is what you are doing.
    You could create several prepared statements which have a common number of bind variables. For example 10 statements with from 1 to 10 bind values. This will work if most of the queries use those.

  • Incorrect doc.no.: select document number between 82139259 and 000000000

    Hi Expert,
    When i try to to Release to Accounting t for a Billing Document (VF02)-->Change Billing Document --> Release to Accounting, It is not creating accounting Document instead it Says the Below Error.Pls Help to resolve this.
    Incorrect doc.no.: select document number between 82139259 and 00000
        Message no. F5151
    Diagnosis
        The document number you specified, "&v1", is not in the ap
        number range. The number range is dependent on the documen
        The exception to this rule is formed by recurring entry do
        must use number range 'X1' and sample documents, which mus
        range 'X2'.
        Possible reasons for this error message are:
        o  You have entered an incorrect document number.
        o  An incorrect document number was transferred to this ap
           during an update from another application (e.g. CO).
    System response
        The document cannot be processed any further.
    System response
        The document cannot be processed any further.
    What to do
        o  Enter a document number that is within the specified number interval.
        o  If this error was caused by an update from another application, check
           the type of number assignment in that application (external or
           internal?) as well as the document number transferred.
    Example
        In the CO settlement profile, a document type with external number
        assignment was entered, whereas an internal document number was
        transferred.
    PLs Help
    Zubair
    Edited by: MhdZubair on Mar 22, 2011 10:42 AM

    Hi,
    Please refer the link :
    Incorrect doc.no.: 2. Select document number between 6300000000 and 6399999
    Regards,
    Pramitha.

  • Sum Debit and Credit where code between 1001001001 and 1001001999 in Report

    Hi all
    I Create a Simple Report
    Which is
    SELECT initcap(Acc_name),to_char(acc_id),to_char(acc_id),control_detail,+
    Opening_balance, NVL(cb.C,0) as Credit, NVL(Cb.D,0) as Debit,+
    Opening_balance+NVL(cb.D,0)-NVL(Cb.C,0) Closing_balance,+
    Cb1.dr,cb1.cr,+
    Opening_balance+NVL(cb.D,0)-NVL(Cb.C,0)+nvl(cb1.Dr,0)-nvl(cb1.Cr,0)Ending+
    from COA,+
    *(Select cb_acc_id,sum(nvl(dabit,0)) D ,sum(nvl(credit,0)) C from cb*
    where vdate < :Date_from+
    Group by cb_acc_id)CB,+
    *(Select cb_acc_id,sum(nvl(dabit,0))Dr ,sum(nvl(credit,0))Cr from Cb*
    Where vdate between nvl(:Date_from,vdate) and nvl(:date_to ,vdate)+
    Group by cb_acc_id)CB1+
    Where acc_id = cb.cb_acc_id (+) and+
    acc_id =cb1.cb_acc_id (+)+
    CONNECT BY PRIOR acc_id = CATAGORY_id+
    START WITH acc_id between 01 and 1000+
    ORDER SIBLINGS BY acc_id+
    Now i need To sum Debit and Credit where code between 1001001001 and 1001001999
    Need Help
    Regard
    Shahzaib ismail

    Hi,
    Usually it can be determined using the field shkzg. If it contain 'S' its debit and if it contains 'H' then its credit.
    Before showing the amount you need to do like;
    IF wa_gl-shkzg = 'H'.
    wa_gl-dmbtr = wa_gl-dmbtr * (-1). " dbmtr - amount
    ENDIF.
    This will solve your problem.
    Regards
    Karthik D
    Edited by: Karthik D on Jun 3, 2009 12:29 PM

  • Default selection on current month, week and date

    Hi,
    We are on Dashboard 4.1 sp3 the same version as BI.
    The dashboard report is using LiveOffice connection. We are now facing an issue with default selection on current month, week and date.
    The dashboard report drilled down from month, to week, then to date. The dashboard feed -live office report is on month/week/date ascending order - becuase we have running average calcualtion on LO report, it seems have to be in ascending order to get the correnct runnning average.
    I tried to on Insertion to change default seletion, it works on month, but it doesnt working on week and daily.
    but when LO report is on ascending order, on dashboard column chart the default selection is not on the current month, week and date.
    Is there a way to solve the issue. Could anyone please help.
    Thanks,

    Hi Suman,
    Thanks for the quick reply.
    Do you mean I Enable sorting -by categrory labels on Behaviour - common tab.
    Thanks,

  • SAP APO Link between pegid and date

    Hi all,
    It's exist a link between pegid and data (order's data)  ??
    Tks,
    bye.

    Please check FM in se37
    /SAPAPO/OM_PEGID_SELECT_ORDERS
    /SAPAPO/OM_PEGID_GET_ORDERS
    Manish

  • Incorrect doc.no.: 24. Select document number between 0090000000 and 009999

    Hi All,
    I created billing doc, it save and gave the number but with error on account determination, i checked the no range corrected it and got the error: Incorrect doc.no.: 24. Select document number between 0090000000 and 0099999999.
    Please Help.
    Maureen.

    I very much hope you've done it in a test system.
    It seems that your document was given number 24, according to the number range that existed at that time. Then you went and changed the number range to 900000... and, naturally, number 24 is not within the valid range anymore. So what else did you expect?
    If it was (fingers crossed) a test system, just forget about that document and create a new one. Otherwise you'll have to change the range back, then cancel the document 24 (make sure the cancellation does not post to accounting either), then change the range again.

  • Link Between PSA and Data Targets

    Hi Experts,
    Could you please help me is there any table which will have PSA & data target (Cube or ODS) details.
    I know the table which will have data target manage screen details and other table wil give the details like data loaded into till PSA.
    But i want to know any SAP table will have link between PSA & data target.
    I want to know if the request is loaded till PSA or it is loaded into data target.
    Any table will give details like PSA request no, if target is there then some kind of flag like....
    Please let me know if any one know the table which will have PSA as well as Data target details.
    Thaks in Advance
    Shaik

    Hi,
    I clearly mentioned im aware of Manage screen details table, i want link between PSA and Data target table which will return if requst loaded till PSA or PSA & target.
    Im using BI 7.0 .
    Regards
    Shaik

  • What is the difference between olap and data warehouse..?

    Hi All,
    Is their any difference between olap and data warehouse..? Please let me know your knowledge about these. Thank you..
    ------------------------------------------------------------------------ Please mark it as complete, if you get the solution with this reply. TQ.

    A data warehouse is a database containing data that usually represents the business history of an organization. This historical data is used for analysis. Data in a data warehouse is organized to support analysis rather than to process real-time transactions
    as in online transaction processing systems (OLTP).
    OLAP technology enables data warehouses to be used effectively for online analysis, providing rapid responses to iterative complex analytical queries. OLAP's multidimensional data model and data aggregation techniques organize and summarize large amounts
    of data so it can be evaluated quickly using online analysis and graphical tools.
    Reference:
    http://technet.microsoft.com/en-us/library/aa197903(v=sql.80).aspx
    http://stackoverflow.com/questions/18916682/data-warehouse-vs-olap-cube
    If this post answers your query, please click "Mark As Answer" or "Vote as Helpful".

  • Between function for dates in Docmd.OpenReport rptName,,[date-filed] BETWEEN #date1# AND #date2# .. NOT WORKING

    Please assist, this is a nightmare indeed.
    Am trying to filter records in a report using the BETWEEN function, as below:
    strCondition = "Format([tblOrderLineTrack_main].[dtAllocation],'dd/MM/yyyy') BETWEEN Format(#06/02/2015#,'dd/MM/yyyy') AND Format(#07/03/2015#,'dd/MM/yyyy')" 
    DoCmd.OpenReport strDocName, acViewPreview, , strCondition, acWindowNormal
    The report is bringing up all records including those outside the specified range. What could be wrong with this???? Please assist, I am going nuts over this...

    The date literals I used are in the
    ISO standard for date notation of YYYY-MM-DD so are internationally unambiguous.  The only circumstance I can envisage in which it would not return the rows expected would be the extremely unlikely one where all the rows with dates in the range happen
    to have a date of 7 March 2015, and all have a non-zero time of day element.  There is no such thing in Access as a date value, only a date/time value so #2015-03-07# in fact represents the point of time at midnight at the start of 7 March 2015. 
    Any rows with date/time values of that date, but with a non-zero time of day would consequently fall outside the range.
    The above is so unlikely that I can't believe it to be the case, but the bullet-proof syntax would be:
        strCondition = "dtAllocation  >= #2015-02-06# " & _
              "AND dtAllocation < #2015-03-07#+1"
    i.e. all date/time values on or later than the start of the first day of the range (#2015-02-06 00:00:00#) and before the start of the day following the end of the range (#2015-03-08 00:00:00#)
    Assuming that the dtAllocation column is of date/time data type, and is returned as such in the report's RecordSource, not as a formatted string expression, I can see no reason on the information available why the above should not work, so if the report is
    still not returning any data some other reason not apparent to us must be suspected.  We are not in a position to debug the report, however, so what that might be I can't say.
    Ken Sheridan, Stafford, England

  • Reg Differrences between SynBo and Data Object

    Hi,
            I want to know the architectural diffrences between a SyncBo of MI 2.5 and Data Object of NWM 7.1.  As it is given in help.sap.com documentation I think A data object support multiple levels of parent- child hirearchy where as a SyncBo is limited to one level of Header and Items.Similarly do any other differences exist?
    2) In what way A data Object concept is better than that of a Synco.?
    3) For manipulating the data of a data Object on Front end, Can we Use the existing SmartSync API of MI 2.5, or a seperate API for client side is going to be released?
    Thanks in Advance,
    Rajesh

    Hello Rajesh,
    1. The differences are small. You pretty much highlighted the biggest one (multi child node). Other differences exist in the fact that a SyncBO is linked to a backend BAPI as the DO is not (you would usually create the DO with the fields you need and then have backend adapters to fill it). Lifecycle of the DO is also different. Even release, non destructive change can happen and old application as well as new application will work at the same time. I can list a couple more, but I think you get that a SyncBO is different than a DO (even if in our development we still get mix both wording:))
    2. Yes DO is a better concept than SyncBO.
    3. There are 3 ways of accessing API on the client side. The first is the old SmartSync API which is only used in backward compatibility application (MAM for example). It should not be used for new development, but only to leverage existing one. After that you have two new frameworks for laptop and for PDA that you can find in NWDS 7.1. They reviewed the naming so I am not sure of the current ones, but I think it is something like Mobile Application for Handheld and Mobile Application for Laptop. Those two new framework uses WebDynPro flavored UI and provide access to the sync/data layer.
    Thank you,
    Julien.

  • Relation between psa and data source

    Hi everyone,
    What is the relation between DataSource and PSA.

    PSA tables get created when u activate datasource in BW...replication is just required for purpose of Meta data loading for that data source....PSA will store data temporarily when u will load data from R/3....just u can manage PSA request datasource wise....by right clicking datasource...selecting manage tab u can see all the PSA req corresponding to that particular datasource.

  • Releation between fields and data element

    Dear Abapers,
    What is the relation between the fields and data element,  while cretion of fields system will ask the data element, can we have one data element to more than one fields.  Can you plese explain me.
    Regards

    Hi,
    data elements are structures defined in SAP Dictionary. 
    Fields you meen in a table? or in programs? in both places you create in reference to SAP Dictionary. 
    data element char20.  TEXT20
    Programs  data:  l_text type char20.
    Tables  ... field   ZTEXT  type CHAR20...TEXT20

  • Where is the documents and data option?

    I don't have the documents and data switch in iCloud settings on my iPhone 6. Ive checked my friends iPhone 6 and he has it. I've tried to lookup a possible answer but all I have found is to remove my profile which I don't have.
    I just have one iCloud.
    Any ideas?

    No I don't, I don't have Yosemite on my macbook yet. Will it benefit me If I put iCloud drive on my phone even if I don't have it on my macbook?
    The reason I want to be able to fix this issue is because I have an app: Clear that I want to sync with iCloud so that it matches my macbook Clear app. When I try to turn on iCloud in the apps settings on my phone it tells me that I have to enable iCloud documents & data.
    Thanks for the help!

  • What is a Reasonable Tradeoff Between System and Data Space in Windows 7 64bit?

    I have a brand new W530 with the 500 GB HD -- 445 GB actual total space in C: ("Windows7_OS"), including about 85 GB of OS, pre-installed applications, and Lenovo bloat-ware).  I plan to create a separate user-data partition by stealing space from the OS partition, call it E:, and to re-direct user Documents, Pictures, etc. directories plus the Outlook PST file there.  Thus C: will be reserved mainly for Windows, Page File, Crash Dump, Restore Points, and new software installation.
    Any thoughts about a reasonable division of drive space between these two partitions?  Coming from Windows XP 32bit on a much smaller HD, I have little idea what to expect in terms comfortable space requriements for Windows 7 64bit.  (I realize I can re-size the partitions later, but it seems best to start with realistic allocations...) -- JCW2
    Solved!
    Go to Solution.

    It is hard to comment without some idea how the machine will be used. Some applications are not very well behaved and install on the c: drive regardless of what you do. Some functions, like the briefcase functions in windows 7 are harder to get off c:, although it can be done. (I got it right the second time I tried) If you share files using briefcase, you end may up with most of your data on c:. I decided I wanted to boot from an SSD, but I needed more data, so I put in a 256GB mSATA drive and moved my boot partition there. I used my entire HD for data. That worked out well for me.

Maybe you are looking for

  • Problem with 3.2.1: versions no longer appear separately from master

    Before updating Aperture to 3.2.1, whenever I made adjustments to an image, a version would be created and would be separate from the master, which was useful for me to compare before and after. Now, after updating to 3.2.1, whenever I make adjustmen

  • Update Bluetooth 2.0

    I can't update my Bluetooth Firmware to 2.0 with Software Update. It says: "There was a problem updating Bluetooth so that the update cannot continue. Turn off any unnecessary Bluetooth devices you are using and try updating again." Also, I am new on

  • Power view reports in sharepoint 2013 :

    How can i add alert and subscription for the power view report in sharepoint 2013 ?.  and please let me know the difference beetween the performance point service and power view report. Please response fast.

  • Hotmail will not function properly

    As of 19th June 2011 i have been unable to use Hotmail in Firefox. The page loads up and inbox button will work but no other function whatsoever does anything. I have tried running in safe mode, and uninstalling, but nothing changes. I really need to

  • Adobe Creative Suit 6 Design & Web Premium fulfilment online Problems???

    Just bought the Adobe Creative Suit 6 Design & Web Premium and iv been trying to fill in the adobe student and teacher edition order fulfillment online but it doenst do anything when iv filled it out and pressed process???.... iv spoken to someone on