How to use date column index

Hi,
Why is that I got different results for my queries?
Note that emp_date is indexed, so i dont want to use
a function to it.
QUERY1(full table scan)
SELECT COUNT(*) FROM EMP WHERE TRUNC(EMP_DATE)=TRUNC(SYSDATE-30); (RESULT=8,842)
QUERY2
SELECT COUNT(*) FROM EMP WHERE
EMP_DATE >=(SYSDATE-30) and EMP_DATE < (SYSDATE-30); (RESULT=0)
QUERY3
SELECT COUNT(*) FROM EMP WHERE
EMP_DATE BETWEEN TRUNC(SYSDATE-30) and TRUNC(SYSDATE-30); (RESULT=2,100)
Please help me how to use indexed date column...

> Why is that I got different results for my queries?
Because your queries are different.
1) This one selects all records on 20 october, regardless of their time component
2) This one selects all records with an emp_date at least being 20 october 14:56:30 AND being smaller than 20 october 14:56:30. No record will ever satisfy this condition.
3) This one selects all records on 19./20 october at midnight 00:00:00
Please see this example:
SQL> create table myemp (emp_date)
  2  as
  3   select trunc(sysdate) - 30 +
  4          case
  5          when level <= 2100 then 0
  6          when level <= 8842 then dbms_random.value(1,86399)/86400
  7          else 2
  8          end
  9     from dual
10  connect by level <= 100000
11  /
Tabel is aangemaakt.
SQL> create index i1 on myemp(emp_date)
  2  /
Index is aangemaakt.
SQL> exec dbms_stats.gather_table_stats(user,'myemp',cascade=>true)
PL/SQL-procedure is geslaagd.
SQL> set autotrace on explain
SQL> select count(*) from myemp where trunc(emp_date)=trunc(sysdate-30)
  2  /
                              COUNT(*)
                                  8842
1 rij is geselecteerd.
Uitvoeringspan
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=88 Card=1 Bytes=8)
   1    0   SORT (AGGREGATE)
   2    1     TABLE ACCESS (FULL) OF 'MYEMP' (Cost=88 Card=1000 Bytes=
          8000)
SQL> select count(*) from myemp where
  2  emp_date >=(sysdate-30) and emp_date < (sysdate-30)
  3  /
                              COUNT(*)
                                     0
1 rij is geselecteerd.
Uitvoeringspan
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=8)
   1    0   SORT (AGGREGATE)
   2    1     FILTER
   3    2       INDEX (RANGE SCAN) OF 'I1' (NON-UNIQUE) (Cost=4 Card=2
          50 Bytes=2000)
SQL> select count(*) from myemp where
  2  emp_date between trunc(sysdate-30) and trunc(sysdate-30)
  3  /
                              COUNT(*)
                                  2100
1 rij is geselecteerd.
Uitvoeringspan
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=8)
   1    0   SORT (AGGREGATE)
   2    1     FILTER
   3    2       INDEX (RANGE SCAN) OF 'I1' (NON-UNIQUE) (Cost=4 Card=2
          50 Bytes=2000)
> Please help me how to use indexed date column...
Use this query instead:
SQL> select count(*)
  2    from myemp
  3   where emp_date between trunc(sysdate)-30 and trunc(sysdate)-29 - interval '1' second
  4  /
                              COUNT(*)
                                  8842
1 rij is geselecteerd.
Uitvoeringspan
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=8)
   1    0   SORT (AGGREGATE)
   2    1     FILTER
   3    2       INDEX (RANGE SCAN) OF 'I1' (NON-UNIQUE) (Cost=4 Card=2
          50 Bytes=2000)Regards,
Rob.

