Internal XML to the query with join

I have a CF page that reads an XML file in a query using < cffile > XMLParse and QueryAddrow.

I then do a QoQ on the result and voila! I have my page.  I hide the query for 8 hours and the XML file is only reread this cache expires.  It works well.

My problem now is that the file contains data from three tables of database instead of one, so I need to make an inner join on the tables.  But I can't do a t/t with an inner join.

Does anyone know a way for me to do this?

Oh, didn't know that.  How about interweaving of QofQ?  Join Query1 and Query2 requests in a new query, then join for 3 statement?

Tags: ColdFusion

Similar Questions

  • 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

  • Performance issue with the query when join OKS and tables of the IB

    Hello

    I'm developing an integration for the automation of RMA through repair. The type of repair order is based on the details of the guarantee. This check must be made for each record.

    Request for detailed below, I wrote, but it of a long way and slows down my program. Without this validation, it works perfectly.

    The problem is the join of tables with OKS IB, he kills performance. I also try to my side,

    any suggestion or help is appreciated. Here's the query in the program:

    SELECT DISTINCT (TYPE |) '-' || service | '-' || status)

    IN v_war_details

    FROM (SELECT TO_NUMBER (linesb.line_number) line,

    DECODE

    (fnd_profile. VALUE

    ('OKS_LINE_MIRR_NAME_OR_DESC'),

    'DISPLAY_NAME', sysitems.concatenated_segments,

    "DISPLAY_DESC", sysitems.description

    ) service.

    linestyletl.NAME TYPE,

    status of ststl.meaning,

    start_date linesb.start_date,

    linesb.end_date end_date,

    oks_misc_util_web.duration_period

    (linesb.start_date,

    linesb.end_date

    ) DURATION OF,.

    TimeUnit.unit_of_measure_tl period

    Of okc_k_lines_b linesb,.

    okc_k_lines_tl linestl,

    okc_line_styles_b linestyleb,

    okc_line_styles_tl linestyletl,

    okc_k_headers_all_b hdr,

    oks_k_lines_b slines,

    okc_k_items kitems,

    mtl_system_items_b1_kfv sysitems,

    okc_statuses_b stsb,

    okc_statuses_tl ststl,

    mtl_units_of_measure_tl timeunit,

    okc_lookups_v rentype,

    Glu mtl_units_of_measure_tl

    WHERE linesb.cle_id IS NULL

    AND linesb.ID = linestl.ID

    AND linestl. LANGUAGE = USERENV ("LANG")

    AND linesb.lse_id = linestyleb.ID

    AND linesb.lse_id (1, 12, 14, 19, 46)

    AND linestyleb.ID = linestyletl.ID

    AND linestyletl. LANGUAGE = USERENV ("LANG")

    AND linesb.chr_id = hdr.ID

    AND linesb.ID = slines.cle_id

    AND linesb.ID = kitems.cle_id

    AND kitems.object1_id1 =

    SysItems.inventory_item_id

    AND kitems.object1_id2 =

    SysItems.organization_id

    AND kitems.uom_code = uom.uom_code (+)

    AND unit of measure. LANGUAGE (+) = USERENV ("LANG")

    AND linesb.sts_code = stsb.code

    AND stsb.code = ststl.code

    AND ststl. LANGUAGE = USERENV ("LANG")

    AND timeunit.uom_code =

    oks_misc_util_web.duration_unit

    (linesb.start_date,

    linesb.end_date

    )

    AND timeunit. LANGUAGE = USERENV ("LANG")

    AND linesb.line_renewal_type_code = rentype.lookup_code (+)

    AND rentype.lookup_type (+) =

    'OKC_LINE_RENEWAL_TYPE '.

    AND (IN) hdr.ID

    SELECT kh.ID

    Of okc_k_headers_all_b kh.

    okc_k_lines_b kl,

    Ki okc_k_items,

    okc_line_styles_v ks,

    csi_item_instances c,

    mtl_system_items_b I have

    WHERE kh.org_id = p_org_id

    AND c.instance_id = p_instance_id

    AND c.serial_number = p_serial_num

    AND i.inventory_item_id =

    p_inventory_item_id

    AND kh.contract_number_modifier IS NULL

    -can be filled

    AND kh.ID = kl.dnz_chr_id

    AND kh.ID = ki.dnz_chr_id

    AND kl.ID = ki.cle_id

    AND kl.lse_id = ks.ID

    AND IN ki.jtot_object1_code

    ("OKX_CUSTPROD")

    AND c.last_vld_organization_id =

    i.organization_id

    AND TO_NUMBER (ki.object1_id1) =

    c.INSTANCE_ID

    AND c.inventory_item_id =

    i.inventory_item_id))

    Service = 'GUARANTEE '.

    AND TRUNC (SYSDATE) BETWEEN start_date AND end_date;

    Not sure where it would be so I put it in the section SQL/PLSQL.

    Kind regards

    Prashant

    Found the solution

    AND TO_NUMBER (ki.object1_id1) = c.instance_id

    replaced by to_char (c.instance_id) = ki.object1_id1 AND

  • Need help in the optimization of the query with the Group and joins by clause

    I'm having the problem by running the following query... It takes a lot of time. To simplify, I added the two tables FILE_STATUS = stores the file load details and COMM table Board table job showing records treated successfully and which was communicated to the other system real. Records with status = T is trasnmitted to another system and traansactions with P is waiting.
    CREATE TABLE FILE_STATUS
    (FILE_ID VARCHAR2(14),
    FILE_NAME VARCHAR2(20),
    CARR_CD VARCHAR2(5),
    TOT_REC NUMBER,
    TOT_SUCC NUMBER);
    
    CREATE TABLE COMM
    (SRC_FILE_ID VARCHAR2(14),
    REC_ID NUMBER,
    STATUS CHAR(1));
    
    INSERT INTO FILE_STATUS VALUES ('12345678', 'CM_LIBM.TXT', 'LIBM', 5, 4);
    INSERT INTO FILE_STATUS VALUES ('12345679', 'CM_HIPNT.TXT', 'HIPNT', 4, 0);
    
    INSERT INTO COMM VALUES ('12345678', 1, 'T');
    INSERT INTO COMM VALUES ('12345678', 3, 'T');
    INSERT INTO COMM VALUES ('12345678', 4, 'P');
    INSERT INTO COMM VALUES ('12345678', 5, 'P');
    COMMIT;
    Here's the query I wrote to give me the details of the file that has been loaded into the system. He reads the table of State and the commission files to display the name of the file, total records loaded, total at the table of the commission and the number of records which has finally been passed successfully loaded (Status = T) with other systems.
    SELECT 
        FS.CARR_CD 
        ,FS.FILE_NAME 
        ,FS.FILE_ID
        ,FS.TOT_REC
        ,FS.TOT_SUCC
        ,NVL(C.TOT_TRANS, 0) TOT_TRANS
    FROM FILE_STATUS FS
    LEFT JOIN
    (
        SELECT SRC_FILE_ID, COUNT(*) TOT_TRANS
        FROM COMM
        WHERE STATUS = 'T'
        GROUP BY SRC_FILE_ID
    ) C ON C.SRC_FILE_ID = FS.FILE_ID
    WHERE FILE_ID = '12345678';
    In production, this request has several joins and takes a long time to deal with... the main culprit for me is the join on the COMM table to count the number of number of transactions sent. Please can you give me tips to optimize this query to get results faster? What I need to delete the Group and use the partition or something else. Help, please!

    Don't know if it will be faster based on the information provided, but analytical functions offer an alternative approach;

    select carr_cd, file_name, file_id, tot_rec, tot_succ, tot_trans
      from (select fs.carr_cd,
                   fs.file_name,
                   fs.file_id,
                   fs.tot_rec,
                   fs.tot_succ,
                   count(case
                            when c.status = 'T' then
                             1
                            else
                             null
                          end) over(partition by c.src_file_id) tot_trans,
                   row_number() over(partition by c.src_file_id order by null) rn
              from file_status fs
              left join comm c
                on c.src_file_id = fs.file_id
             where file_id = '12345678')
     where rn = 1;
    
    CARR_CD FILE_NAME            FILE_ID           TOT_REC   TOT_SUCC  TOT_TRANS
    ------- -------------------- -------------- ---------- ---------- ----------
    LIBM    CM_LIBM.TXT          12345678                5          4          2
    
  • How to optimize the query with a join of virtual tables

    I'm working on a query that is get the data of virtual tables 2 and b
    one is formed by the Union, all say 4 queries and b is formed by the Union, all say 3 queries
    then these two virtual tables and b are joined on a column common and data are extracted from their part.
    Problem is that there is about 1 minutes each in the two virtual tables has and b. If individual a and b queries virtual takes about 5 seconds to retrieve data
    but the join on column takes about 25 seconds to retrieve data.
    Can someone guide me how to optimize the recovery of joining 2 virtual tables having large data

    Thank you

    Please read these:

    When your query takes too long
    When your query takes too long...

    How to post a SQL tuning request
    HOW to: Validate a query of SQL statement tuning - model showing

  • Structure of the query with parameters

    Hello
    Consume the web service, the results in a file xml with complex structures.
    The function below the structure of the query
    < TemplateName CcResultItems = "CgrInfo_1" >
    My question is how to reorganize the query to obtain the results of the structure
    < TemplateName CcResultItems = "CgrOwners_4" >
    which should return three rows.

    Kind regards
    Kostadin

    create or replace
    FUNCTION WS_SELECT_XML RETURN VARCHAR2 AS
    XML_VAR XMLTYPE: = XMLTYPE)
    "" ' < soap envelope: xmlns:soap = 'http://www.w3.org/2003/05/soap-envelope"" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" container = "http://www.w3.org/2001/XMLSchema" >. "
    < soap: Header >
    "< XmlSoapHeader xmlns ="https://test.wstestx.com/XWS2/ "/>"
    < / soap: Header >
    < soap: Body >
    "< ProcessRequestResponse xmlns ="https://test.wstestx.com/XWS2/">."
    < ProcessRequestResult > <! [CDATA [< CcResponse >

    < TemplateName CcResultItems = "CgrInfo_1" >
    < CcResultItem > < InfoMessage > < / InfoMessage > < IsitTerminated > 0 < / IsitTerminated > < IdObject > 365124 < / IdObject > < sanctuary ObjectlName > < / ObjectlName > < ObjectTaxNumber > 305089321502 < / ObjectTaxNumber > < / CcResultItem >
    < / CcResultItems >
    < TemplateName CcResultItems = "CgrUnits_2" >
    < / CcResultItems >
    < TemplateName CcResultItems = "CgrActors_3" >
    < CcResultItem > < IdObject > 365124 < / IdObject > < UnitNo > 0 < / UnitNo > < EntityTYPEcode > 1 < / EntityTYPEcode > < EntityTYPEdesc > person < / EntityTYPEdesc > < / CcResultItem >
    < / CcResultItems >
    < TemplateName CcResultItems = "CgrOwners_4" >
    < CcResultItem > < IdObject > 365124 < / IdObject > < EntityTYPEcode > 1 < / EntityTYPEcode > < EntityTYPEdesc > person < / EntityTYPEdesc > < OwnerID > 610697843014 < / OwnerID > < OwnerName > ALEX < / OwnerName > < / CcResultItem >
    < CcResultItem > < IdObject > 365124 < / IdObject > < EntityTYPEcode > 1 < / EntityTYPEcode > < EntityTYPEdesc > person < / EntityTYPEdesc > < OwnerID > 840645947005 < / OwnerID > < OwnerName > JOHN < / OwnerName > < / CcResultItem >
    < CcResultItem > < IdObject > 365124 < / IdObject > < EntityTYPEcode > 2 < / EntityTYPEcode > < company EntityTYPEdesc > < / EntityTYPEdesc > < OwnerID > 703454 < / OwnerID > < OwnerName > BROWN < / OwnerName > < / CcResultItem >
    < / CcResultItems >
    < TemplateName CcResultItems = "CgrActivities_5" >
    < / CcResultItems >
    < TemplateName CcResultItems = "CgrMembership_6" >
    < / CcResultItems >
    < TemplateName CcResultItems = "CgrFounding_7" >
    < CcResultItem > < IdObject > 365124 < / IdObject > < FoundingDate > 2007-08-16 13:53 < / FoundingDate > < Total > 146701.00 < / Total > < / CcResultItem >
    < / CcResultItems >
    [[< / CcResponse >]] > < / ProcessRequestResult >
    < / ProcessRequestResponse >
    < / soap: Body >
    < / envelope soap: >
    ');
    BEGIN
    FOR R IN)
    WITH T AS (SELECT (XML_VAR) DOUBLE COLLAR)
    SELECT x2.*
    FROM XMLTable)
    XMLNamespaces)
                ' http://www.w3.org/2003/05/soap-envelope ' LIKE 'SOAP'
    , by default ' https://test.wstestx.com/XWS2/ '
    )
    , ': soap envelope / soap: Body/ProcessRequestResponse/ProcessRequestResult '
    by the way XML_VAR
    path of CcResponse clob columns '.'
    ) x 1
    XMLTABLE)
    ' / CcResponse/CcResultItems.
    XMLPARSE PASSAGE (DOCUMENT X 1.) CCRESPONSE)
    COLUMNS
    TemplateName VARCHAR2 (140) path "@TemplateName"
    , IDOBJECT VARCHAR2 (140) PATH "CcResultItem/IdObject.
    , PATH of VARCHAR2 (340) OBJECTLNAME ' CcResultItem/ObjectlName '.

    , PATH of VARCHAR2 (140) VRSKA 'CcResultItem '.
    ) X 2
    WHERE X 2. TemplateName = "CgrInfo_1."
    -WHERE X 2. TemplateName = "CgrActors_3."
    -WHERE X 2. TemplateName = "CgrOwners_4."
    ) LOOP
    DBMS_OUTPUT. Put_line (' IdObject: ' |) R.IDOBJECT |  ' ObjectlName: ' | R.ObjectlName | "TemplateName ' |" R.TemplateName);
    END LOOP;
    DBMS_OUTPUT. Put_line ("- end -");
    RETURNS A NULL VALUE.
    END WS_SELECT_XML;

    Based on your query, I'll assume that you started with

    Extract data from webservice response

    In my opinion, it comes of the change you are looking for

    FOR R IN (
       SELECT x2.TemplateName, x3.idobject, x3.OWNERID
          FROM XMLTable(
                 XMLNamespaces(
                   'http://www.w3.org/2003/05/soap-envelope' AS "soap"
                 , default 'https://test.wstestx.com/XWS2/'
                 )
               , 'soap:Envelope/soap:Body/ProcessRequestResponse/ProcessRequestResult'
                 passing XML_VAR
                 columns
                 CcResponse clob path '.'
               ) x1
          , XMLTABLE(
              '/CcResponse/CcResultItems[@TemplateName="CgrOwners_4"]'
              PASSING XMLPARSE(DOCUMENT X1.CCRESPONSE)
              COLUMNS
                      TemplateName  VARCHAR2(20) PATH '@TemplateName'
                    , ItemXML       XMLTYPE       PATH 'CcResultItem'
            ) X2
          , XMLTABLE(
              '/CcResultItem'
              PASSING x2.itemXML
              COLUMNS
                      IDOBJECT      VARCHAR2(20) PATH 'IdObject'
                    , OWNERID       VARCHAR2(20) PATH 'OwnerID'
            ) X3
    )
    

    As Odie post pointed out.  The first (x 1) XMLTable retrieves the content of ProcessRequestRequest and by doing this, delete the CDATA tag.  We now have a CLOB that resembles XML.  The second XMLTable (x 2) converts this CLOB into an XMLType and looking for the node that matches the XPath expression.  It's where I've hardcoded in your query to search for a specific node.  As you want node has a repeated structure that you want to retrieve each row, I spent structures repeatedly in the third XMLTable (x 3) so he could analyze.  You could combine x 2 and x 3 using XQuery, but I suggest starting by this method I found that it's easier to understand what is happening.

    To test out your code, simply replace the line

    by the way XML_VAR

    with

    from XMLTYPE ("... the content of the SOAP Message...")

    and run the query.  You can do this to debug the query as you and just do a SELECT * to see what all went from XMLTable to XMLTable, so went to check the correct data.

  • Combine two results of the query with rank

    Dear all,

    I'm an analyst working DB for the first time:

    I have two requests:
    1)
    Select * (select 'CAFNo', 'ActionDate', 'ActionDetail', rank() on rnk (partition by order of 'CAFNo' through 'ActionDate'),
    of 'ABC '.
    where 'ActionDetail '.
    as 'FIU successfully presented and routed to the fulfillment team %')
    where rnk = 1

    Results in
    CAFNo', 'ActionDate1', 'ActionDetail '.

    2)
    Select * (select rank() on rnk (partition by order of "CAFNo" by "ActionDate"), 'CAFNo', 'ActionDate', 'ActionDetail'
    of 'ABC '.
    where 'ActionDetail '.
    like '% customer ID %')
    where rnk = 1

    Results in
    CAFNo', 'ActionDate2', 'ActionDetail '.
    ---------------------------------------------------------------------
    I would like to combine the results of two as:
    No College, Actiondate1, actiondate2, ActionDetail

    I tried the full outer join and other options but without success. Help, please
    Please share concept to join the two results not the actual query.
    with t as (
               select  "CAFNo",
                       "ActionDate",
                       "ActionDetail",
                       case
                         when "ActionDetail" like '%Customer ID%' then 2
                         else 1
                       end weight,
                       rank() over(
                                   partition by "CAFNo",
                                                 case
                                                   when "ActionDetail" like '%Customer ID%' then 2
                                                   else 1
                                                 end
                                   order by "ActionDate"
                                  ) rnk
                 from  "ABC"
                 where "ActionDetail" like '%Customer ID%'
                    or "ActionDetail" like 'CRF successfully submitted and routed to Fulfillment Team%'
              )
    select  "CAFNo",
            max(
                case weight
                  when 1 then "ActionDate"
                end
               ) "ActionDate1",
            max(
                case weight
                  when 2 then "ActionDate"
                end
               ) "ActionDate2",
            max(
                case weight
                  when 1 then "ActionDetail"
                end
               ) "ActionDetail1",
            max(
                case weight
                  when 2 then "ActionDetail"
                end
               ) "ActionDetail2"
      from  t
      where rnk = 1
      group by "CAFNo"
    /
    

    SY.

  • Hierarchical query with join

    Hi all
    I want to reproduce the following query:
    SQL> select to_char(level,'9') Lev,
    first_name||' '||last_name Name, 
    sys_connect_by_path((select first_name||' '||last_name from employees m where e.manager_id=m.employee_id),'/')Path,
    (select department_name from departments d where d.department_id=e.department_id) Department 
    from employees e 
    start with employee_id=100 
    connect by manager_id=prior employee_id order siblings by 4,3,2;
    
    LE NAME           PATH                      DEPARTMENT
    -- -------------------- ------------------------------ ---------------
     1 Steven King          /                      Executive
     2 Lex De Haan          //Steven King                 Executive
     3 Alexander Hunold     //Steven King/Lex De Haan      IT
     4 Bruce Ernst          //Steven King/Lex De Haan/Alex IT
                   ander Hunold
    
    -- QUERY TRUNCATED --
    
     3 Sarah Bell          //Steven King/Shanta Vollman   Shipping
     3 Stephen Stiles     //Steven King/Shanta Vollman   Shipping
     3 Vance Jones          //Steven King/Shanta Vollman   Shipping
    
    107 rows selected.
    with a JOIN query. This query uses the example of the HR diagram and displays the names of the employees with their managers and departments using join instead of correlated query. So far, I got:
    SQL> select first_name|| ' '||last_name Name,
    Manager,Department from employees e,
    (select first_name||' '||last_name Manager,employee_id,first_name first from employees) m ,
    (select department_name Department,department_id from departments) d 
    where e.manager_id=m.employee_id  and e.department_id=d.department_id;
    
    NAME               MANAGER            DEPARTMENT
    -------------------- -------------------- --------------------
    Lex De Haan          Steven King       Executive
    Neena Kochhar          Steven King       Executive
    Eleni Zlotkey          Steven King       Sales
    Gerald Cambrault     Steven King       Sales
    Alberto Errazuriz    Steven King       Sales
    Karen Partners          Steven King       Sales
    
    -- QUERY TRUNCATED --
    
    John Russell          Steven King       Sales
    Kevin Mourgos          Steven King       Shipping
    Shanta Vollman          Steven King       Shipping
    Payam Kaufling          Steven King       Shipping
    Adam Fripp          Steven King       Shipping
    Pat Fay           Michael Hartstein       Marketing
    William Gietz          Shelley Higgins       Accounting
    
    105 rows selected.
    
    SQL> select first_name|| ' '||last_name Name,
    Manager,Department from employees e,
    (select first_name||' '||last_name Manager,employee_id,first_name first from employees) m ,
    (select department_name Department,department_id from departments) d where e.manager_id=m.employee_id  and e.department_id=d.department_id 
    start with e.employee_id=100 connect by e.manager_id=prior e.employee_id;
    
    no rows selected
    
    SQL> 
    But the above query returns lines until I have slides BEGIN WITH CONNECT BY clause, which returns nothing. What is the problem with the START WITH CONNECT BY clause from the second query?

    Best regards
    TA.

    Published by: Valerie good-natured April 18, 2011 02:54

    Employee no. 100 has no manager_id, so you need an outer join:

    select first_name|| ' '||last_name Name,
    Manager,Department from employees e,
    (select first_name||' '||last_name Manager,employee_id,first_name first from employees) m ,
    (select department_name Department,department_id from departments) d where
    e.manager_id=m.employee_id (+)
    and e.department_id=d.department_id (+)
    start with e.employee_id=100 connect by e.manager_id=prior e.employee_id;
    

    Hope this helps,
    Tony

  • Please help improve the query with the analytic function

    The mentioned below query takes about 10 hours to complete (10.2.0.4).

    There are 3 tables (table t has a relationship 1: n with table e and k table also has a relationship 1: n with table e).
    Table a contains 200,000 lines. (this table is truncated and inserted several times a week)
    E table contains rows of 1Mio.
    K table contains rows of 170Mio.

    drop table t;
    create table t
    (
       t_id number,
       constraint t_pk primary key (t_id)
    );
    
    drop table e;
    create table e
    (
       e_id number,
       e_doc nvarchar2(16),
       e_date date,
       constraint e_pk primary key (e_id)
    );
    
    drop table k;
    create table k (
       t_id number,
       e_id number
    );
    
    create unique index k_i1 on k(t_id, e_id);
    
    exec dbms_stats.gather_table_stats(user, 'T');
    exec dbms_stats.gather_table_stats(user, 'K');
    exec dbms_stats.gather_table_stats(user, 'E');
    
    
    
    -- Sample data:
    
    insert into t(t_id) values (100);
    insert into t(t_id) values (101);
    insert into t(t_id) values (102);
    insert into t(t_id) values (103);
    
    
    insert into e(e_id, e_doc, e_date) values (200, 'doc 200', to_date('01.01.2010', 'DD.MM.YYYY'));
    insert into e(e_id, e_doc, e_date) values (201, 'doc 201', to_date('02.01.2010', 'DD.MM.YYYY'));
    insert into e(e_id, e_doc, e_date) values (202, 'doc 202', to_date('03.01.2010', 'DD.MM.YYYY'));
    insert into e(e_id, e_doc, e_date) values (203, 'doc 203', to_date('04.01.2010', 'DD.MM.YYYY'));
    insert into e(e_id, e_doc, e_date) values (204, 'doc 204', to_date('05.01.2010', 'DD.MM.YYYY'));
    insert into e(e_id, e_doc, e_date) values (205, 'doc 205', to_date('06.01.2010', 'DD.MM.YYYY'));
    insert into e(e_id, e_doc, e_date) values (206, 'doc 206', to_date('07.01.2010', 'DD.MM.YYYY'));
    insert into e(e_id, e_doc, e_date) values (207, 'doc 207', to_date('08.01.2010', 'DD.MM.YYYY'));
    
    insert into k(t_id, e_id) values (100, 200);
    insert into k(t_id, e_id) values (100, 201);
    insert into k(t_id, e_id) values (100, 202);
    insert into k(t_id, e_id) values (100, 203);
    
    insert into k(t_id, e_id) values (101, 203);
    insert into k(t_id, e_id) values (101, 204);
    
    
    
    
    
    select k.t_id, e.e_date,  e.e_id, e.e_doc
    from   e, k, t
    where  k.e_id = e.e_id
    and    k.t_id = t.t_id
    order by k.t_id, e.e_date desc;
    
    
          T_ID E_DATE         E_ID E_DOC
    ---------- -------- ---------- ----------------
           100 04.01.10        203 doc 203
           100 03.01.10        202 doc 202
           100 02.01.10        201 doc 201
           100 01.01.10        200 doc 200
           101 05.01.10        204 doc 204
           101 04.01.10        203 doc 203
    I need a query that takes the latest 3 posts for a given t_id:
          T_ID E_DOC_LIST
    ---------- -----------------------
           100 doc 200/doc 201/doc 202
           101 doc 203/doc 204
    
    
    Sample query:
    
    select t_id, e_doc_list
       from (
       select  k.t_id,
            row_number() over(partition by k.t_id order by k.t_id, e.e_date desc) r_num, 
            rtrim(       lag(e.e_doc, 0) over(partition by k.t_id order by k.t_id, e.e_date) || 
                  '/' || lag(e.e_doc, 1) over(partition by k.t_id order by k.t_id, e.e_date) || 
                  '/' || lag(e.e_doc, 2) over(partition by k.t_id order by k.t_id, e.e_date), 
                  '/') e_doc_list
         from  e,
               k,
               t
         where  k.e_id = e.e_id
         and    k.t_id = t.t_id
         order by k.t_id, e.e_date desc
    ) where  r_num = 1   ;
    
    
          T_ID E_DOC_LIST
    ---------- --------------------------------------------------
           100 doc 203/doc 202/doc 201
           101 doc 204/doc 203
    The example query takes several hours in production.
    The r_num = 1 filter is applied quite late. Is there another way to generate the query or even review the tables.
    For the sample query:
    
    -----------------------------------------------------------------------------------------
    | Id  | Operation                        | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    -----------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                 |      |     6 |   468 |     6  (50)| 00:00:01 |
    |*  1 |  VIEW                            |      |     6 |   468 |     6  (50)| 00:00:01 |
    |*  2 |   WINDOW SORT PUSHED RANK        |      |     6 |   216 |     6  (50)| 00:00:01 |
    |   3 |    WINDOW SORT                   |      |     6 |   216 |     6  (50)| 00:00:01 |
    |   4 |     NESTED LOOPS                 |      |     6 |   216 |     4  (25)| 00:00:01 |
    |   5 |      MERGE JOIN                  |      |     6 |   198 |     4  (25)| 00:00:01 |
    |   6 |       TABLE ACCESS BY INDEX ROWID| E    |     8 |   208 |     2   (0)| 00:00:01 |
    |   7 |        INDEX FULL SCAN           | E_PK |     8 |       |     1   (0)| 00:00:01 |
    |*  8 |       SORT JOIN                  |      |     6 |    42 |     2  (50)| 00:00:01 |
    |   9 |        INDEX FULL SCAN           | K_I1 |     6 |    42 |     1   (0)| 00:00:01 |
    |* 10 |      INDEX UNIQUE SCAN           | T_PK |     1 |     3 |     0   (0)| 00:00:01 |
    -----------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - filter("R_NUM"=1)
       2 - filter(ROW_NUMBER() OVER ( PARTITION BY "K"."T_ID" ORDER BY
                  "K"."T_ID",INTERNAL_FUNCTION("E"."E_DATE") DESC )<=1)
       8 - access("K"."E_ID"="E"."E_ID")
           filter("K"."E_ID"="E"."E_ID")
      10 - access("K"."T_ID"="T"."T_ID")
    
    
    and for query in production
    
    ---------------------------------------------------------------------------------------
    | Id  | Operation                 | Name         | Rows  | Bytes |TempSpc| Cost (%CPU)|
    ---------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT          |              |  3118K|   425M|       |   160K  (1)|
    |   1 |  VIEW                     |              |  3118K|   425M|       |   160K  (1)|
    |   2 |   SORT ORDER BY           |              |  3118K|   163M|   383M|   160K  (1)|
    |   3 |    WINDOW SORT PUSHED RANK|              |  3118K|   163M|   383M|   160K  (1)|
    |   4 |     WINDOW SORT           |              |  3118K|   163M|   383M|   160K  (1)|
    |   5 |      HASH JOIN            |              |  3118K|   163M|    40M| 33991   (1)|
    |   6 |       TABLE ACCESS FULL   | E            |  1053K|    28M|       |  4244   (1)|
    |   7 |       NESTED LOOPS        |              |  3118K|    80M|       | 21918   (1)|
    |   8 |        TABLE ACCESS FULL  | T            |   144K|  1829K|       |   282   (2)|
    |   9 |        INDEX RANGE SCAN   | K_I1         |    22 |   308 |       |     1   (0)|
    ---------------------------------------------------------------------------------------
    
     

    TimWong765 wrote:
    ...
    Table a contains 200,000 lines. (* this table is truncated and inserted several times a week *)

    You could be in one of the rare cases where the index should be rebuild, take a look in the following thread:
    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:6601312252730 #69571308712887 (search for 'index of Sweeper')
    Make sure that you have checked if you are in this case before going for an expensive index rebuild.

    Nicolas.

  • Run the query with multiple parameters

    Dear

    Motion code below for the data is of per_all_people_f, who works for only one setting, when I pass 2 parameters, then is to take the last of them fail times two, could you pls advice how it both join in where clause.

    ================================================================================

    --------------------------------control file ----------------------------------

    ================================================================================

    ' Public Sub processFormRequest (pageContext OAPageContext, OAWebBean webBean)

    {

    super.processFormRequest (pageContext, webBean);

    Am = (OAApplicationModule) pageContext.getApplicationModule (webBean) OAApplicationModule;

    OAApplicationModule am = pageContext.getRootApplicationModule ();

    String model = pageContext.getParameter ("ALL");

    String pempno = pageContext.getParameter ("paramEmpNo");

    String phiredt = pageContext.getParameter ("paramHireDate");

    System.out.println ("control controller exucution");

    If (pageContext.getParameter ("GetData")! = null)

    {

    System.out.println ("controller exucution");

    Boolean ExecuteQuery = BooleanUtils.getBoolean (false);

    [Serializable] parameters = {pempno, phiredt, model, executeQuery};

    Class [] paramTypes = {String.class, String.class, String.class, Boolean.class};

    am.invokeMethod ("initSummary", parameters, paramTypes);

    OAAdvancedTableBean = table

    (OAAdvancedTableBean) webBean.findChildRecursive ("ResultsTable");

    When a user of handling started looking, we always need to run

    the query, so we move on 'false' to queryData().

    table.queryData (pageContext, false);

    }

    }

    ================================================================================

    -Request module file-

    ================================================================================

    public void initSummary (string model,

    String ParmEmpNum,

    String ParmHireDt,

    String created,

    String showMyOrders,

    Boolean ExecuteQuery)

    {

    xxEmployeeVOImpl vo = getxxEmployeeVO1();

    If (vo is nothing)

    {

    Tokens [] MessageToken = {new MessageToken ("parameter", "xxEmployeeVO")};

    throw new OAException ("AK", "FWK_TBX_OBJECT_NOT_FOUND", chips);

    }

    vo.initQuery (model, ParmEmpNum, ParmHireDt, executeQuery);

    System.out.println ("calling vo...");

    }

    ================================================================================

    -xxEmployeeVOImpl-

    ================================================================================

    public void initQuery (String, String ParamEmpNum, String ParmHireDt, Boolean executeQuery model)

    {

    StringBuffer whereClause = new StringBuffer (100);

    Whole CheckWhere;

    Vector of parameters = new Vector (3);

    setWhereClause (null);

    setWhereClauseParams (null);

    Integer bindCount = 0;

    String WhereClause = null;

    If ((ParamEmpNum! = null) & & (!("".)) Equals (ParamEmpNum.Trim ()))

    {

    setWhereClause (null);

    setWhereClauseParams (null);

    setWhereClause ("EMPLOYEE_NUMBER =:" + CheckWhere);

    setWhereClauseParam(0,ParamEmpNum);

    System.out.println ("request" + this.getQuery ());

    System.out.println ("ParamEmpNum" + ParamEmpNum);

    CheckWhere = CheckWhere ++;

    }

    If ((ParmHireDt! = null) & & (!("".)) Equals (ParmHireDt.Trim ()))

    {

    CheckWhere = CheckWhere ++;

    If (CheckWhere > 1)

    {

    setWhereClause (null);

    setWhereClauseParams (null);

    setWhereClause ("AND START_DATE =:" + CheckWhere);

    setWhereClauseParam(0,ParmHireDt);

    System.out.println ("request" + this.getQuery ());

    }

    on the other

    {

    {setWhereClause (null);

    setWhereClauseParams (null);

    setWhereClause ("START_DATE =:"+ CheckWhere ");

    setWhereClauseParam(0,ParmHireDt);

    System.out.println ("request" + this.getQuery ()) ;}

    }

    System.out.println ("ParamEmpNum" + ParmHireDt);

    }

    System.out.println ("request" + this.getQuery ());

    executeQuery();

    Try this:

    public void initQuery(String dummy,String ParamEmpNum,String ParmHireDt, Boolean executeQuery)
    {
      System.out.println("ParamEmpNum: "+ ParamEmpNum);
      System.out.println("ParmHireDt : "+ ParmHireDt);
    
      setWhereClause(null);
      setWhereClauseParams(null);
    
      String WhereClause = null;
    
      int bindCount = 0;
      HashMap paramMap = new HashMap();
    
      if  ( (ParamEmpNum != null) && (!("".equals(ParamEmpNum.trim())))  )
      {
      paramMap.put(bindCount,ParamEmpNum);
      WhereClause = "EMPLOYEE_NUMBER = :"+ (++bindCount) + " AND ";
      }
      if  ( (ParmHireDt != null) && (!("".equals(ParmHireDt.trim())))  )
      {
      paramMap.put(bindCount,ParmHireDt);
      WhereClause = WhereClause + ("START_DATE = :"+ (++bindCount) + " AND ");
      }
      if(bindCount > 0)
      {
      // Remove the AND at the end
      WhereClause = WhereClause.substring(0, WhereClause.length()-5);
    
      setWhereClause(WhereClause);
      for(int i = 0; i < bindCount; i ++) {
      setWhereClauseParam(i,paramMap.get(i));
      }
      }
    
      System.out.println("Query "+ this.getQuery());
      executeQuery();
    }
    

    You may need to change the START_DATE whereclause as below:

    WhereClause = WhereClause + ("START_DATE = TO_DATE (:" + (++ bindCount) + ', "MON-DD-YYYY" ") AND" ' ");

    Note:-need to specify the correct format.

    See you soon

    AJ

  • Select the query with the level line list where the clause

    Hi all

    I am creating a tabular presentation based on a SQL query that has a list of selection based on a query with a where clause clause that refers to a column in the original SQL query.

    The situation is, I have a table that stores the client_id, source_id, and build_id, lets call it client_source. I have a second table, build_source, containing source_id and build_id, one to many relations between the two (1 source_id could have build_id 1-7).

    Using a tabular presentation, I want to select the correspondent build_id to use in client_source, but the selection list should contain only the build_id for this particular source_id of lines.

    Here is an example of the SQL source of tabular presentation;

    Select
    s.ROWID,
    s.CLIENT_ID,
    s.SOURCE_ID,
    APEX_ITEM. SELECT_LIST_FROM_QUERY (1, s.BUILD_ID,)
    "Select display b.build_id, b.build_id return.
    b build_source where b.source_id = s.SOURCE_ID ') lst
    of s client_source

    what I want to achieve, it's as source_id "BOLD" match fields. When the query is built this way, I get an error of "invalid identifier" Oracle on s.SOURCE_ID during execution.

    Is there some special tags to be used to refer to the external column? I must be missing something because this looks like a pretty mundane problem.

    I am running on 4.1.0.00.32, on an Oracle 10 g release 10.2.0.4.0 Server Express request.


    I look forward to useful responses!


    See you soon,.
    Jason

    Published by: 1005131 on May 9, 2013 19:02

    Your selection by query list receives a static SQL. That SQL can't "see" the value of your s.source_id.
    But it would work like this:
    where b.source_id = ' | s.SOURCE_ID)

    You would be the value for the SQL concatenation. It is not ideal, but it will work.

    Jorge

  • How to transpose the query with the following result

    Dear all,

    Can someone tell me a method to convert my query result

    Details are provided in

    http://obiee11ge.blogspot.com/2010/07/how-to-transpose-query-with-following.html

    Concerning

    Mustafa

    Hello

    Try this
    Create a request combined with,

    criterion no. 1: model, revenue (Actual), Cogs (Actual), Opex (Actual), PL (Actual)

    in the dummy column fx enter the "Real" value

    criterion 2: model, revenue (Yago), Cogs (YAgo), Opex (Yago), PL (Yago)

    in the dummy column fx enter the value as "Yago".

    criterion 3: model, revenue (Budget), Cogs (Budget), Opex (Budget), PL (Budget)

    in the dummy column fx enter the value as 'Budget '.

    Now go to the columns of result and set names coumn (revenue, COGS, Opex, PL) for the result set.
    For the Dumny, remove column header.

    In a sheet view, you will get the result.

    Thank you
    Vino

  • 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

  • Display of the results of the query with the column names unknown

    I use this code to grab the headers of columns in a select * statement. (I never know what table is queried out of 12 000 or more.) I want to make a loop on the column headers, then the query results in a web page table.

    < cfoutput >
    < cfset colHeaderNames = ArrayToList (recordset1.getColumnList ()) / >
    #colHeaderNames #.
    < / cfoutput >

    Is there a similar method or suggestions for the release of the results of the query - now that I know the column headings?

    If I understand correctly, you can do something like the code below.

  • results on the query with filter, but no results when the filter removed

    I was handed the query below and I may be missing something blinding here but if I run it I get no results

    SELECT lipqoh
    OF f41021 a, b f0006
    WHERE b.mcmcu = a.limcu AND
    b.mcstyl = "W";

    If I add the filter a.liitm = 105900 as data below is returned (although the inputs are 0 as expected at the moment, this isn't always the case)

    SELECT lipqoh
    OF f41021 a, b f0006
    WHERE b.mcmcu = a.limcu AND
    b.mcstyl = 'W '.
    a.liitm = 105900;

    the fields for each of the tables mentioned in the motion have the following features

    lipqoh number NULLABLE
    mcmcu Char(12 BYTE) NOT NULLABLE
    mcstyl tank (2 BYTE) NULLABLE
    liitm number NO NULLABLE

    Any guidance would be greatly appreciated

    Thank you for providing feedback. The only difference seems to come from the mcstyl columns.
    The following snipplet perhaps explain how this expression may be true or not true according to the data types.

    select * from dual
    where 'W ' = cast('W' as char(2 byte));
    
    DUMMY
    -----
    X
    
    select *  from dual
    where cast('W ' as varchar2(2 byte)) =  'W';
    
    no rows found
    

    This statement returns all rows?

    SELECT lipqoh
    FROM f41021 a , f0006 b
    WHERE b.mcmcu = a.limcu
    AND   b.mcstyl = 'W '; /* blank added */
    

    I expect so. I still don't understand why oracle treats differently the two queries. However I do not have an adequate control environment. Your version is simply a bit outdated (no longer supported). And I know that some of the type conversion rules had been changed between 9i and 10g.

    Published by: Sven w. on March 30, 2010 15:15

Maybe you are looking for

  • Audio device for HP Pavilion a1102n. Help, please!

    OK, I got this computer for like 3 years now. but I fell it like last week. I ordered a HP recovery disk. After I get the recovery disk, I fixed my computer. but I can't hear any sound or talk to someone about my computer. When I check my audio devic

  • Satellite 1110-Z15 HD Exchange

    HelloI need to change my hard drive but I can't open the case.What I did:* remove all screws* try to remove the keyboard but I find no way--> carefully, I opened the case up to the Middle, but I think that under the keyboard must be a screw more! So

  • Re: Satellite C660-11W - overheating problem

    Hello I have this laptop about 2 months, so the solution to this problem may not be that my laptop is old and is inside the dust...If I just surf the internet, notebook temperature is around 40-60 degrees, but if am I game it goes quickly to the top

  • Packed error Library Project: contains the compiled code

    I have tried to understand how the packed library works for LVOOP, but facing a wall with an error and do not know how to solve. (i) I did a "class 1", I then put in a library called 'library'. (II) I create a library packed and put the top-level lib

  • Como reiniciar impresion trabajos administrator

    Trato print documents are only tells me that no you can print because no is pueden ver las propiedades del servidor. El servicio local impresion trabajos Administrator without be esta ejecutando, reiniciar el o el equipo administrator. No to como to