SQL query with terms and calculations?

Hello
How do I create a query with terms and calculations?
For example, I have this table


Start | End |     At work |     Mandatory
------------------------------------------------------------------------------------
1ST JANUARY 13 | JANUARY 11, 13.     Office |          1
JANUARY 14, 13. 25 JANUARY 13 |     Ministry of the Interior.     0
04-MRZ-13 | 15-MRZ-13 |     Office |          0
FEBRUARY 11, 13. FEBRUARY 22, 13.     Office |          1


Now, if the workplace of the column = office and required column = 0
the new 'price' column should calculate: (end-start) * $25.00
and if workplace = Office and required column = 1
the 'price' column must calculate: (end-start) * $20.60
any other $0.00

I tried with the case statement, but I didn't know how
to calculate my values and display in the virtual column 'price '.

Something like
case
When Working_Place = 'Office' and mandatory = 1
then...
else ' 0.00'. "
end PRICE
?????


Or is that not possible?

Published by: DB2000 on 12.03.2013 05:09

Use CASE:

select  start_dt,
        end_dt,
        working_place,
        mandatory,
        case
          when working_place = 'Office' and mandatory = 0 then (end_dt - start_dt) * 25
          when working_place = 'Office' and mandatory = 1 then (end_dt - start_dt) * 20.60
          else 0
        end price
  from  tbl
/

START_DT  END_DT    WORKING_PLA  MANDATORY      PRICE
--------- --------- ----------- ---------- ----------
01-JAN-13 11-JAN-13 Office               1        206
14-JAN-13 25-JAN-13 Home Office          0          0
04-MAR-13 15-MAR-13 Office               0        275
11-FEB-13 22-FEB-13 Office               1      226.6

SQL> 

SY.

Tags: Database