Similar Messages

  • Hi in the between operator how to use date column

    Hi
    I have one small doubut ,once i try to get the results perticular between dates ,it not working
    ex:- in the emp table i try get the employess u hire between 01-jan-80 to 03-jan-80
    once i use query select * from emp where hiredate between '01-jan-80' and '03-jan-80'
    it is display differnt data.
    plz help i want data only 01,2nd and 3rd jan data only how to write query.
    Thank's

    Hi,
    When you want to hard-code a DATE, don't just use a string. Use the TO_DATE function, for example
    TO_DATE ( '01-jan-1980'
            , 'dd-mon-yyyy'
            )or use a DATE literal (always specified in 'YYYY-MM-DD' format):
    DATE '1980-01-01'Remember that DATE expressions always include the time of day. If you use TO_DATE without specifying the time, or a DATE literal (as I did above) the time defaults to midnight, which is the first point in time on that day.
    If you are certain that your all DATEs in your table are at midnight, you can use BETWEEN like this:
    select  *
    from      emp
    where      hiredate between TO_DATE ('01-jan-1980', 'dd-mon-yyyy')
               and       TO_DATE ('03-jan-1980', 'dd-mon-yyyy')
    ;If your table did have a hiredate such as January 3, 1980, 10:35 am, the query above would not choose it (because 10:35 is later than midnight.)
    Because of the problems with BETWEEN, some people do two comparisons instead:
    select  *
    from      emp
    where      hiredate >= TO_DATE ('01-jan-1980', 'dd-mon-yyyy')
    and      hiredate <  TO_DATE ('03-jan-1980', 'dd-mon-yyyy') + 1
    ;This will pick anything on January 3, 1980, regardless of its time.
    Edited by: Frank Kulash on Aug 5, 2009 10:49 AM

  • How to get the column index inside a dataTable

    Hello,
    before I get staked, there are multiple threads handling familiar topics to the one I'm questioning about but none gives an anwer. If there is one, I'm propably to less skilled to see it.
    So here is my Problem: I've build a web-interface to a time-recording system. The hours worked on a certain project are displayed in a dataTable component which is generated out of a mySQL Query. Each entry (column/row) contains a inputText component to display and edit the specific value.
    Editing one of these inputText elements now fires a valueChangeEvent which reads the new value and stores it in the database. For that cause I need to know the row- and column-index of the inputText component that fired the event.
    Using the getClientId method from the valueChangeEvent I get some Information which makes it possible to calculate the row/column index. A typical clientID looks like "form_table:mainTable:0:_id14". "form_table" is the ID of the form the dataTable is in. "mainTable" is the id of the dataTable component. "0" is the row the component is in. And finally "_id14" stands for the id randomly given to the inputText component by JSF.
    My Problem is now, that though I can calculate the column out of the[i] "_id14", this calculation is hardcoded. So everytime I add a component in before the dataTable, the calculation needs to be adjusted in the code.
    The Questions:
    - How to force a sensefull id indicating a column-index for the inputText components inside the columns of a dataTable?
    - Nicer since no workaround: How to get the column-index inside the dataTable on a natural way? (e.g. out of the valueChangeEvent the specific inputText component fires)
    After some investigation here on the board and on the net I know multiple ways to get the row index, (Things like component-binding and so on) but I can't find a answer on how to get the column-index.
    Thanks to all answers and/or links to things my eyes missed while searching for one.

    ...then index 0 becomes index 1 and my program doesn't work properlyThe program works properly, just not as you expect it to.
    As you've noticed the table gives you the flexibility to move columns around. So if you move column 0 to column 1, why would you expect to still use 0 as the index? The table manages the reordering of columns for you to make sure the data being displayed in each table column comes from the correct column in the data model.
    You can manage this yourself using one of the following methods (I forget which one):
    table.convertColumnIndexToModel(int viewColumnIndex)
    table.convertColumnIndexToView(int modelColumnIndex)
    Or, you can get data from the data model directly:
    table.getModel().getValueAt(row, 0);

  • How to use the Columns Hidden | space in the bottom of af:panelCollection?

    Hi,experts,
    In jdev 11.1.2.3,
    I can see a row of Columns Hidden | Columns Frozen in the bottom of component af:panelCollection - pc1 which have an af:table - t1 component inside in designer view,
    and can see there is a blank row space only with "|" inside when the page is running.
    Now I want to use this blank row space such as to display row numbers for the table, so I set the property for the panelColletion as following source code:
    ==========================
    <af:panelCollection id="pc1" inlineStyle="width:1250px; height:500px;">
    <f:facet name="menus"/>
    <f:facet name="toolbar"/>
    <f:facet name="statusbar">
    <af:group id="g4"/>
    </f:facet>
    <af:table value="#{bindings.TView1.collectionModel}" var="row"
    rows="#{bindings.TView1.rangeSize}"
    emptyText="#{bindings.TView1.viewable ? 'No data to display.' : 'Access Denied.'}"
    fetchSize="#{bindings.TView1.rangeSize}" rowBandingInterval="1"
    filterModel="#{bindings.ImplicitViewCriteriaQuery.queryDescriptor}"
    queryListener="#{bindings.ImplicitViewCriteriaQuery.processQuery}" filterVisible="false"
    varStatus="vs"
    selectedRowKeys="#{bindings.TView1.collectionModel.selectedRow}"
    selectionListener="#{bindings.TView1.collectionModel.makeCurrent}"
    rowSelection="single" id="t1" inlineStyle="font-size:xx-large; font-weight:bolder;">
    <af:column sortProperty="#{bindings.TView1.hints.GoodsStatus3.name}" filterable="true"
    sortable="true"
    headerText="#{bindings.TView1.hints.GoodsStatus3.label}"
    id="c42">
    <af:outputText value="#{row.GoodsStatus3}" id="ot33"/>
    </af:column>
    <f:facet name="footer">
    <af:group id="g3">
    *<af:outputText value="RowsNumber:" id="ot44"/>*
    *<af:outputText value="#{bindings.TView1Iterator.estimatedRowCount}"*
    id="ot43" partialTriggers="::pc1:t1"/>
    </af:group>
    </f:facet><f:facet name="detailStamp"/>
    </af:table>
    </af:panelCollection>
    =====================
    but when run the page there is no display for the row number, instead on the bottom of the table, there is only a blank row with "|" inside.
    How to use the Columns Hidden | Columns Frozen space in the bottom of component af:panelCollection ?
    Thanks!

    Hi, Arun
    It works.
    As in my use case, can draw an af:toolbar component into statusbar of Panel Collection facets in Structure view.
    There is still a small issue:
    cannot see the Columns Hidden|Columns Frozen component in the Structure view,
    and if drop more than one af:toolbar into statusbar, the sencond one will fall/wrap into second row, even though there is enough space on the first row (to occupy a second row in statusbar will be a waste of space), and cannot see how to adjust.
    Thank you very much!
    bao

  • How to  use data function using characterstics variable for calculation on

    how to  use data function using characterstics variable for calculation on  attribute as key figure

    Hi Gayatri
    Did you not see my answer for CASE because CASE does indeed offer the use of the BETWEEN clause, but DECODE does not. Let me give you a little synopsis of DECODE.
    In its most simple form it takes 4 values and looks like this: DECODE(A, B, C, D)
    This essentially means, IF A = B THEN C ELSE D
    The trick to solving BETWEEN in a DECODE is to work out algoriths where A = B. Because we don't know how many values are between 00 and 99, although I could guess there were 100 we could of course have 100 parts in the DECODE but that would be awful. How about if we look at it another way and say this:
    IF PART_NUMBER < 'SDK00' THEN pay_amount
    ELSE IF PART_NUMBER > 'SDK99' THEN pay_AMOUNT
    ELSE pay_amount + 100
    This statement only had 2 hard coded values, but how to make DECODE work with less than? Easy, we use the LEAST function. The LEAST function takes 2 values and returns the one with the lowest value. So I use LEAST(PART_NUMBER, 'SDK00') then whenever the PART_NUMBER is lower than SDK00 it will be true. A similar situation exists for the opposite function GREATEST. Putting all of this together then, you can do this:
    DECODE(PART_NUMBER, GREATEST(PART_NUMBER, 'SDK00'), DECODE(PART_NUMBER, LEAST(PART_NUMBER, 'SDK99'), PAY_AMOUNT * 100, PAY_AMOUNT), PAY_AMOUNT)
    In English this can be read as follows:
    IF the PART_NUMBER is greater than or equal to SDK00 and the PART_NUMBER is less than or equal to SDK99 THEN PAY_AMOUNT x 100 ELSE 0
    Best wishes
    Michael

  • Can u  tell me any of you how to use Date class

    Can u tell me any of you how to use Date class. Please send me the source code.

    People won't send you the source code.
    Ask specific questions. You are very vague.
    Tell me how to build.

  • How to use numeric column in BI Publisher 11g Data Model?

    Hi Gurus
    I was able to create a link(join) in Data model when I used VARCHAR column.
    However if I used numeric column I got an error
    Any ideas?
    Thanks
    Laszlo

    Can you please post the error message?
    Regards,
    Kalyan Chukkapalli
    http://123obi.com

  • How to use text based index

    Hi,
    I want to use a text based index. The problem statement was i have to delete all those records which have column
    'ABC%'
    means data can be ABC1, ABC2, ABCl, ABCn
    so i thought i would do like
    delete from tab1
    where col1 like 'ABC%'.
    There are millions of records.
    so i thought of optimizing the Query by using text based index. If my approach is right can you suggest how i can implement it and Is there any other way around?
    Thanks
    _vinod                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Are you saying that simple b tree index would be used in a qurey where i have used LIKE operator? Yes. Not "would" but certainly "could", as long as wildcard is trailing.
    Now whether it "would" depends on whether it's estimated to be the cheapest access path.

  • How to drill date (column )into month in xcelsius

    Hi,
    I am fresher to Xcelsius. I need to know how to drill the date column into month, then further drilling down month to day.
    I have 2 columns
    Date                       Revenue
    1/1/2010                 452553
    2/2/2011                  97992
    3/5/2011                  23526
    4/3/2011                 63563
    If i click " 1/1/2011" date column, i need to see the corresponding month data in seperate chart( i need to get the detailed data).
    I need to know how the datas should be arranged in excel.
    Thanks in Advance
    Regards,
    Abirami

    Hi Abirami,
    To filter out date, you can use calendar component in Xcelsius. This article explains how to use the calendar component in an interactive way.
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/b05b0244-0453-2e10-b4b3-fab707baddaf
    Then with the help of an invisible combo box as explained in the article to could get just the selected month's data in bar chart.
    Hope this helps.
    Regards,
    Anju Saseendran

  • How to use Data Navigation in OBIEE11g

    Hi,
    I read an article about BIEE 10g feature: Data Navigation (click on a record in Analytics report1 and corresponding drill down data show in Analytics report2). I found that there are some setting "Type: Navigate" in "Value Interaction" should be set in Tab: "Column Format" of Column properties in BIEE 10g (pls refer to: http://gerardnico.com/wiki/dat/obiee/navigation).
    However, I didn't find these setting in OBIEE 11g. How do I use Data Navigator in OBIEE 11g? Is this features is disabled?

    *1. Firstly, what means of "Column (should be filtered)?*
    The column in Criteria you should give the *Filter*
    2. Table.Column -> Column Properties -> Interaction -> Value (Primary Interaction) -> Action Links -> Add (+ Symbol in Green color) -> Action -> Click *Navigate to BI Content* -> Select the Report from the Shared folder -> OK and Save the report.
    Thanks,
    Balaa...

  • How to make date column sortable which has inline case in report

    Hi all,
    I have date column which has inline case to check for expiration and display text 'expired' along with date. This column is set to be sortable. On sorting, it is doing based on char not on date. How can I retain this inline case along with getting correct sort order on clicking column header ?
    Thanks!

    982185 wrote:
    Hi all,Welcome to the forum: please read the FAQ and forum sticky threads (if you haven't done so already), and update your profile with a real handle instead of "982185".
    When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
    <li>Full APEX version
    <li>Full DB/version/edition/host OS
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)
    <li>Browser(s) and version(s) used
    <li>Theme
    <li>Template(s)
    <li>Region/item type(s) (making particular distinction as to whether a "report" is a standard report, an interactive report, or in fact an "updateable report" (i.e. a tabular form)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand.
    I have date column which has inline case to check for expiration and display text 'expired' along with date. This column is set to be sortable. On sorting, it is doing based on char not on date. How can I retain this inline case along with getting correct sort order on clicking column header ?Note comments above regarding the importance of stating whether you are using a standard or interactive report.
    Here's 2 possible techniques, which you can modify to fit how you want "expired" values to be sorted:
    <li>{message:id=10609805}
    <li>{message:id=4175275}
    The second one is the best approach if using a standard report, or an interactive report in APEX 4.2.

  • How to get the column index of the selected column

    Hi All,
    I have a dynamically populated advanceddatagrid. Iam trying to edit any column of a particular row. In my as file im able to get the row index using selecteditem property. But I need to get the column Index and the updated value of the column to be passed from the as file to the java method.
    So that I can update the DB with the updated value. Can somebody help with a sample code.

    ...then index 0 becomes index 1 and my program doesn't work properlyThe program works properly, just not as you expect it to.
    As you've noticed the table gives you the flexibility to move columns around. So if you move column 0 to column 1, why would you expect to still use 0 as the index? The table manages the reordering of columns for you to make sure the data being displayed in each table column comes from the correct column in the data model.
    You can manage this yourself using one of the following methods (I forget which one):
    table.convertColumnIndexToModel(int viewColumnIndex)
    table.convertColumnIndexToView(int modelColumnIndex)
    Or, you can get data from the data model directly:
    table.getModel().getValueAt(row, 0);

  • How to use the column names generated from Dynamic SQL

    Hi,
    I have a problem with Dynamic SQL.
    I have written an SQL which will dynamically generate the Select statement with from and where clause in it.
    But that select statement when executed will get me hundreds of rows and i want to insert each row separately into one more table.
    For that i have used a ref cursor to open and insert the table.
    In the select list the column names will also be as follows: COLUMN1, COLUMN2, COLUMN3,....COLUMNn
    Please find below the sample code:
    TYPE ref_csr IS REF CURSOR;
    insert_csr ref_csr;
    v_select VARCHAR2 (4000) := NULL;
    v_table VARCHAR2 (4000) := NULL;
    v_where VARCHAR2 (4000) := NULL;
    v_ins_tab VARCHAR2 (4000) := NULL;
    v_insert VARCHAR2 (4000) := NULL;
    v_ins_query VARCHAR2 (4000) := NULL;
    OPEN insert_csr FOR CASE
    WHEN v_where IS NOT NULL
    THEN 'SELECT '
    || v_select
    || ' FROM '
    || v_table
    || v_where
    || ';'
    ELSE 'SELECT ' || v_select || ' FROM ' || v_table || ';'
    END;
    LOOP
    v_ins_query :=
    'INSERT INTO '
    || v_ins_tab
    || '('
    || v_insert
    || ') VALUES ('
    || How to fetch the column names here
    || ');';
    EXECUTE IMMEDIATE v_ins_query;
    END LOOP;
    Please help me out with the above problem.
    Edited by: kumar0828 on Feb 7, 2013 10:40 PM
    Edited by: kumar0828 on Feb 7, 2013 10:42 PM

    >
    I Built the statement as required but i need the column list because the first column value of each row should be inserted into one more table.
    So i was asking how to fetch the column list in a ref cursor so that value can be inserted in one more table.
    >
    Then add a RETURNING INTO clause to the query to have Oracle return the first column values into a collection.
    See the PL/SQL Language doc
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/returninginto_clause.htm#sthref2307

  • How to use single column in a group by clause

    hi frs
    i hve used sum function in a sql how to use a single column in a query.
    for ex
    select sum(sal),ename,job,deptno,empno from emp
    group by deptnowhether its possible to use single column in a group by class.
    i want like this because in my custom report i need it. Report query has more than 30 column so its not possible to use 30 columns in a group by.
    pls help.
    Thanks
    Rajesh

    Maybe something like this -
    Select ename, job, deptno, empno, sal, col1, col2, col3, col4 ......, coln
    From
    Select SUM(sal) sal, deptno deptno_i
    From Emp
    Group By deptno
    ,Emp
    Where deptno = deptno_i
    Shailender Mehta

  • How to use dates/times in the definition of local fields?

    Hello!
    I have few tough questions for which I haven't found an answer. I hope someone is capable to help me.
    1. Is there a transaction to search tables if we know the field?
    2. I'd like to define a local field and need to use dates in the calculation function. So basically I need to calculate the lean-time from the date of the purchase order (field BSTDK) to the date of the final delivery (field PLIFTS) and the result should be displayed in weeks. How can I do this? Or can I?
    3. Can I use the local fields further in my calculations?
    Thank you in advance!
    Maria Kangasniemi

    Hi,
    1. Is there a transaction to search tables if we know the field?
    Tcode:    SE84
    2. I'd like to define a local field and need to use dates in the calculation function. So basically I need to calculate the lean-time from the date of the purchase order (field BSTDK) to the date of the final delivery (field PLIFTS) and the result should be displayed in weeks. How can I do this? Or can I?
    Doing some calculation you can define it.
    3. Can I use the local fields further in my calculations?
    What is local Fields?

Maybe you are looking for

  • Photoshop is really broken, help please

    hi, i have had a problem for a while now and i am not really sure why. My problem is using the brush tool in Photoshop, while i am using it, it is fine, there are no problems but when i unclick to stop drawing on my trackpad and try to to scroll usin

  • Where can i register my macbook pro ?

    where can i register my macbook pro ?

  • How to find whether MI is installed in my landscape?

    Hi I would like to know, how/where can I check whether my landscape has mobile infrastructure components got installed or not? I've seen in sld - products where mdk all versions are there. Is it require to take any post installation steps for utilizi

  • Icons not showing up. . .

    Sometimes when I open a folder in icon view I will not see all the icon images altho I can see them in preview and in Bridge. It's almost like Finder generated some of the images but didn't finish the job as this usually happens when I have to scroll

  • Grainy photos in iOS8

    Since downloading iOS8 (big mistake) onto my iPad the photos taken with the camera are terrible quality, very grainy.  With iOS7 they were lovely and clear.  Having most of the problems everyone else is having also.