Similar Questions

  • More than 1 SQL query with checkbox and error invalid number report

    Hi all

    I have two SQL query reports that each has an apex_item.checkbox and two processes for each report.  A report/process works very well.  It gives me an error of invalid number.

    In addition, another query SQL (editable report) gives me the following error when using the Multi line process, delete.

    ORA-06502: PL/SQL: digital or value error: character number conversion
    error ORA-06502: PL/SQL: digital or value error: character number conversion
    error
    Ok

    When I got a report from SQL query (with box and a process) and the query SQL (editable report) everything worked.  It stopped working when I added another SQL query report (with box and a process).

    A SQL query has the following in my query: apex_item.checkbox(3,email_id,'UNCHECKED') ""

    The other SQL query has the following: apex_item.checkbox(2,b.file_id,'UNCHECKED') ""

    Any help will be greatly appreciated,

    Sylvia

    Hi Reema,

    I've recreated the region and now it works!

    Thank you for this, looking at

    Sylvia

  • Write a SQL query with lines in columns

    All the

    I need help in writing a SQL query with lines in columns, let give u an example...

    drop table activity;

    CREATE TABLE 'ACTIVITY '.

    (

    "PROJECT_WID" NUMBER (22.0) NOT NULL,

    VARCHAR2 (150 CHAR) "PROJECT_NO."

    VARCHAR2 (800 CHAR) 'NAME '.

    );

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1683691, '10007', 12-121');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1684994, '10008', 12-122');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1686296, '10009', 12-123');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (2225222, '9040', 12-124');

    drop table lonet;

    CREATE TABLE 'LONET.

    (

    VARCHAR2 (150 CHAR) "NAME."

    NUMBER OF THE "ROOT."

    VARCHAR2 (150 CHAR) "ENTRYVALUE".

    );

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1683691, "LDE");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1683691, 'LME');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1683691, 'ICE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1683691, 'IKE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1686291, "QTY");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1686291, 'MAX');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1684994, "MTE");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1684994, 'MAC');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMT', 1684994, 'NICE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMR', 1684994, 'RAY');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1686296, "CAQ");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("PAP", 1686296, "QAQ");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("VANESSA", 1686296, "THEW");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("ANDR", 1686296, "REYL");

    commit;

    Link: activity.project_wid = lonet.root

    look like output

    Project_wid Project_no NAME GAC NAM BAG RAC
    16836911000712-121LDELMELCELKE
    16849941000812-122MTEnullnullMAC
    16862961000912-123nullnullCAQQAQ
    2225222904012-124nullnullnullnull

    two problems, in that I am running

    1. I dono how simply we can convert rows to columns

    2. for root = 1683691, there are double NAM and RAC in lonet table... ideally these data should not be there, but since its here, we can take a MAX so that it returns a value

    3. There are undesirables who should be ignored

    Once again my thought process is that we join the activity and 4 alias table lonet.

    ask for your help in this

    Thank you

    Hello

    This is called pivoting.

    Here's a way to do it:

    WITH relevant_data AS

    (

    SELECT a.project_wid, a.project_no, b.SID

    , l.name AS lonet_name, l.entryvalue

    Activity one

    LEFT OUTER JOIN lonet l.root = a.project_wid l

    )

    SELECT *.

    OF relevant_data

    PIVOT (MAX (entryvalue)

    FOR lonet_name IN ("GAC" IN the gac

    "NAM" AS nam

    'BAG' IN the bag

    "RAC" AS cars

    )

    )

    ORDER BY project_wid

    ;

    Output:

    PROJECT_WID PROJECT_NO GAC NAM BAG RAC NAME

    ----------- ---------- ---------- ---------- ---------- ---------- ----------

    1683691 12 - 10007 121 LDE LME LCE LKE

    1684994 MAC MTE 10008 12-122

    1686296 12 - 10009 123 QAC QAQ

    2225222 9040 12 - 124

    To learn more about swivel, see the FAQ in the Forum: Re: 4. How can I convert rows to columns?

    Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

  • Report of update SQL query with line selector. Update process.

    I have a report of update SQL query with the selectors in line.
    How to identify line selector in a process update on the page.

    I want to update some columns with a value of an area of selection on the page.

    With the help of the base:

    UPDATE table_name
    SET Column1 = value
    WHERE some_column = some_value

    I would need to do:

    UPDATE table_name
    SET column1 =: P1_select
    WHERE [line selector] =?

    Now sure how to identify [line selector] and/or validate it is checked.
    Thank you
    Bob

    Identify the name of the checkbox of the source of the page element, it should be of the fxx format (f01, f02... f50).
    Suppose that we f01.

    for i in 1 .. apex_application.g_f01.count
    loop
      UPDATE CONTRACTS
      SET SIP_LOAD_FLAG = :P16_STATUS
      where  =  apex_application.g_f01(i); --i'th checked record' primary key
    end loop;
    
  • Rewrite the query with joins, and group by

    Hello

    It's an interview question.

    Table names: bookshelf_checkout
    virtual library

    And the join condition between these two tables is title

    We need to rewrite under request without using the join condition and group by clause?

    SELECT b.title,max(bc.returned_date - bc.checkout_date) "Most Days Out"
               FROM bookshelf_checkout bc,bookshelf b
               WHERE bc.title(+)=b.title
               GROUP BY b.title;
    When I was in College, I read most of SELECT statements can be replaced by operations base SQL (DEFINE the OPERATORS). Now, I am rewriting the query with SET operators, but not able to get the exact result.

    Kindly help me on this.

    Thank you
    Suri

    Something like that?

      1  WITH books AS (
      2  SELECT 'title 1' title FROM dual UNION ALL
      3  SELECT 'title 2' FROM dual UNION ALL
      4  SELECT 'title 3' FROM dual ),
      5  bookshelf AS (
      6  SELECT 'title 1' title, DATE '2012-05-01' checkout_date, DATE '2012-05-15' returned_date FROM dual UNION ALL
      7  SELECT 'title 1' title, DATE '2012-05-16' checkout_date, DATE '2012-05-20' returned_date FROM dual UNION ALL
      8  SELECT 'title 2' title, DATE '2012-04-01' checkout_date, DATE '2012-05-15' returned_date FROM dual )
      9  SELECT bs.title, MAX(bs.returned_date - bs.checkout_date) OVER (PARTITION BY title) FROM bookshelf bs
     10  UNION
     11  (SELECT b.title, NULL FROM books b
     12  MINUS
     13* SELECT bs.title, NULL FROM bookshelf bs)
    SQL> /
    
    TITLE   MAX(BS.RETURNED_DATE-BS.CHECKOUT_DATE)OVER(PARTITIONBYTITLE)
    ------- ------------------------------------------------------------
    title 1                                                           14
    title 2                                                           44
    title 3
    

    Lukasz

  • SQL query with the troubleshooting Subselects

    I have a query with the 3 Subselects. Each of the Subselects works very well on its own. I run the query in Oracle SQL Developer and get ORA 933 "sql command not completed successfully" at 47 48 line pass. I am unable to say what is causing the error. The pointers you know sincerely!

    Here is the code:
    SELECT 
      adjud.country,
      adjud.site,
      adjud.prodtype,
      sum(adjud.acount) + sum(denied.dcount) as TotalClosed,
      case when adjud.adtype = 'Paid' then adjud.acount End as NumPaid,
      case when adjud.adtype = 'Paid' then adjud.totalpaid End as AmtPaid,
      count(adjud.contest) + count(denied.contest) + count(pend.contest) as CntContestable,
      sum(pend.pcount) as PendingCount,
      Case when pend.overunder = 'Over' Then count(pend.pcount) End as Over90Count,
      sum(pend.facevalue) as PendingAmount
    From 
    ( select 
        count(clm.clm_nbr) as acount, 
        sum(clm.rsrv_amt) as facevalue,
        sum(clm.tot_pd_amt) as totalpaid,
        clm.prdt_type_nm as prodtype,
        clm.cntsbl_indc as contest,
        case when clm.exam_co_cd in ('107','134')
          then 'Hong Kong'
          else 
            case when clm.exam_co_cd = '234'
              then 'Singapore'
              else 'US'
            End
        End as country,
        clm.exam_admin_site_cd as site,
        Case when clm.rmk_cd in ('R00', 'R01', 'R02') then 'Denied' Else 'Paid' End as adtype
      from afp_cds.claim_vw clm
      where 
        clm.adjud_dt is not null and 
        clm.adjud_dt > :startDate and
        clm.adjud_dt < :EndDate
      group by 
        clm.prdt_type_nm,
        clm.cntsbl_indc,
        case when clm.exam_co_cd in ('107','134') 
          then 'Hong Kong'
          else 
            case when clm.exam_co_cd = '234'
              then 'Singapore'
              else 'US'
            End
        End,
        clm.exam_admin_site_cd,
        Case when clm.rmk_cd in ('R00', 'R01', 'R02') then 'Denied' Else 'Paid' End
    ) as adjud, 
    ( select 
        count(clm.clm_nbr) as dcount,
        sum(clm.rsrv_amt) as facevalue,
        clm.prdt_type_nm as prodtype,
        case when clm.exam_co_cd in ('107','134') 
          then 'Hong Kong'
          else 
            case when clm.exam_co_cd = '234'
              then 'Singapore'
              else 'US'
            End
        End as country,
        clm.exam_admin_site_cd as site,
        clm.cntsbl_indc as contest
      from afp_cds.claim_vw clm
      where 
        clm.deny_dt is not null and
        clm.deny_dt > :startDate and
        clm.deny_dt < :EndDate
      group by
        clm.prdt_type_nm,
        case when clm.exam_co_cd in ('107','134') 
          then 'Hong Kong'
          else 
            case when clm.exam_co_cd = '234'
              then 'Singapore'
              else 'US'
            End
        End,
        clm.exam_admin_site_cd,
        clm.cntsbl_indc
    ) as denied,
    ( select 
        count(clm.clm_nbr) as pcount, 
        sum(clm.rsrv_amt) as facevalue,
        clm.prdt_type_nm as prodtype,
        case when clm.exam_co_cd in ('107','134') 
          then 'Hong Kong'
          else 
            case when clm.exam_co_cd = '234'
              then 'Singapore'
              else 'US'
            End
        End as country,
        clm.exam_admin_site_cd as site,
        clm.cntsbl_indc as contest,  
        case when sysdate - clm.regtrtn_dt > 90 then 'Over' else 'Under' End as overunder
      from afp_cds.claim_vw clm
      where
        clm.adjud_dt is null and
        clm.deny_dt is null
      group by
        clm.prdt_type_nm,
        case when clm.exam_co_cd in ('107','134') 
          then 'Hong Kong'
          else 
            case when clm.exam_co_cd = '234'
              then 'Singapore'
              else 'US'
            End
        End,
        clm.exam_admin_site_cd,
        clm.cntsbl_indc,  
        case when sysdate - regtrtn_dt > 90 then 'Over' else 'Under' End
    ) as pend
    
    where
      adjud.prodtype = denied.prodtype and
      adjud.country = denied.country and
      adjud.site = denied.site and
      adjud.contest = denied.contest and
      adjud.prodtype = pend.prodtype and
      adjud.country = pend.country and
      adjud.site = pend.site and
      adjud.contest = pend.contest 
    group by
      adjud.country,
      adjud.site,
      adjud.prodtype,
      case when adjud.adtype = 'Paid' then adjud.acount End,
      case when adjud.adtype = 'Paid' then adjud.totalpaid End,
      Case when pend.overunder = 'Over' Then count(pend.pcount) End

    Do not use "Sub" with the table alias.

    Change this stmt type:

    ) as adjud,
    

    TO

    ) adjud,
    
  • SQL query with dynamic exercise

    Hello

    I wrote this query with static exercise and exercise, I need info on making the dynamic variables

    Exercise: starts from July1st. This year up to June 30 is "2011" and July ' 1's '2012'
    Exercise: July1st his '1' and June ' 1 his '12'

    Query:

    Select distinct o.c_num, o.ac_num, s.sub_ac_num, o.fiscal_year, o.ac_exp_date, s.sub_ac_ind
    of org_account o
    outer join left sub_account s
    on o.c_num = s.c_num and o.ac_num = s.ac_num
    where (o.ac_exp_date > = CURRENT_DATE or o.ac_exp_date is null)
    and o.fiscal_year = * '2011' * -> need to be dynamic
    and o.fiscal_period = * '12' * -> need to be dynamic

    Thank you
    Mano

    Published by: user9332645 on June 2, 2011 18:55

    Hi, Mano,

    Welcome to the forum!

    Whenever you have a question, please post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data.
    Always tell what version of Oracle you are using.

    Since this is your first thread, I will post some examples of data for you:

    CREATE TABLE     table_x
    (     dt     DATE
    );
    
    INSERT INTO table_x (dt) VALUES (DATE '2010-12-31');
    INSERT INTO table_x (dt) VALUES (DATE '2011-01-01');
    INSERT INTO table_x (dt) VALUES (DATE '2011-06-02');
    INSERT INTO table_x (dt) VALUES (DATE '2011-06-30');
    INSERT INTO table_x (dt) VALUES (DATE '2011-07-01');
    

    What is the output you can from these data?

    DT          FISCAL_YEAR     FISCAL_PERIOD
    ----------- --------------- ---------------
    31-Dec-2010 2011            06
    01-Jan-2011 2011            07
    02-Jun-2011 2011            12
    30-Jun-2011 2011            12
    01-Jul-2011 2012            01
    

    If so, here's a way to get it:

    SELECT       dt
    ,       TO_CHAR ( ADD_MONTHS (dt, 6)
                , 'YYYY'
                )     AS fiscal_year
    ,       TO_CHAR ( ADD_MONTHS (dt, 6)
                , 'MM'
                )     AS fiscal_period
    FROM       table_x
    ORDER BY  dt
    ;
    

    Since your exercise begins 6 months prior to the calendar year, you must add 6 months to the actual date for the fiscal year and month.

    The above query produces strings for fiscal_year and fiscal_period. If you prefer to have the numbers, then use EXTRACT instead of TO_CHAR:

    SELECT       dt
    ,       EXTRACT (      YEAR
                FROM     ADD_MONTHS (dt, 6)
                )     AS fiscal_year
    ,       EXTRACT (      MONTH
                FROM     ADD_MONTHS (dt, 6)
                )     AS fiscal_period
    FROM       table_x
    ORDER BY  dt
    ;
    

    The first query will work in Oracle 6 (and more).
    I don't know when EXTRACT was introduced. Certainly, it works in Oracle 10 and may be available in older versions too.

  • Report with the query with union and parameters

    Hello

    We have an obligation to create a report with the request, which is the union and parameters.

    I intend to create a database for the report based on a query. But the problem here is that the way to pass parameters in the query.

    Request is something like that

    Select x.a, x.b, x.c
    x
    where x.year =: para1
    and x.status = 'A '.
    Union of all the
    Select x.a, x.b, x.c
    x
    where x.year =: para1 - 1
    and (x.status = 'c' and x.date =: para2 or x.status = 'I' and x.date < =: para2)

    Here x.year in the first select statement must be equal to: para1 and second select statement, it should be: para - 1.

    How this requirement can be achieved?

    Client don't want to separate worksheet, a parameter and another for the actual data that I tried with sys_context and it worked. But the client wants the result in a single sheet only... So I need to change their approach.

    Help, please.

    Thank you

    Hello
    Another option is to convert the request so that you will have the items from the selection
    for example on the query you provided that you can use:

    Select 'Curr' rec_type, x.a, x.b, x.c, x.year, x.date, x.status
    x
    where x.status = "A".
    Union of all the
    Select 'Prev' rec_type, x.a, x.b, x.c, x.year, x.date, x.status
    x
    where x.status in ('c', 'I')

    then, in the workbook, you will be able to create conditions such as:
    rec_type = 'Curr' and year =: para1

    rec_type = 'Prev' and year =: para1-1
    rec_type = 'Prev' and (status = 'c' and date =: para2 or status = 'I' and date)<=>

    Tamir

  • appropriate index for a query with 3 ands

    Hello

    I have the following table:

    PAGES
    ----------
    BOOK_ID DIMENSION BEGIN_POS END_POS PAGE_TEXT

    where book_id is 64-bit, size is 32 - bit, begin_pos is 32 - bit, end_pos is 32 - bits and page_text is a blob (UTF-8)

    My query is:

    Select * from PAGES
    where BOOK_ID = 1234 and DIMENSION = - 2 and BEGIN_POS < = 10000 and 10000 < END_POS

    Who will not fail to return 1 result.

    My question is what kind of clues or index (multi-column?) do need me to this query with WHERE clause uses 4 columns?

    Thank you
    Andy

    user9990110 wrote:
    My only guess is to create an index (book_id, dimension, begin_pos) and another (book_id, dimension, end_pos), but this seems a little strange.

    In your case, I would prefer an ITO - your BLOB is stored in the segment of overflow (outside of and apart from the index structure in itself ). With an IOT, each query will effectively use the index, and I wish to create two indexes on a table of 5 columns (relatively large overhead). Although compare of course.

  • Need help with sql query involving distinct and County

    I have 2 tables and I want to get the number of specific names. Find the details below. It's hard to explain but I will try to provide as much detail as I can.

    Table A:
    ID of the SR
    1001 1
    1002 2
    2 1003
    1004 3


    Table B:
    Name of the key SrNew
    1 David 1001
    2 James 1002
    3 James 1002
    4 James 1003
    5 James 1004
    6 Mike 1004

    Result: I'm looking:
    Count names such as if the name appears for the same ID of Table A two times, and then only count 1.

    Name of County
    David 1
    James 2 (1002 and 1003 for the same ID (ID #2) so count as 1 for this and then 1 more for 1004 and ID 3)
    1 Mike


    I have following question:
    SELECT distinct (b.Name), a.ID
    FROM TableA, TableB b
    Where a.Sr = b.SrNew Group By b.Name, a.ID

    and as a result I get:
    ID name
    David 1
    James 2
    3 James
    3 Mike


    Now, I want to just the number of each name with the result, but don't know how I can do this with a sql?

    Thanks in advance.

    Who help me?

    SELECT b.Name, count(distinct a.ID)
    FROM TableA a, TableB b
    Where a.Sr = b.SrNew
    Group By b.Name
    

    Nicolas.

  • SDO_RELATE within PL/SQL query with rownum clause runs slowly on 12 c - works great on 10 g

    Hello

    I use the database 12.1.0.2 with a node 2 RAC on Windows.

    I am struck by a really weird performance problem with a particular query.  Bear with me while I try to explain...

    I have a chart with lines 30 sdo_geometry million, in 7 partitions with a local partitioned spatial index divided.  Called BIG_PARTITIONED_TABLE for this example.

    I query the table to search for one line with a geometry that is equal to the geometry of my request.  In this case I use sdo_relate with "mask = equal".  Instantly returns:

    SQL> select id, geometry
      2  from       BIG_PARTITIONED_TABLE o
      3  where      sdo_relate(o.geometry, sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      4     SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272)), 'mask=equal') = 'TRUE'
      5  and rownum = 1;
    
            ID
    ----------
    GEOMETRY(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    -------------------------------------------------------------------------------
    2.5405E+12
    SDO_GEOMETRY(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272))
    
    Elapsed: 00:00:00.10
    
    

    But if I put the same query in PL/SQL, so it takes 21 seconds:

    SQL> declare
      2     l_id number;
      3     l_geom sdo_geometry;
      4     l_window_geom sdo_geometry;
      5  begin
      6     l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      7             SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272));
      8
      9     select id, geometry
    10     into l_id, l_geom
    11     from    BIG_PARTITIONED_TABLE o
    12     where   sdo_relate(o.geometry, l_window_geom, 'mask=equal') = 'TRUE'
    13     and rownum = 1;
    14
    15  end;
    16  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:21.13
    
    

    If I remove the "rownum = 1", then it returns instantly:

    SQL> declare
      2     l_id number;
      3     l_geom sdo_geometry;
      4     l_window_geom sdo_geometry;
      5  begin
      6     l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      7             SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272));
      8
      9     select id, geometry
    10     into l_id, l_geom
    11     from    BIG_PARTITIONED_TABLE o
    12     where   sdo_relate(o.geometry, l_window_geom, 'mask=equal') = 'TRUE';
    13
    14  end;
    15  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:00.03
    
    

    If using sdo_equal instead of sdo_relate and keep the "rownum = 1", then it returns instantly.

    SQL> declare
      2     l_id number;
      3     l_geom sdo_geometry;
      4     l_window_geom sdo_geometry;
      5  begin
      6     l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      7             SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272));
      8
      9     select id, geometry
    10     into l_id, l_geom
    11     from    BIG_PARTITIONED_TABLE o
    12     where   sdo_equal(o.geometry, l_window_geom) = 'TRUE'
    13     and rownum = 1;
    14
    15  end;
    16  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:00.13
    
    

    Here is a comparison of the plans to explain.  First, here's the good thing, that is using the spatial index (BIG_PARTITIONED_TABLE_SPIND):

    select id, GEOMETRY
    FROM
    BIG_PARTITIONED_TABLE O WHERE SDO_EQUAL(O.GEOMETRY, :B1 ) = 'TRUE'
    AND ROWNUM = 1
    
    call     count       cpu    elapsed       disk      query    current        rows
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.01       0.02          0         39          0           0
    Fetch        1      0.00       0.01          0         31          0           1
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    total        3      0.01       0.04          0         70          0           1
    
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 263     (recursive depth: 1)
    Number of plan statistics captured: 1
    
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
    ---------- ---------- ----------  ---------------------------------------------------
             1          1          1  COUNT STOPKEY (cr=99 pr=0 pw=0 time=43307 us)
             1          1          1   PARTITION RANGE ALL PARTITION: 1 7 (cr=99 pr=0 pw=0 time=43297 us cost=0 size=66 card=1)
             1          1          1    TABLE ACCESS BY LOCAL INDEX ROWID BIG_PARTITIONED_TABLE PARTITION: 1 7 (cr=99 pr=0 pw=0 time=43280 us cost=0 size=66 card=1)
             1          1          1     DOMAIN INDEX  BIG_PARTITIONED_TABLE_SPIND (cr=98 pr=0 pw=0 time=43250 us)
    
    

    Then the slow that does not use the spatial index.

    select id, GEOMETRY
    FROM
    BIG_PARTITIONED_TABLE O WHERE SDO_RELATE(O.GEOMETRY, :B1 , 'mask=equal') = 'TRUE'
      AND ROWNUM = 1
    
    call     count       cpu    elapsed       disk      query    current        rows
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    Parse        1      0.01       0.00          0          0          0           0
    Execute      1      0.03       0.03          0       1123          0           0
    Fetch        1     24.25      24.25          0     499429          0           1
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    total        3     24.30      24.29          0     500552          0           1
    
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 263     (recursive depth: 1)
    Number of plan statistics captured: 1
    
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
    ---------- ---------- ----------  ---------------------------------------------------
             1          1          1  COUNT STOPKEY (cr=499532 pr=0 pw=0 time=24289612 us)
             1          1          1   HASH JOIN RIGHT SEMI (cr=499532 pr=0 pw=0 time=24289586 us cost=32 size=144 card=1)
             1          1          1    VIEW  VW_NSO_1 (cr=103 pr=0 pw=0 time=31110 us cost=29 size=98016 card=8168)
             1          1          1     COLLECTION ITERATOR PICKLER FETCH SDO_PQRY (cr=103 pr=0 pw=0 time=31104 us cost=29 size=16336 card=8168)
      16914892   16914892   16914892    PARTITION RANGE ALL PARTITION: 1 7 (cr=499429 pr=0 pw=0 time=28678375 us cost=3 size=6600 card=100)
      16914892   16914892   16914892     TABLE ACCESS FULL BIG_PARTITIONED_TABLE PARTITION: 1 7 (cr=499429 pr=0 pw=0 time=23406547 us cost=3 size=6600 card=100)
    
    

    I tried adding an indication / * + index (o BIG_PARTITIONED_TABLE_SPIND) * / but that did not help.

    I am struck this issue during testing of upgrade 10.2.0.5 to 12.1.0.2.  The query works perfectly on 10g - we note only that this question on 12 c.

    I can't use sdo_equal as the real mask that we want is equal + dommagescausdspar + covers.  I'm just using equal here to simplify the test.

    I use "rownum = 1" because I want to just the first result.  In practice I can rewrite probably is a FOR LOOP, I get out after the first result, but that seems all just awful.

    Any ideas?  If anyone has seen anything like this before?  Its an optimizer delivers really so I'm going to cross post the SQL Forum after a certain time, but thought I would post it here first.

    Thank you

    John

    Hi John,.

    Can you please try the following before your slow queries event?

    "ALTER session set events ' trace 54669 name context forever."

    Thank you

    Ying

  • Help setting up a SQL query with poor performance

    Hi all

    Database version: 10.2.0.5

    I'm working on a new report to view the top users by the number of calls. The table is truncated and filled again every month with records for the previous month; It contains approximately 400 000 records.

    I created a view with the columns needed for the report; also, the two functions of view calls to determine if a phone number is assigned to multiple staffs or several departments.

    It's full again table every month:

     CREATE TABLE "VOIP"."MONTHLY_BILLING_DETAILS" 
       (    "ID" NUMBER NOT NULL ENABLE, 
        "CDRRECORDTYPE" NUMBER, 
        "G_CALLMANAGERID" NUMBER, 
        "G_CALLID" NUMBER, 
        "O_LEGCALLIDENTIFIER" NUMBER, 
        "DATETIMEORIGINATION" NUMBER, 
        "O_NODEID" NUMBER, 
        "O_SPAN" NUMBER, 
        "O_IPADDR" NUMBER, 
        "CALLINGPARTYNUMBER" VARCHAR2(50 BYTE) NOT NULL ENABLE, 
        "CALLINGPARTY_USERID" VARCHAR2(128 BYTE), 
        "O_CAUSE_LOCATION" NUMBER, 
        "O_CAUSE_VALUE" NUMBER, 
        "O_PRECEDENCELEVEL" NUMBER, 
        "O_MEDIATRANSPORTADDR_IP" NUMBER, 
        "O_MEDIATRANSPORTADDR_PORT" NUMBER, 
        "O_MCAP_PAYLOADCAPABILITY" NUMBER, 
        "O_MCAP_MAXFRAMESPERPACKET" NUMBER, 
        "O_MCAP_G723BITRATE" NUMBER, 
        "O_VCAP_CODEC" NUMBER, 
        "O_VCAP_BANDWIDTH" NUMBER, 
        "O_VCAP_RESOLUTION" NUMBER, 
        "O_VIDEOTRANSPORTADDR_IP" NUMBER, 
        "O_VIDEOTRANSPORTADDR_PORT" NUMBER, 
        "O_RSVPAUDIOSTAT" VARCHAR2(64 BYTE), 
        "O_RSVPVIDEOSTAT" VARCHAR2(64 BYTE), 
        "DESTLEGIDENTIFIER" NUMBER, 
        "DESTNODEID" NUMBER, 
        "DESTSPAN" NUMBER, 
        "DESTIPADDR" NUMBER, 
        "ORIGINALCALLEDPARTYNUMBER" VARCHAR2(50 BYTE), 
        "FINALC_PARTYNUMBER" VARCHAR2(50 BYTE), 
        "FINALC_PARTY_USERID" VARCHAR2(128 BYTE), 
        "DESTCAUSE_LOCATION" NUMBER, 
        "DESTCAUSE_VALUE" NUMBER, 
        "DESTPRECEDENCELEVEL" NUMBER, 
        "DESTMEDIATRANSPORTADDR_IP" NUMBER, 
        "DESTMEDIATRANSPORTADDR_PORT" NUMBER, 
        "DESTMCAP_PAYLOADCAPABILITY" NUMBER, 
        "DESTMCAP_MAXFRAMESPERPACKET" NUMBER, 
        "DESTMCAP_G723BITRATE" NUMBER, 
        "DV_CAP_CODEC" NUMBER, 
        "DV_CAP_BANDWIDTH" NUMBER, 
        "DV_CAP_RESOLUTION" NUMBER, 
        "DV_TRANSPORTADDR_IP" NUMBER, 
        "DV_TRANSPORTADDR_PORT" NUMBER, 
        "DESTRSVPAUDIOSTAT" VARCHAR2(64 BYTE), 
        "DESTRSVPVIDEOSTAT" VARCHAR2(64 BYTE), 
        "DATETIMECONNECT" NUMBER, 
        "DATETIMEDISCONNECT" NUMBER, 
        "LASTREDIRECTDN" VARCHAR2(50 BYTE), 
        "PKID" VARCHAR2(4000 BYTE), 
        "O_INALCALLEDPARTYNUM_PARTITION" VARCHAR2(50 BYTE), 
        "CALLINGPARTYNUM_PARTITION" VARCHAR2(50 BYTE), 
        "FINALC_PARTYNUM_PARTITION" VARCHAR2(50 BYTE), 
        "LASTREDIRECTDNPARTITION" VARCHAR2(50 BYTE), 
        "DURATION" NUMBER, 
        "O_DEVICENAME" VARCHAR2(129 BYTE), 
        "DESTDEVICENAME" VARCHAR2(129 BYTE), 
        "O_CALLTERMINATION_BEHALF" NUMBER, 
        "DESTCALLTERMINATION_BEHALF" NUMBER, 
        "O_CALLEDPARTYREDIRECT_BEHALF" NUMBER, 
        "LASTREDIRECTREDIRECT_BEHALF" NUMBER, 
        "O_CALLEDPARTYREDIRECTREASON" NUMBER, 
        "LASTREDIRECTREDIRECTREASON" NUMBER, 
        "DESTCONVERSATIONID" NUMBER, 
        "G_CALLID_CLUSTERID" VARCHAR2(50 BYTE), 
        "JOIN_BEHALF" NUMBER, 
        "COMMENTS" VARCHAR2(2048 BYTE), 
        "AUTHCODEDESCRIPTION" VARCHAR2(50 BYTE), 
        "AUTHORIZATIONLEVEL" NUMBER, 
        "CLIENTMATTERCODE" VARCHAR2(32 BYTE), 
        "O_DTMFMETHOD" NUMBER, 
        "DESTDTMFMETHOD" NUMBER, 
        "CALLSECUREDSTATUS" NUMBER, 
        "O_CONVERSATIONID" NUMBER, 
        "O_MCAP_BANDWIDTH" NUMBER, 
        "DESTMCAP_BANDWIDTH" NUMBER, 
        "AUTHORIZATIONCODEVALUE" VARCHAR2(32 BYTE), 
        "OUTPULSEDCALLINGPARTYNUMBER" VARCHAR2(50 BYTE), 
        "OUTPULSEDCALLEDPARTYNUMBER" VARCHAR2(50 BYTE), 
        "O_IPV4V6ADDR" VARCHAR2(64 BYTE), 
        "DESTIPV4V6ADDR" VARCHAR2(64 BYTE), 
        "O_VCAP_CODEC_CHAN2" NUMBER, 
        "O_VCAP_BANDWIDTH_CHAN2" NUMBER, 
        "O_VCAP_RESOLUTION_CHAN2" NUMBER, 
        "O_V_TRANSPORTADDR_IP_CHAN2" NUMBER, 
        "O_V_TRANSPORTADDR_PORT_CHAN2" NUMBER, 
        "O_V_OCHANNEL_ROLE_CHAN2" NUMBER, 
        "DV_CAP_CODEC_CHAN2" NUMBER, 
        "DV_CAP_BANDWIDTH_CHAN2" NUMBER, 
        "DV_CAP_RESOLUTION_CHAN2" NUMBER, 
        "DV_TRANSPORTADDR_IP_CHAN2" NUMBER, 
        "DV_TRANSPORTADDR_PORT_CHAN2" NUMBER, 
        "DV_CHANNEL_ROLE_CHAN2" NUMBER, 
        "DATE_CREATED" DATE, 
        "DATETIME_CONNECT" DATE, 
        "DATETIME_DISCONNECT" DATE, 
        "USERID_EMAIL_ADDRESS" VARCHAR2(100 BYTE), 
        "FROM_FULL_TELEPHONE" VARCHAR2(20 BYTE), 
        "TO_FULL_TELEPHONE" VARCHAR2(20 BYTE), 
        "FROM_EXCHANGE" VARCHAR2(7 BYTE), 
        "TO_EXCHANGE" VARCHAR2(20 BYTE), 
        "FROM_CITY" VARCHAR2(200 BYTE), 
        "FROM_STATE" VARCHAR2(2 BYTE), 
        "TO_CITY" VARCHAR2(200 BYTE), 
        "TO_STATE" VARCHAR2(2 BYTE), 
        "CALL_TYPE" VARCHAR2(10 BYTE), 
         CONSTRAINT "MONTHLY_BILLING_PK" PRIMARY KEY ("ID")
      USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA"  ENABLE
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 75497472 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX1" ON "VOIP"."MONTHLY_BILLING_DETAILS" (TRUNC("DATETIME_CONNECT")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX10" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("CALL_TYPE") 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX2" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("FROM_EXCHANGE") 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX3" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("FROM_FULL_TELEPHONE", TRUNC("DATETIME_CONNECT")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX4" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT", NVL("FROM_FULL_TELEPHONE","CALLINGPARTYNUMBER")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 5242880 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX5" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT", NVL("TO_FULL_TELEPHONE","ORIGINALCALLEDPARTYNUMBER")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 5242880 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX6" ON "VOIP"."MONTHLY_BILLING_DETAILS" (TO_CHAR("DATETIME_CONNECT",'fmMONTH YYYY')) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX7" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("TO_EXCHANGE") 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX8" ON "VOIP"."MONTHLY_BILLING_DETAILS" (NVL("FROM_FULL_TELEPHONE","CALLINGPARTYNUMBER")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX9" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT") 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    

    These are the functions to determine if a phone number is assigned to multiple staffs or departments:

    FUNCTION GET_EMPLOYEE_NAME (P_FROM_FULL_TELEPHONE IN VARCHAR2)
    RETURN VARCHAR2
    AS
      L_NAME EMPLOYEES.NAME%TYPE;
    BEGIN
      SELECT NAME
      INTO L_NAME
      FROM EMPLOYEES
      WHERE WORK_PHONE_1_FORMAT = P_FROM_FULL_TELEPHONE;
      
      RETURN L_NAME;
    EXCEPTION
      WHEN TOO_MANY_ROWS THEN
        L_NAME := 'Multiple Employees';
        RETURN L_NAME;
      WHEN NO_DATA_FOUND THEN
        L_NAME := 'No Employee Assigned';
        RETURN L_NAME;
      WHEN OTHERS THEN
        NULL;
    END;
    

    FUNCTION GET_DEPARTMENT_NAME (P_FROM_FULL_TELEPHONE IN VARCHAR2)
    RETURN VARCHAR2
    AS
      L_DEPT_DESCR EMPLOYEES.DEPT_DESCR%TYPE;
    BEGIN
      SELECT DEPT_DESCR
      INTO L_DEPT_DESCR
      FROM EMPLOYEES
      WHERE WORK_PHONE_1_FORMAT = P_FROM_FULL_TELEPHONE;
      
      RETURN L_DEPT_DESCR;
    EXCEPTION
      WHEN TOO_MANY_ROWS THEN
        L_DEPT_DESCR := 'Multiple Departments';
        RETURN L_DEPT_DESCR;
      WHEN NO_DATA_FOUND THEN
        L_DEPT_DESCR := 'No Department Assigned';
        RETURN L_DEPT_DESCR;
      WHEN OTHERS THEN
        NULL;
    END;
    

    This is the point of view that I'll use in the report:

    CREATE OR REPLACE FORCE VIEW "VOIP"."TOP_USERS_BY_CALLS_V" ("TOP_NO", "EMPLOYEE_NAME", "EMPLOYEE_DEPARTMENT", "PHONE_NUMBER", "QUANTITY_CALLS") AS 
      SELECT
      ROWNUM,
      VOIP_PKG.GET_EMPLOYEE_NAME(FROM_FULL_TELEPHONE),
      VOIP_PKG.GET_DEPARTMENT_NAME(FROM_FULL_TELEPHONE),
      FROM_FULL_TELEPHONE,
      QUANTITY_CALLS
    FROM (
    SELECT
      MBD.FROM_FULL_TELEPHONE,
      COUNT(1) QUANTITY_CALLS
    FROM
      MONTHLY_BILLING_DETAILS MBD
    WHERE
      MBD.FROM_FULL_TELEPHONE IS NOT NULL                                     AND
      MBD.FROM_FULL_TELEPHONE <> '000-000-0000'                               AND
      LENGTH(MBD.FROM_FULL_TELEPHONE) = 12                                    AND
      LENGTH(MBD.TO_FULL_TELEPHONE) = 12                                      AND
      SUBSTR(MBD.TO_FULL_TELEPHONE,1,3) NOT IN (SELECT AREA_CODE
                                                FROM NYNJ_METRO_AREA_CODES)   AND
      SUBSTR(MBD.TO_FULL_TELEPHONE,1,3) NOT IN ('800','822','833','844',
                                                '855','866','877','888')
    GROUP BY
      MBD.FROM_FULL_TELEPHONE
    ORDER BY
      QUANTITY_CALLS DESC
    )
    WHERE ROWNUM <= 100;
    

    Explain Plan output and Extended SQL Trace:


    SQL> 
    SQL> show parameter user_dump_dest
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    user_dump_dest                       string      D:\ORACLEHOMES\ADMIN\RTS9\UDUM
                                                     P
    SQL> 
    SQL> show parameter optimizer
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      10.2.0.5
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     100
    optimizer_mode                       string      ALL_ROWS
    optimizer_secure_view_merging        boolean     TRUE
    SQL> 
    SQL> show parameter db_file_multi
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    db_file_multiblock_read_count        integer     16
    SQL> 
    SQL> show parameter db_block_size
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    db_block_size                        integer     8192
    SQL> 
    SQL> show parameter cursor_sharing
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    cursor_sharing                       string      EXACT
    SQL> 
    SQL> column sname format a20
    SQL> column pname format a20
    SQL> column pval2 format a20
    SQL> 
    SQL> select
      2  sname
      3  , pname
      4  , pval1
      5  , pval2
      6  from
      7  sys.aux_stats$;
    
    SNAME                PNAME                     PVAL1 PVAL2
    -------------------- -------------------- ---------- --------------------
    SYSSTATS_INFO        STATUS                          COMPLETED
    SYSSTATS_INFO        DSTART                          02-09-2009 15:46
    SYSSTATS_INFO        DSTOP                           02-09-2009 15:46
    SYSSTATS_INFO        FLAGS                         1
    SYSSTATS_MAIN        CPUSPEEDNW            1259.6206
    SYSSTATS_MAIN        IOSEEKTIM                    10
    SYSSTATS_MAIN        IOTFRSPEED                 4096
    SYSSTATS_MAIN        SREADTIM
    SYSSTATS_MAIN        MREADTIM
    SYSSTATS_MAIN        CPUSPEED
    SYSSTATS_MAIN        MBRC
    SYSSTATS_MAIN        MAXTHR
    SYSSTATS_MAIN        SLAVETHR
    
    13 rows selected.
    
    Elapsed: 00:00:00.03
    SQL> 
    SQL> explain plan for
      2  SELECT
      3    TOP_NO,
      4    EMPLOYEE_NAME,
      5    EMPLOYEE_DEPARTMENT,
      6    PHONE_NUMBER,
      7    QUANTITY_CALLS
      8  FROM
      9    TOP_USERS_BY_CALLS_V
     10  ORDER BY
     11    QUANTITY_CALLS DESC;
    
    Explained.
    
    Elapsed: 00:00:00.18
    SQL> 
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 826236322
    
    ----------------------------------------------------------------------------------------------------------------
    | Id  | Operation                          | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                   |                           |     1 |  4042 |  1313   (1)| 00:00:16 |
    |   1 |  SORT ORDER BY                     |                           |     1 |  4042 |  1313   (1)| 00:00:16 |
    |   2 |   VIEW                             | TOP_USERS_BY_CALLS_V      |     1 |  4042 |  1312   (1)| 00:00:16 |
    |*  3 |    COUNT STOPKEY                   |                           |       |       |            |          |
    |   4 |     VIEW                           |                           |     1 |    25 |  1312   (1)| 00:00:16 |
    |*  5 |      SORT ORDER BY STOPKEY         |                           |     1 |    26 |  1312   (1)| 00:00:16 |
    |   6 |       HASH GROUP BY                |                           |     1 |    26 |  1312   (1)| 00:00:16 |
    |*  7 |        FILTER                      |                           |       |       |            |          |
    |*  8 |         TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS   |     1 |    26 |  1310   (1)| 00:00:16 |
    |*  9 |          INDEX FULL SCAN           | MONTHLY_BILL_INDEX3       |   934 |       |   449   (1)| 00:00:06 |
    |* 10 |         INDEX FULL SCAN            | NYNJ_METRO_AREA_CODES_UK1 |     1 |     4 |     1   (0)| 00:00:01 |
    ----------------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter(ROWNUM<=100)
       5 - filter(ROWNUM<=100)
       7 - filter( NOT EXISTS (SELECT 0 FROM VOIP."NYNJ_METRO_AREA_CODES" "NYNJ_METRO_AREA_CODES" WHERE
                  LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3))))
       8 - filter(LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888')
       9 - filter(LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000'
                  AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL)
      10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3)))
    
    33 rows selected.
    
    Elapsed: 00:00:00.82
    SQL> 
    SQL> rollback;
    
    Rollback complete.
    
    Elapsed: 00:00:00.00
    SQL> 
    SQL> set autotrace traceonly arraysize 100
    SQL> 
    SQL> alter session set tracefile_identifier = 'mytrace1';
    
    Session altered.
    
    Elapsed: 00:00:00.01
    SQL> 
    SQL> alter session set events '10046 trace name context forever, level 8';
    
    Session altered.
    
    Elapsed: 00:00:00.15
    SQL> 
    SQL> SELECT
      2    TOP_NO,
      3    EMPLOYEE_NAME,
      4    EMPLOYEE_DEPARTMENT,
      5    PHONE_NUMBER,
      6    QUANTITY_CALLS
      7  FROM
      8    TOP_USERS_BY_CALLS_V
      9  ORDER BY
     10    QUANTITY_CALLS DESC;
    
    100 rows selected.
    
    Elapsed: 00:10:37.68
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 826236322
    
    ----------------------------------------------------------------------------------------------------------------
    | Id  | Operation                          | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                   |                           |     1 |  4042 |  1313   (1)| 00:00:16 |
    |   1 |  SORT ORDER BY                     |                           |     1 |  4042 |  1313   (1)| 00:00:16 |
    |   2 |   VIEW                             | TOP_USERS_BY_CALLS_V      |     1 |  4042 |  1312   (1)| 00:00:16 |
    |*  3 |    COUNT STOPKEY                   |                           |       |       |            |          |
    |   4 |     VIEW                           |                           |     1 |    25 |  1312   (1)| 00:00:16 |
    |*  5 |      SORT ORDER BY STOPKEY         |                           |     1 |    26 |  1312   (1)| 00:00:16 |
    |   6 |       HASH GROUP BY                |                           |     1 |    26 |  1312   (1)| 00:00:16 |
    |*  7 |        FILTER                      |                           |       |       |            |          |
    |*  8 |         TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS   |     1 |    26 |  1310   (1)| 00:00:16 |
    |*  9 |          INDEX FULL SCAN           | MONTHLY_BILL_INDEX3       |   934 |       |   449   (1)| 00:00:06 |
    |* 10 |         INDEX FULL SCAN            | NYNJ_METRO_AREA_CODES_UK1 |     1 |     4 |     1   (0)| 00:00:01 |
    ----------------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter(ROWNUM<=100)
       5 - filter(ROWNUM<=100)
       7 - filter( NOT EXISTS (SELECT 0 FROM VOIP."NYNJ_METRO_AREA_CODES" "NYNJ_METRO_AREA_CODES" WHERE
                  LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3))))
       8 - filter(LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888')
       9 - filter(LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000'
                  AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL)
      10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3)))
    
    
    Statistics
    ----------------------------------------------------------
            365  recursive calls
              0  db block gets
         689543  consistent gets
         212906  physical reads
              0  redo size
           5984  bytes sent via SQL*Net to client
            400  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              2  sorts (memory)
              0  sorts (disk)
            100  rows processed
    
    SQL> 
    SQL> disconnect
    

    Part of the automatic trace output:

    SELECT
      TOP_NO,
      EMPLOYEE_NAME,
      EMPLOYEE_DEPARTMENT,
      PHONE_NUMBER,
      QUANTITY_CALLS
    FROM
      TOP_USERS_BY_CALLS_V
    ORDER BY
      QUANTITY_CALLS DESC
    
    call     count       cpu    elapsed       disk      query    current        rows
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    Parse        1      0.00       0.43          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2     24.70     635.81     212587     631823          0         100
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    total        4     24.70     636.25     212587     631823          0         100
    
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 148  
    
    Rows     Row Source Operation
    -------  ---------------------------------------------------
        100  SORT ORDER BY (cr=689531 pr=212900 pw=0 time=636823070 us)
        100   VIEW  TOP_USERS_BY_CALLS_V (cr=689531 pr=212900 pw=0 time=642681672 us)
        100    COUNT STOPKEY (cr=631823 pr=212587 pw=0 time=635667026 us)
        100     VIEW  (cr=631823 pr=212587 pw=0 time=635666810 us)
        100      SORT ORDER BY STOPKEY (cr=631823 pr=212587 pw=0 time=635666493 us)
       2512       HASH GROUP BY (cr=631823 pr=212587 pw=0 time=635666125 us)
      27112        FILTER  (cr=631823 pr=212587 pw=0 time=519230237 us)
     315563         TABLE ACCESS BY INDEX ROWID MONTHLY_BILLING_DETAILS (cr=381523 pr=212587 pw=0 time=580209555 us)
     394473          INDEX FULL SCAN MONTHLY_BILL_INDEX3 (cr=2679 pr=2679 pw=0 time=26793918 us)(object id 206675)
     226627         INDEX FULL SCAN NYNJ_METRO_AREA_CODES_UK1 (cr=250300 pr=0 pw=0 time=3575488 us)(object id 206605)
    
    
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       2        0.00          0.00
      db file sequential read                    212587        0.20        611.67
      SQL*Net message from client                     2        0.00          0.00
      SQL*Net more data to client                     2        0.00          0.00
    ********************************************************************************
    

    DBMS_XPLAN. Output DISPLAY_CURSOR:

    SQL> 
    SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
    
    PLAN_TABLE_OUTPUT
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    SQL_ID  1ut636vt58jdw, child number 0
    -------------------------------------
    SELECT /*+ gather_plan_statistics */   TOP_NO,   EMPLOYEE_NAME,   EMPLOYEE_DEPARTMENT,   PHONE_NUMBER,   QUANTITY_CALLS FROM   TOP_USERS_BY_CALLS_V
    ORDER BY   QUANTITY_CALLS DESC
    
    Plan hash value: 826236322
    
    --------------------------------------------------------------------------------------------------------------------------------------------------------------
    | Id  | Operation                          | Name                      | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |  OMem |  1Mem | Used-Mem |
    --------------------------------------------------------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                   |                           |      1 |        |    100 |00:09:56.06 |     689K|    210K|       |       |          |
    |   1 |  SORT ORDER BY                     |                           |      1 |      1 |    100 |00:09:56.06 |     689K|    210K| 13312 | 13312 |12288  (0)|
    |   2 |   VIEW                             | TOP_USERS_BY_CALLS_V      |      1 |      1 |    100 |00:10:04.98 |     689K|    210K|       |       |          |
    |*  3 |    COUNT STOPKEY                   |                           |      1 |        |    100 |00:09:54.89 |     631K|    210K|       |       |          |
    |   4 |     VIEW                           |                           |      1 |      1 |    100 |00:09:54.89 |     631K|    210K|       |       |          |
    |*  5 |      SORT ORDER BY STOPKEY         |                           |      1 |      1 |    100 |00:09:54.88 |     631K|    210K|  6144 |  6144 | 6144  (0)|
    |   6 |       HASH GROUP BY                |                           |      1 |      1 |   2512 |00:09:54.88 |     631K|    210K|   821K|   821K| 1153K (0)|
    |*  7 |        FILTER                      |                           |      1 |        |  27112 |00:08:58.57 |     631K|    210K|       |       |          |
    |*  8 |         TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS   |      1 |      1 |    315K|00:08:57.07 |     381K|    210K|       |       |          |
    |*  9 |          INDEX FULL SCAN           | MONTHLY_BILL_INDEX3       |      1 |    934 |    394K|00:00:23.02 |    2679 |   2679 |       |       |          |
    |* 10 |         INDEX FULL SCAN            | NYNJ_METRO_AREA_CODES_UK1 |    250K|      1 |    226K|00:00:03.47 |     250K|      0 |       |       |          |
    --------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter(ROWNUM<=100)
       5 - filter(ROWNUM<=100)
       7 - filter( IS NULL)
       8 - filter((LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822'
                  AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855'
                  AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888'))
       9 - filter((LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000' AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL))
      10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3)))
    
    
    35 rows selected.
    
    Elapsed: 00:00:00.50
    SQL> 
    SQL> spool off
    
    

    Any help will be greatly appreciated. Please let me know if you need additional information.

    Thank you

    Erick

    ediazjorge wrote:

    Please let me know if you need additional information or do additional tests.

    Thanks again!

    Erick

    It's to you if you are satisfied or interested in improvements (if possible).

    If so the first thing I would like if you had your refreshed perspective as advised. According to expected area_code table cardinalities I doubt.

    So, if not cool off with dbms_stats.gather_table_stats on two tables, area_codes and MONTHLY_BILLING_DETAILS.

    Bottlenecks are now obviously the full table of MONTHLY_BILLING_DETAILS as well as the ANTI of LOOPS IMBRIQUEES scan.

    At the moment I don't think that an index of MONTHLY_BILLING_DETAILS will help a lot, because most of the lines will pass filter predicates, and because we need some columns in it, I have now I there will be gain a full index scan.

    I was surprissed that the optimizer pushes the substr <> predicates to both tables.

    So depending on your data, you might try

    1 make a factory of subquery select the two MONTHLY_BILLING_DETAILS columns that all directly apply predicates of membership and use it directly in the join instead of the table.

    or

    2. If all subtr to so are part of the table area_code choose in it using a subquery (or inline view) plant excluding these values.

    Both are attempts to get rid of the substr excluding as filters of join predicates.

    In fact, I was expecting a hash join anti as shown in the plan to explain instead of the nested loops anti, I expect to be more effective in this case.

    Perhaps with correct cardinalities the optimizier would understand himself.

    Just to test it, you can try the use_hash hint in the join:

    Select / * + USE_HASH (MBD, one) * /.

    ..

    OF MONTHLY_BILLING_DETAILS MBD,.

    NYNJ_METRO_AREA_CODES one

    (It's a good habit anyway usually use aliases and precede the names of columns. In the, it is easier to read queries are only trivial).

  • (Editable report) SQL query with line selector

    I used this code to get the update of the records in a query SQL (editable report).
    Updates a value in a selection box.

    because me in 1... apex_application.g_f01. Count
    loop
    UPDATE CONTRACTS
    SET LOAD_FLAG =: P8_SELECT
    WHERE ID = apex_application.g_f01 (i); -i'the checked the file 'primary key '.
    end loop;

    Here's my dilemma.
    Line selector seems to be in a fixed position.
    By linking the line for identification number selector (1, 2, 3, etc.)
    Sort by ID (1, 2, 3, etc.)
    It works perfectly, as long as the ID is sorted in order. < <
    If it is sorted by another field with say ID 29 now in the 1st row, by checking the box and update, you update ID #1 located elsewhere on the page.
    Any ideas how to make the line selector literally equal to the line, it is displayed in?
    Thank you
    Bob

    I think I have an idea of what is wrong and, eventually, how to fix it. Try this:

    make your field primary key (NO ROWID!) in a column in a table column, either through the "wizard" (i.e. through the report attributes screen), or using the APEX_ITEM api (as described by Vee). I often have my primary key as a hidden; If you really need to see it, you can use "DISPLAY_AND_SAVE".

    So if your primary key 'ID' colum is now in the 2nd table as a table (i.e. f02 - adjust accordingly!), your PL/SQL process should look like this:

    for i in 1 .. apex_application.g_f01.count
    loop
       UPDATE CONTRACTS
          SET LOAD_FLAG = :P8_SELECT
        where ID = apex_application.g_f02(apex_application.g_f01(i)); 
    
    end loop;
    

    It of a little confusing at first but it it makes sense when you train how tabular tables work with check boxes. The length of this array represents only what is verified - so if you have 3 values checked, the cardinality of the table in a particular table 3. On the other hand, your other tabular berries (containing the 'normal' values) has a cardinality of the count of all the visible lines.

    In this case, the record selector (F01) contains the ID of the relevant line in your report - so passing this value in the array index 2 (F02) should give you the correct primary key for that particular line value. If you subsequently order the report by another field, it should work again.

    I should add that Vee method will work well - the difference is that, instead of organizing the rowid, f01 contains the actual key value. Hope this helps

    Published by: Joel_C on March 21, 2011 11:50

  • pl - sql query with index by table errors

    Hello once again

    I'm stuck again with the following query

    I want to display the name of the Department, employee id name count and avg sal

    rec type is rendered
    (
    not a number (8.0).
    DNAME varchar2 (40),
    mgr_nm varchar2 (55),
    d_hc number (8.0).
    SAL number (8.2)
    );
    rec1 is the rec index table directory.
    Start
    for rec1 in)
    Select a1.dnm, a1.nm, b.did, b.hc, b.sal
    Of
    (
    Select d.department_id as did e1.first_name |' '|| E1.last_name like nm, d.department_name as dnm
    of hr.employees e1, hr.departments d
    where e1.department_id = d.department_id) a1.
    (
    Select d.department_id as did, count (e1.employee_id) as hc, avg (e1.salary) as sal
    of hr.employees e1, hr.departments d
    where e1.department_id = d.department_id
    D.department_id group) b
    where a1.did = b.did)
    loop
    dbms_output.put_line (REC1);
    end loop;
    end;
    /

    my error is

    ORA-00900: invalid SQL statement

    Help, please

    Thank you!!!

    Try this:

    begin
      for rec1 in ( select a1.dnm
                    ,      a1.nm
                    ,      b.did
                    ,      b.hc
                    ,      b.sal
                    from ( select d.department_id as did
                           ,      e1.first_name||' '||e1.last_name as nm
                           ,      d.department_name as dnm
                           from   hr.employees e1
                           ,      hr.departments d
                           where  e1.department_id=d.department_id
                         ) a1
                    ,    ( select d.department_id as did
                           ,      count(e1.employee_id) as hc
                           ,      avg(e1.salary)as sal
                           from   hr.employees e1
                           ,      hr.departments d
                           where  e1.department_id=d.department_id
                           group by d.department_id
                          ) b
                    where a1.did=b.did
                  )
      loop
        dbms_output.put_line(rec1.dnm||' - '||rec1.nm||' - '||rec1.did||' - '||rec1.hc||' - '||rec1.sal);
      end loop;
    end;
    /
    

    Edit
    Use code tags when you post for example, keep formatting and indenting.
    See: http://wiki.oracle.com/page/Oracle+Discussion+Forums+FAQ (scroll down a bit)

    Published by: hoek on November 24, 2009 16:01

  • stamenet sql tune with exists and not exists has subquerys

    Hello

    Please advice me how I can resolve the application below.

    Database version:

    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

    PL/SQL Release 10.2.0.4.0 - Production

    CORE 10.2.0.4.0 Production

    AMT for HP - UX: release 10.2.0.4.0 - Production

    NLSRTL Version 10.2.0.4.0 - Production

    Query:

    Select / * + RULE * /.

    VD.*

    of encyc_owner.v_document vd

    where rownum < =: b_max_hits and

    VD.start_page = 0 and

    VD.end_page = 0 and

    VD.doc_type_id =: b_doc_type_id and

    THERE ARE

    (select 1

    of encyc_owner.t_doc_user_group_xref tdugx,.

    encyc_owner.t_user_group_xref tugx

    where tdugx.doc_version_id = vd.doc_version_id and

    tdugx.user_group_id = tugx.user_group_id and

    tugx.user_id =: b_user_id and

    tdugx.start_date < =: b_effective_date and

    tdugx.end_date > =: b_effective_date) and

    NOT EXIST

    (select 1

    of encyc_owner.t_doc_version tdvalt,.

    encyc_owner.t_doc_user_group_xref tdugx,

    encyc_owner.t_user_group_xref tugx

    where tdvalt.document_id = vd.document_id and

    tdvalt.version_date > vd.version_date and

    tdugx.doc_version_id = tdvalt.doc_version_id and

    tdugx.user_group_id = tugx.user_group_id and

    tugx.user_id =: b_user_id and

    tdugx.start_date < =: b_effective_date and

    tdugx.end_date > =: b_effective_date)

    order of vd.doc_type_label, vd.doc_type_id, vd.document_label, vd.document_id, vd.version_date, vd.version_major, vd.version_minor, vd.doc_version_id, vd.start_page, vd.end_page

    Execution plan:

    PLAN_TABLE_OUTPUT

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Hash value of plan: 2201102624

    ---------------------------------------------------------------------------------------------------------------------

    | ID | Operation | Name                    | Lines | Bytes | Cost (% CPU). Time |

    ---------------------------------------------------------------------------------------------------------------------

    |   0 | SELECT STATEMENT |                         |     1.   338.   597 (1) | 00:00:08 |

    |   1.  SORT ORDER BY |                         |     1.   338.   596 (1) | 00:00:08 |

    |*  2 |   COUNT STOPKEY |                         |       |       |            |          |

    |*  3 |    FILTER                                 |                         |       |       |            |          |

    |   4.     NESTED LOOPS |                         |     1.   338.   594 (1) | 00:00:08 |

    |   5.      NESTED LOOPS |                         |     1.   312.   594 (1) | 00:00:08 |

    PLAN_TABLE_OUTPUT

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    |   6.       NESTED LOOPS |                         |     1.   300.   594 (1) | 00:00:08 |

    |   7.        NESTED LOOPS |                         |     1.   229.   593 (1) | 00:00:08 |

    |   8.         NESTED LOOPS |                         |     1.   218.   593 (1) | 00:00:08 |

    |*  9 |          HASH JOIN |                         |    35.  4655.   579 (1) | 00:00:07 |

    |  10.           NESTED LOOPS |                         |  1134 | 81648 |   468 (1) | 00:00:06 |

    |  11.            NESTED LOOPS |                         |  1134 | 54432 |    14 (0) | 00:00:01 |

    |  12.             TABLE ACCESS BY INDEX ROWID | T_DOC_TYPE |     1.    42.     0 (0) | 00:00:01 |

    | * 13 |              INDEX UNIQUE SCAN | PK_DOC_TYPE |     1.       |     0 (0) | 00:00:01 |

    |  14.             VIEW                          | VW_SQ_1                 |  1134 |  6804 |    14 (0) | 00:00:01 |

    |  15.              UNIQUE FATE |                         |  1134 | 36288 |            |          |

    |  16.               NESTED LOOPS |                         |  1134 | 36288 |    14 (0) | 00:00:01 |

    PLAN_TABLE_OUTPUT

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    |  17.                TABLE ACCESS BY INDEX ROWID | T_DOC_USER_GROUP_XREF |  2036 | 48864 |    14 (0) | 00:00:01 |

    | * 18.                 INDEX RANGE SCAN | I_DOC_USER_GROUP_XREF_3 |    66.       |    13 (0) | 00:00:01 |

    | * 19.                INDEX UNIQUE SCAN | I_USER_GROUP_XREF_1 |     1.     8.     0 (0) | 00:00:01 |

    |  20.            TABLE ACCESS BY INDEX ROWID | T_DOC_VERSION |     1.    24.     0 (0) | 00:00:01 |

    | * 21.             INDEX UNIQUE SCAN | PK_DOC_VERSION |     1.       |     0 (0) | 00:00:01 |

    |  22.           TABLE ACCESS BY INDEX ROWID | T_DOCUMENT | 13986.   833K |   110 (0) | 00:00:02 |

    | * 23.            INDEX RANGE SCAN | I_DOCUMENT_1 | 13986.       |     8 (0) | 00:00:01 |

    |  24.          TABLE ACCESS BY INDEX ROWID | T_DOC_SECTION |     1.    85.     0 (0) | 00:00:01 |

    | * 25.           INDEX UNIQUE SCAN | I_DOC_SECTION_1 |     1.       |     0 (0) | 00:00:01 |

    |  26.         TABLE ACCESS BY INDEX ROWID | T_DOC_LINK_XREF |     1.    11.     1 (0) | 00:00:01 |

    | * 27.          INDEX RANGE SCAN | I_DOC_LINK_XREF_1 |     1.       |     0 (0) | 00:00:01 |

    PLAN_TABLE_OUTPUT

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    |  28.        TABLE ACCESS BY INDEX ROWID | T_DOC_LINK |     1.    71.     0 (0) | 00:00:01 |

    | * 29.         INDEX UNIQUE SCAN | PK_DOC_LINK |     1.       |     0 (0) | 00:00:01 |

    |  30.       TABLE ACCESS BY INDEX ROWID | T_STORAGE |     1.    12.     0 (0) | 00:00:01 |

    | * 31.        INDEX UNIQUE SCAN | PK_STORAGE |     1.       |     0 (0) | 00:00:01 |

    |  32.      TABLE ACCESS BY INDEX ROWID | T_MEDIA |     1.    26.     0 (0) | 00:00:01 |

    | * 33 |       INDEX UNIQUE SCAN | PK_MEDIA_TYPE |     1.       |     0 (0) | 00:00:01 |

    |  34.     NESTED LOOPS |                         |     1.    51.     1 (0) | 00:00:01 |

    |  35.      NESTED LOOPS |                         |     1.    27.     1 (0) | 00:00:01 |

    |  36.       TABLE ACCESS BY INDEX ROWID | T_DOC_VERSION |     1.    19.     1 (0) | 00:00:01 |

    | * 37 |        INDEX RANGE SCAN | I_DOC_VERSION_2 |     1.       |     1 (0) | 00:00:01 |

    | * 38 |       INDEX RANGE SCAN | I_USER_GROUP_XREF_1 |     3.    24.     0 (0) | 00:00:01 |

    PLAN_TABLE_OUTPUT

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    | * 39 |      TABLE ACCESS BY INDEX ROWID | T_DOC_USER_GROUP_XREF |     1.    24.     0 (0) | 00:00:01 |

    | * 40 |       INDEX UNIQUE SCAN | I_DOC_USER_GROUP_XREF_1 |     1.       |     0 (0) | 00:00:01 |

    ---------------------------------------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):

    ---------------------------------------------------

    2 filter (ROWNUM < = TO_NUMBER (:B_MAX_HITS)))

    3 filter (NOT EXISTS (SELECT / * + * / 'ENCYC_OWNER' 0.)) "" T_USER_GROUP_XREF ".

    "TUGX", "ENCYC_OWNER". "" T_DOC_USER_GROUP_XREF ""TDUGX","ENCYC_OWNER ". ' ' T_DOC_VERSION ' 'TDVALT' WHERE

    'TDVALT '. "' VERSION_DATE ' IS NOT NULL AND"TDVALT ". "" VERSION_DATE ">: B1 AND 'TDVALT '. "DOCUMENT_ID" =: B2 AND "

    PLAN_TABLE_OUTPUT

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    'TDUGX '. "" USER_GROUP_ID "=" TUGX. " "" USER_GROUP_ID "AND"TDUGX ". "" DOC_VERSION_ID "=" TDVALT. " "" DOC_VERSION_ID "AND

    'TDUGX '. "" Start_date "< =: B_EFFECTIVE_DATE AND"TDUGX. " "' End_date ' > =: B_EFFECTIVE_DATE AND

    'TUGX '. "USER_ID"= TO_NUMBER (:B_USER_ID)))

    9 - access("TD".") DOC_TYPE_ID "=" TDT ". "" DOC_TYPE_ID "AND"TD ". «DOCUMENT_ID '=' TDV '.» DOCUMENT_ID")

    13 - access("TDT".") DOC_TYPE_ID '= TO_NUMBER (:B_DOC_TYPE_ID)).

    18 - access("TDUGX".") End_date"> =: B_EFFECTIVE_DATE AND"TDUGX. " ("" Start_date "< =: B_EFFECTIVE_DATE)

    filter ("TDUGX". "End_date" (> =: B_EFFECTIVE_DATE) "

    19 - access("TUGX".") USER_ID "= TO_NUMBER(:B_USER_ID) AND"TDUGX". "" USER_GROUP_ID "=" TUGX. " ("' USER_GROUP_ID")

    21 - access ("DOC_VERSION_ID"= "TDV"." DOC_VERSION_ID')

    23 - access("TD".") DOC_TYPE_ID '= TO_NUMBER (:B_DOC_TYPE_ID)).

    25 - access("TDV".") DOC_VERSION_ID "=" TDS ". "" DOC_VERSION_ID "AND"TDS ". "START_PAGE"= 0 AND "TDS". "END_PAGE"= 0)

    PLAN_TABLE_OUTPUT

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    27 - access("TDV".") DOC_VERSION_ID "=" TDLX. " ("' DOC_VERSION_ID")

    29 - access("TDLX".") DOC_LINK_ID "=" TDL ". ("' DOC_LINK_ID")

    31 - access("TDL".") STORAGE_ID "=" TS ". ("' STORAGE_ID")

    33 - access("TDL".") MEDIA_ID "=" TM ". ("' MEDIA_ID")

    37 - access("TDVALT".") DOCUMENT_ID "=: B1 AND"TDVALT"". "" VERSION_DATE">: B2 AND 'TDVALT '. "' VERSION_DATE ' IS NOT

    NULL)

    38 - access("TUGX".") USER_ID "= TO_NUMBER (:B_USER_ID))

    39 - filter("TDUGX".") Start_date"< =: B_EFFECTIVE_DATE AND"TDUGX. " ("' End_date ' > =: B_EFFECTIVE_DATE)

    40 - access("TDUGX".") DOC_VERSION_ID "=" TDVALT. " "" DOC_VERSION_ID "AND

    'TDUGX '. "" USER_GROUP_ID "=" TUGX. " ("' USER_GROUP_ID")

    Can you check if her below meets your expectations.

    Select / * + RULE * /.

    VD.*

    of encyc_owner.v_document vd

    where rownum<= :b_max_hits="">

    VD.start_page = 0 and

    VD.end_page = 0 and

    VD.doc_type_id =: b_doc_type_id and

    THERE ARE

    (select 1

    of encyc_owner.t_doc_version tdvalt,.

    encyc_owner.t_doc_user_group_xref tdugx,

    encyc_owner.t_user_group_xref tugx

    where tdvalt.document_id = vd.document_id and

    tdvalt.version_date > vd.version_date and

    tdugx.doc_version_id = tdvalt.doc_version_id and

    tdugx.doc_version_id = vd.doc_version_id and

    tdugx.user_group_id = tugx.user_group_id and

    tugx.user_id =: b_user_id and

    tdugx.start_date<= :b_effective_date="">

    tdugx.end_date > =: b_effective_date)

Maybe you are looking for

  • Installation/uninstallation program has stopped working

    I get this error message whenever I try to uninstall any program.  It seems to have started randomly.  Here is a screenshot. I am running Vista 64 bit.  I surfed on the other questions and answers on the internet and did not help.  The computer is 4

  • Level code 5508 in HA mode without interruption

    I'm going to do my first upgrade with 5508 s in HA mode, and from what I've read that the APs will have restart all at the same time and load the new code that is pushed to her advance. I work in an environment where downtime is very difficult to hav

  • Checkbox labels disappear and colors modified during export to interactive PDF

    I did an InDesign document that contains two simple text boxes: one containing the word 'Yes' – the other containing the word 'no '. The background color of these two boxes are defined as 100% Cyan. After that, I have converted both of them boxes [(v

  • Why the preview of the image seems to be solarized?

    Sorry if this is a stupid question, Im new in LR and I can't understand why all my photos appear like this

  • The caterpillars 3D scene is too big

    I use motion tracking in AE (right click - camera approach) but when I open it in C4D it becomes too big. I do 100cm of radius of the sphere, but it seems so small in the scene.Screenshot below. I adjusted the target to make bigger it, but when they