Explanation For the query

Hi All,
Could anybody please explain me the following query.
How to display number value in words?
SQL> select sal, (to_char(to_date(sal,'j'), 'jsp')) from emp;
i know that j indicates Julion day.
i am unable to understand how to_date converts sal into date
Pls explain me in detail.
thanks in advance.
rampa

You've a decent instructor. The example is based on the SCOTT/TIGER sample schema.
Here's your code:
select sal, (to_char(to_date(sal,'j'), 'jsp')) from emp;Start inside the most nested parentheses:
SELECT TO_DATE(sal, 'J') FROM emp;Then convert that date to a string.
SELECT to_char(to_date(sal,'j'), 'jsp') FROM emp;Then add sal to the SELECT statement.
To understand each specific piece
TO_CHAR, TO_DATE, 'J', and 'JSP'go to the Oracle docs at http://tahiti.oracle.com and look them up.

Similar Messages

  • Error in SQL Query The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query

    hi Experts,
    while running SQL Query i am getting an error as
    The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query
    select  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
    T2.LineText
    from OQUT T0  INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
    QUT10 T2 ON T1.DocEntry = T2.DocEntry where T1.DocEntry='590'
    group by  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
    ,T2.LineText
    how to resolve the issue

    Dear Meghanath,
    Please use the following query, Hope your purpose will serve.
    select  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
    CAST(T2.LineText as nvarchar (MAX))[LineText]
    from OQUT T0  INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry LEFT OUTER JOIN
    QUT10 T2 ON T1.DocEntry = T2.DocEntry --where T1.DocEntry='590'
    group by  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
    ,CAST(T2.LineText as nvarchar (MAX))
    Regards,
    Amit

  • Save Query - An error occurred while creating connection strings for the query

    A workbook trying to edit and reload I get the following error "Save Query - An error occurred while creating connection strings for the query" No Power Pivot data model or anything.

    I am getting the same error when editing a Power Query in an Excel spreadsheet. It happens when I change a Group By step to do a Sum instead of Count Rows.

  • RPD - Cannot obtain number of columns for the query result :Working with MS SQL 2012 schema

    Hi All,
    I have created my warehouse in MS SQL 2012.
    For management purpose, I have created different schemas in SQL database
    In RPD, Physical layer, when i view data > I get error as
    [nQSError:16002] Cannot obtain number of columns for the query result.
    [nQSError:16001] ODBC error state : S0002 code : 208 message: [Microsoft][ODBC SQL Server Driver][SQL Server] Invalid object name 'tbl'..
    [nQSError:16001] ODBC error state : S0002 code : 208 message: [Microsoft][ODBC SQL Server Driver][SQL Server] Statements could not be prepared..
    I have already browsed : OBIEE 11g Strange ODBC Driver Error with SQL Server : Total Business Intelligence ... did not help me
    please help!!!

    Hi All,
    After all R&D it is been found that Oracle business administrator( RPD) needs default dbo schema. It doesn't accept custom schema for pulling data.
    If anybody have other views please share.!!
    Thank you

  • To know the users and the variables for the query

    Hi,
    Say I have one query and which is executed 5 times in the day n i can see this in ST03N Expert mode. Now, suppose i want to see the users who executed the query and what are the selections they gave for the query to run, is there a place to see this?
    Appreciate your time
    Sriram

    Sriram,
    You can use BW Statistics to view technical information regarding users. SAP also delivers queries that give you usage by users, just install from business content. The statistics cubes extract data from various tables including:
    RSDDSTAT
    RSDDSTATAGGR
    etc..
    You can search more, names will start with "RSDDSTAT*"
    Hope it helps,
    Farhan

  • Program name for the query generated using sq0102-03

    Hi Folks,
    How can we know the proggram  name for the query generated using sq01 and all?
    K.Kiran.

    Hi Kiran,
    U can get program name of nay transaction code by following this procedure
    after entering tcode it will direct u to the related screen then on the tool bar select system then go for status there u can find program name
    Rewards if helpfull
    Regards,
    Pavan

  • Please Help for the Query

    Please Help for the Query
    Hi frds please help me for the below query.What I want to do is to pull out the data from below table :-
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/18/2008 3IINFOTECH -4
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3
    as such :-
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3
    Here I want to find the Trend i.e either asc or desc order from the lowest indicator.
    In the above sample data -8, -4, -5, -3 out of which I want the asc order data -8, -5, -3 and exclude -4 data.Because the asc order -8, -5, -3 will not follow.
    So I want the data
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3

    SQL> CREATE TABLE BORRAME(FECHA DATE, INDICA VARCHAR2(100));
    Tabla creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/13/2008','MM/DD/YYYY'), '3IINFOTECH -8');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/18/2008','MM/DD/YYYY'), '3IINFOTECH -4');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/25/2008','MM/DD/YYYY'), '3IINFOTECH -5');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/27/2008','MM/DD/YYYY'), '3IINFOTECH -3');
    1 fila creada.
    SQL> COMMIT;
    Validación terminada.
    SQL>
    SQL> SELECT FECHA, INDICA
      2  FROM BORRAME
      3  WHERE SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) <> '4'
      4  ORDER BY SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) DESC;
    FECHA                                                                
    INDICA                                                               
    13/03/08                                                             
    3IINFOTECH -8                                                        
    25/03/08                                                             
    3IINFOTECH -5                                                        
    27/03/08                                                             
    3IINFOTECH -3                                                        
                    

  • Help for the query

    hello,
    I have a question again. The tables for the query are "Patient" and "Station".
    Station-Table:
    s_id, station
    Patient-Table:
    p_id, name, s_id, gender
    I want to know how many Patient are Male and Female for each Station. That means that the output should be:
    Station Male Female
    S1 12 10
    S2 6 4

    I supposed the values in gender are 'M' for Male and 'F' for Female
    select s.station, sum(decode(p.gender, 'M', 1, 0)) Male , sum(decode(p.gender, 'F', 1, 0)) Female
    from station s, patient p
    where s.s_id=p.s_id
    group by s.station;

  • How to  Export/Import "report for the query" to another company

    Hello,
    I do this:
    1.create query in SQL analizer
    2.copy paste into SBO query generator and save
    3.create report for the query
    Then, How to Export/Import "report for the query" to another company ?
    Thanks for your HELP.

    Look for SAP Note number 600813
    That's the note Adele means, I guess.
    <b>Edit (@13:18)</b>
    The direct link:
    https://websmp101.sap-ag.de/~sapidb/012006153200000183292003E.ITF
    ---- Replace *SOURCE* with the source database name.
    ---- Replace *DEST* with the destination database name.
    insert into [*DEST*].[dbo].[RDOC]
    select [*SOURCE*].[dbo].[RDOC].*
    from
    [*SOURCE*].[dbo].[RDOC],[*DEST*].[dbo].[cinf],[*SOURCE*].[dbo].[cinf]
    where [*DEST*].[dbo].[cinf].[lawsset]=[*SOURCE*].[dbo].[cinf].[lawsset]and [*DEST*].[dbo].[cinf].[version]=[*SOURCE*].[dbo].[cinf].[version] and [*SOURCE*].[dbo].[RDOC].[Doccode]NOT IN (SELECT Doccode from [*DEST*].[dbo].[RDOC])
    insert into [*DEST*].[dbo].[RITM]
    select [*SOURCE*].[dbo].[RITM].*
    from [*SOURCE*].[dbo].[RITM],[*DEST*].[dbo].[cinf],[*SOURCE*].[dbo].[cinf] where [*SOURCE*].[dbo].[RITM].[Doccode] NOT IN (select Doccode from [*DEST*].[dbo].[RITM])AND [*SOURCE*].[dbo].[RITM].[Doccode]IN (SELECT Doccode from [*DEST*].[dbo].[RDOC])
    Hope it helps...
    Grtz, Rowdy

  • Need Help with instr/Regexp for the query

    Hi Oracle Folks
    I am using Oracle
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    I have some student responses and the valid values are +/-/O(alphabet)/P and spaces at the end of the sting only not in the middle.
    As per my requirement the record number 2 3,4 should be listed from the query but I am getting only one (record 3).
    Can we use REG_EXP
    Please help.
    Thanks in advance.
    Rajesh
    with x as (
    SELECT '+-+-POPPPPPP   ' STUDENT_RESPONSE, 1 record_number FROM DUAL union all
    SELECT '+--AOPPPPPP++' STUDENT_RESPONSE, 2 record_number FROM DUAL union all
    SELECT '+-+-  OPPPPPP--' STUDENT_RESPONSE, 3 record_number FROM DUAL union all
    SELECT '+-+-9OPPPPPP   ' STUDENT_RESPONSE, 4 record_number FROM DUAL )
    (SELECT RECORD_NUMBER,
    TRIM(STUDENT_RESPONSE) FROM X
    WHERE
    ((INSTR (UPPER(TRIM(STUDENT_RESPONSE)),'-') =0)
    OR (INSTR (UPPER(TRIM(STUDENT_RESPONSE)),'+') =0)
    OR (INSTR (UPPER(TRIM(STUDENT_RESPONSE)),'O') =0)
    OR (INSTR (UPPER(TRIM(STUDENT_RESPONSE)),'P') =0)
    OR (INSTR (UPPER(TRIM(STUDENT_RESPONSE)),' ') !=0)
    )

    Hi, Rajesh,
    Rb2000rb65 wrote:
    Hi Oracle Folks
    I am using Oracle
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing optionsThanks for posting this (and the WITH clause for the sample data). That's very helpful.
    I have some student responses and the valid values are +/-/O(alphabet)/P and spaces at the end of the sting only not in the middle.Are you combining the responses to several qeustions in one VARCHAR2 column? It might be better to have a separate row for each question.
    As per my requirement the record number 2 3,4 should be listed from the query but I am getting only one (record 3). What exactly is your requirement? Are you trying to find the rows where student_response contains any of the forbidden characters, or where it contains a space anywhere but at the end of the string?
    Can we use REG_EXPYes, but it's easy enough, and probably more efficient, to not use regular expressions in this case:
    Here's one way:
    SELECT     record_number
    ,     student_response
    FROM     x
    WHERE     TRANSLATE ( UPPER ( RTRIM (student_response, ' '))
                , 'X+-OP'
                , 'X'
                )     IS NOT NULL
    ;That is, once you remove trailing spaces and all occurrences of '+', '-', 'O' or 'P', then only the forbidden characters are left, and you want to select the row if there are any of those.
    If you really, really want to use a regular expression:
    SELECT     record_number
    ,     student_response
    FROM     x
    WHERE     REGEXP_LIKE ( RTRIM (student_response)
                  , '[^-+OP]'          -- or '[^+OP-]', but not '[^+-OP]'.  Discuss amongst yourselves
                  , 'i'
    ;but, I repeat, this will probably be slower than the first solution, using TRANSLATE.
    Edited by: Frank Kulash on Oct 17, 2011 1:05 PM
    Edited by: Frank Kulash on Oct 17, 2011 1:41 PM
    The following is slightly simpler than TRANSLATE:
    SELECT     record_number
    ,     student_response
    FROM     x
    WHERE     RTRIM ( UPPER ( RTRIM (student_response, ' '))
               , '+-OP'
               )          IS NOT NULL
    ;

  • Performance tuning for the query

    CURSOR c_exercise_list IS
           SELECT
                  DECODE(v_mfd_mask_id ,'Y',' ',o.opt_id) opt_id,
                  DECODE(v_mfd_mask_id ,'Y',' ',o.soc_sec) soc_sec,
                  P.plan_id plan_id, E.exer_id exer_id, E.exer_num,
                  DECODE(G.sar_flag, 0, DECODE(G.plan_type, 0, '1', 1, '2', 2, '3', 3, ' ', 4,'5', 5, '6', 6, '7', 7, '8', 8, '9', '0'), ' ') option_type,
                  TO_CHAR(G.grant_dt, 'YYYYMMDD') grant_dt, TO_CHAR(E.exer_dt, 'YYYYMMDD') exer_dt,
                  E.opts_exer opts_exer,
                  E.mkt_prc   mkt_prc,
                  E.swap_prc  swap_prc,
                  E.shrs_swap shrs_swap, decode(e.exer_type,2,decode(xe.cash_partial,'Y','A','2'),TO_CHAR(E.exer_type)) exer_type,
                  E.sar_shrs  sar_shrs,
                  NVL(ROUND(((xe.sar_shrs_withld_optcost - (e.opts_exer * g.opt_prc) / e.mkt_prc) * e.mkt_prc),2),0)+e.sar_cash sar_cash,
                  NVL(f.fixed_fee1,0) fixed_fee1,
                  NVL(f.fixed_fee2,0) fixed_fee2,
                  NVL(f.fixed_fee3,0) fixed_fee3,
                  NVL(f.commission,0) commission,
                  NVL(f.sec_fee,0)    sec_fee,
                  NVL(f.fees_paid,0)  fees_paid,
                  NVL(ct.amount,0)     cash_tend,
                  E.shrs_tend  shrs_tend, G.grant_id grant_id, NVL(G.grant_cd, ' ') grant_cd,
                  NVL(xg.child_symbol,' ') child_symbol,
                  NVL(xg.opt_gain_deferred_flag,'N') defer_flag,
                  o.opt_num opt_num,
                  --XO.new_ssn,
                  DECODE(v_mfd_mask_id ,'Y',' ',xo.new_ssn) new_ssn,
                          xo.use_new_ssn
                  ,xo.tax_verification_eligible tax_verification_eligible
                  ,(SELECT TO_CHAR(MIN(settle_dt),'YYYYMMDD') FROM tb_ml_exer_upload WHERE exer_num = E.exer_num AND user_id=E.user_id AND NVL(settle_dt,TO_DATE('19000101','YYYYMMDD'))>=E.exer_dt) AS settle_dt
                  ,xe.rsu_type  AS rsu_type
                  ,xe.trfbl_det_name AS trfbl_det_name
                  ,o.user_txt1,o.user_txt2,xo.user_txt3,xo.user_txt4,xo.user_txt5,xo.user_txt6,xo.user_txt7
                  ,xo.user_txt8,xo.user_txt9,xo.user_txt10,xo.user_txt11,
                  xo.user_txt12,
                  xo.user_txt13,
                  xo.user_txt14,
                  xo.user_txt15,
                  xo.user_txt16,
                  xo.user_txt17,
                  xo.user_txt18,
                  xo.user_txt19,
                  xo.user_txt20,
                  xo.user_txt21,
                  xo.user_txt22,
                  xo.user_txt23,
                  xo.user_dt2,
                  xo.adj_dt_hire_vt_svc,
                  xo.adj_dt_hire_vt_svc_or,
                  xo.adj_dt_hire_vt_svc_or_dt,
                  xo.severance_plan_code,
                  xo.severance_begin_dt,
                  xo.severance_end_dt,
                  xo.retirement_bridging_dt
                  ,NVL(xg.pu_var_price ,0) v_pu_var_price
                  ,NVL(xe.ficamed_override,'N') v_ficmd_ovrride
                  ,NVL(xe.vest_shrs,0) v_vest_shrs
                  ,NVL(xe.client_exer_id,' ') v_client_exer_id
                  ,(CASE WHEN xg.re_tax_flag = 'Y' THEN pk_xop_reg_outbound.Fn_GetRETaxesWithheld(g.grant_num, E.exer_num, g.plan_type)
                         ELSE 'N'
                     END) re_tax_indicator -- 1.5V
                  ,xe.je_bypass_flag
                  ,xe.sar_shrs_withld_taxes   --Added for SAR july 2010 release
                  ,xe.sar_shrs_withld_optcost --Added for SAR july 2010 release
            FROM
            (SELECT exer.* FROM exercise exer WHERE NOT EXISTS (SELECT s.exer_num FROM suspense s
                WHERE s.exer_num = exer.exer_num AND s.user_id = exer.user_id AND exer.mkt_prc = 0))E,
                grantz G,  xop_grantz xg, optionee o, xop_optionee xo, feeschgd f, cashtendered ct, planz P,xop_exercise xe
            WHERE
                  E.grant_num  = G.grant_num
            AND   E.user_id    = G.user_id
            AND   E.opt_num    = o.opt_num
            AND   E.user_id    = o.user_id
            AND   (G.grant_num = xg.grant_num(+) AND G.user_id=xg.user_id(+))
            AND   (o.opt_num   = xo.opt_num(+)   AND o.user_id=xo.user_id(+))
            AND   E.plan_num = P.plan_num
            AND   E.user_id = P.user_id
            AND   E.exer_num = f.exer_num(+)
            AND   E.user_id = ct.user_id(+)
            AND   E.exer_num = ct.exer_num(+)
            AND   E.user_id = ct.user_id(+)
            AND   E.exer_num=xe.exer_num(+)
            AND   E.user_id=xe.user_id(+)
            AND   G.user_id = USER
            AND NOT EXISTS (
                        SELECT tv.exer_num
                          FROM tb_xop_tax_verification tv--,exercise ex
                         WHERE tv.exer_num = e.exer_num
                           AND tv.user_id = e.user_id
                           AND tv.user_id = v_cms_user
                           AND tv.status_flag IN (0,1,3,4, 5)) -- Not Processed
            ;how to tune the query to impropve the performance, any1 help me ..thanks in advance
    Edited by: BluShadow on 21-Feb-2013 08:14
    corrected {noformat}{noformat} tags. Please read {message:id=9360002} and learn how to post code correctly.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    i got CPU cost: 458.50 Elapsed time: 1542.90 so anything can tune to improve the performance, but there is no full table scan applied for none of the mentioned table. . and most of the columns are unique index scan takes place.. anybody can help me to find the solution
    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
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    Edited by: 956684 on Feb 22, 2013 4:09 AM

  • Filter value selection for the query execution

    Dear experts!
    I am working with an input ready query (which is over an aggregation level), and we need to display in the selection variable screen the values for a charateristic from the InfroProvider, not from the Master Data.  I don't mind how to do this, but I need to do it and for the moment it seems impossible.  I've read note 984229 and in there it says that:
    <i>'Only Values in InfoProvider'
    In this case, only values of characteristics that are posted in the InfoCube dimensions or in the DataStore are used for the input value request. This D-mode is valid for InfoCubes or the DataStore as an InfoProvider and for MultiProviders that have only InfoCubes and/or a DataStore as part providers. An exception to this is characteristics that are modeled as a Line Item Dimension. D-mode is not supported for this.</i>
    I am over an aggregation level, and thus SAP says it is not possible with the F4, but I don't mind if I have to code whatever, but I need someway to do this.......
    I need whatever type of solution......I am open to any kind of help you can provide me...... =) please!!!!
    Points will be given to helpful answers
    Thanks and kind regards.
    Cecilia

    Could you please check as per Note 1565809 and make sure the F4 mode is really M mode in each level settings?

  • The Connection String for the Query Log table is automatically encrypted.

    When I try to use the Usage Based Optimization to apply Aggregation Design to my measure group, it shows me the following
    error message.
    The connection string cannot be found. Open Microsoft SQL Server Management Studio and, in the Analysis Server Properties
    page, check the value of the Log\QueryLog\QueryLogConnectionString
    property.
    I encountered this error like two weeks ago.  At that time I just reset the connection string and every things seem
    to be fine.  A week ago, I successfully applied the Usage Based Optimization for one of my cubes.  However when I tried to apply UBO for my other cubes today, I encountered the same issue again!  I believe no one has changed the property of
    the connection string.
    Also if I query the Query Log table, I can see those latest queries made by the users.  I'm sure the queries are still
    logging into this table.
    This is really strange.  Anyone else has encountered the same issue?  Thanks.

    Hello Thomas,
    I encounterd this issue. And I am struggling trying to solve this problem. If you have resolved this issue and I guess you must've, because this post is two years old, could you kindly post how you resolved this issue?
    Thanks in advance
    Best Regards,
    Neeraja

  • Tuning tricks for the query.

    Hi Everyone,
    This is my DB version @ production.
    BANNER                                                         
    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                                       
    TNS for Linux: Version 10.2.0.4.0 - Production                 
    NLSRTL Version 10.2.0.4.0 - Production
    We have a query, which is running more than 3 mins at production as we have 40 millions active records for almost 2 million active patients.
    So clearly the active record percentage is 98. We have indexes on all required field values last date of computed statistics was 1st Jan 2014.
    But we are unable achieve the performance from the query. If we are making it tightly coupled with parent - child relationship, then it's generating cost
    value more than 2 million. So we tried some sub-queries but still the cost value is in million. Please do have a look at the query and suggest me something where
    I can meliorate this. We can't go change DB structure straight away right now. So what needs to be done here? Please suggest something.
    Query:-
    select distinct
            (select p.last_name || ', ' || p.first_name
              from patient p
             where p.patient_id = loc.patient_id) as patient_name,
           (select p.external_id
              from patient p
             where p.patient_id = loc.patient_id) as external_id,
           (select p.spectra_mrn
            from patient p
            where p.patient_id = loc.patient_id) as spectra_mrn,
           ord.requisition_number as requisition_number,
           f.facility_name as facility_name,
           f.facility_id as facility_id,
           (select fad.account_type as modality
              from patient p,
                   patient_facility_modality pfm,
                   facility_account_modality fam,
                   facility_account_detail fad
             where p.patient_id = pfm.patient_id
               and pfm.facility_account_modality_id =
                                                  fam.facility_account_modality_id
               and fam.facility_account_detail_id = fad.facility_account_detail_id
               and p.patient_id = loc.patient_id
               and pfm.facility_id = loc.facility_id) as modality,
           (select fad.account_number as account_number
              from patient p,
                   patient_facility_modality pfm,
                   facility_account_modality fam,
                   facility_account_detail fad
             where p.patient_id = pfm.patient_id
               and pfm.facility_account_modality_id =
                                                  fam.facility_account_modality_id
               and fam.facility_account_detail_id = fad.facility_account_detail_id
               and p.patient_id = loc.patient_id
               and pfm.facility_id = loc.facility_id) as account_number,
           (select fad.hlab_num as hlab_num
              from patient p,
                   patient_facility_modality pfm,
                   facility_account_modality fam,
                   facility_account_detail fad
             where p.patient_id = pfm.patient_id
               and pfm.facility_account_modality_id =
                                                  fam.facility_account_modality_id
               and fam.facility_account_detail_id = fad.facility_account_detail_id
               and p.patient_id = loc.patient_id
               and pfm.facility_id = loc.facility_id) as hlab_num,
           loc.order_draw_dt as draw_dt,
           c.corporation_name as corporation_name,
           c.corporation_acronym as acronym,
           loc.patient_id,
           loct.test_id
      from lab_order_occ loc,
           lab_order_occ_test loct,
           facility f,
           corporation c,
           order_requisition_header ord
    where loc.lab_order_occ_id = loct.lab_order_occ_id
       and loc.facility_id = f.facility_id
       and f.corporation_id = c.corporation_id
       and ord.patient_id = loc.patient_id
       and ord.facility_id = loc.facility_id
       and ord.draw_dt = loc.order_draw_dt
       and loc.order_draw_dt between trunc(sysdate) - 7 and trunc(sysdate)
       and loc.status = 'A'
       and loc.msg_sent_to_lab_yn = 'Y'
       and loct.status <> 'R'
       and loct.test_id in (
                       select test_id
                         from test_required
                        where required_test_code in (
                                                     select test_code
                                                       from interface_adt_aoe_master))
        and              
          (select count(*) from interface_adt_aoe_master where source_system = corporation_acronym
          and test_code = (select test_code from test where test_id=(select aoe_test_id from lab_order_occ_test_aoe where lab_order_occ_test_id= loct.lab_order_occ_test_id)))
          !=
          (select count(*) from EMR_ADTAOE_DTL where patient_id = loc.patient_id and facility_id = loc.facility_id and (
              (test_id = (select aoe_test_id from lab_order_occ_test_aoe where lab_order_occ_test_id= loct.lab_order_occ_test_id) and trunc(draw_date) like trunc(loc.order_draw_dt))
                or (test_id = (select aoe_test_id from lab_order_occ_test_aoe where LAB_ORDER_OCC_TEST_ID= loct.lab_order_occ_test_id) and trunc(draw_date)= trunc(to_date('12-31-2999','mm-dd-yyyy')))
            and STATUS = 'Y'  and ANSWER is not null)
    Execution Plan @ QAT environment
    explain plan succeeded.
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                          
    Plan hash value: 2140167730                                                                                                                                                                                                                                                                                
    | Id  | Operation                             | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                                                                                                                   
    |   0 | SELECT STATEMENT                      |                                |   399 | 59451 |  6293   (1)| 00:01:16 |                                                                                                                                                                                   
    |   1 |  TABLE ACCESS BY INDEX ROWID          | PATIENT                        |     1 |    21 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |*  2 |   INDEX UNIQUE SCAN                   | PATIENT_PK                     |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |   3 |  TABLE ACCESS BY INDEX ROWID          | PATIENT                        |     1 |    11 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |*  4 |   INDEX UNIQUE SCAN                   | PATIENT_PK                     |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |   5 |  TABLE ACCESS BY INDEX ROWID          | PATIENT                        |     1 |    12 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |*  6 |   INDEX UNIQUE SCAN                   | PATIENT_PK                     |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |   7 |  NESTED LOOPS                         |                                |     1 |    43 |     5   (0)| 00:00:01 |                                                                                                                                                                                   
    |   8 |   NESTED LOOPS                        |                                |     1 |    29 |     4   (0)| 00:00:01 |                                                                                                                                                                                   
    |   9 |    NESTED LOOPS                       |                                |     1 |    19 |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 10 |     INDEX UNIQUE SCAN                 | PATIENT_PK                     |     1 |     5 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 11 |     INDEX RANGE SCAN                  | PATIENT_FACILITY_MOD_IX_01     |     1 |    14 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |  12 |    TABLE ACCESS BY INDEX ROWID        | FACILITY_ACCOUNT_MODALITY      |     1 |    10 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 13 |     INDEX UNIQUE SCAN                 | FACILITY_ACCOUNT_MODALITY_PK   |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                                                   
    |  14 |   TABLE ACCESS BY INDEX ROWID         | FACILITY_ACCOUNT_DETAIL        |     1 |    14 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 15 |    INDEX UNIQUE SCAN                  | FACILITY_ACCOUNT_DETAIL_PK     |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                                                   
    |  16 |  NESTED LOOPS                         |                                |     1 |    40 |     5   (0)| 00:00:01 |                                                                                                                                                                                   
    |  17 |   NESTED LOOPS                        |                                |     1 |    29 |     4   (0)| 00:00:01 |                                                                                                                                                                                   
    |  18 |    NESTED LOOPS                       |                                |     1 |    19 |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 19 |     INDEX UNIQUE SCAN                 | PATIENT_PK                     |     1 |     5 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 20 |     INDEX RANGE SCAN                  | PATIENT_FACILITY_MOD_IX_01     |     1 |    14 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |  21 |    TABLE ACCESS BY INDEX ROWID        | FACILITY_ACCOUNT_MODALITY      |     1 |    10 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 22 |     INDEX UNIQUE SCAN                 | FACILITY_ACCOUNT_MODALITY_PK   |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                                                   
    |  23 |   TABLE ACCESS BY INDEX ROWID         | FACILITY_ACCOUNT_DETAIL        |     1 |    11 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 24 |    INDEX UNIQUE SCAN                  | FACILITY_ACCOUNT_DETAIL_PK     |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                                                   
    |  25 |  NESTED LOOPS                         |                                |     1 |    42 |     5   (0)| 00:00:01 |                                                                                                                                                                                   
    |  26 |   NESTED LOOPS                        |                                |     1 |    29 |     4   (0)| 00:00:01 |                                                                                                                                                                                   
    |  27 |    NESTED LOOPS                       |                                |     1 |    19 |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 28 |     INDEX UNIQUE SCAN                 | PATIENT_PK                     |     1 |     5 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 29 |     INDEX RANGE SCAN                  | PATIENT_FACILITY_MOD_IX_01     |     1 |    14 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |  30 |    TABLE ACCESS BY INDEX ROWID        | FACILITY_ACCOUNT_MODALITY      |     1 |    10 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 31 |     INDEX UNIQUE SCAN                 | FACILITY_ACCOUNT_MODALITY_PK   |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                                                   
    |  32 |   TABLE ACCESS BY INDEX ROWID         | FACILITY_ACCOUNT_DETAIL        |     1 |    13 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 33 |    INDEX UNIQUE SCAN                  | FACILITY_ACCOUNT_DETAIL_PK     |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                                                   
    |  34 |  HASH UNIQUE                          |                                |   399 | 59451 |  6293   (1)| 00:01:16 |                                                                                                                                                                                   
    |* 35 |   FILTER                              |                                |       |       |            |          |                                                                                                                                                                                   
    |* 36 |    FILTER                             |                                |       |       |            |          |                                                                                                                                                                                   
    |* 37 |     HASH JOIN                         |                                |   399 | 59451 |  6285   (1)| 00:01:16 |                                                                                                                                                                                   
    |  38 |      TABLE ACCESS FULL                | CORPORATION                    |   291 | 11640 |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    |  39 |      NESTED LOOPS                     |                                |   399 | 43491 |  6282   (1)| 00:01:16 |                                                                                                                                                                                   
    |* 40 |       HASH JOIN                       |                                |  2113 |   216K|  6281   (1)| 00:01:16 |                                                                                                                                                                                   
    |  41 |        TABLE ACCESS FULL              | TEST_REQUIRED                  |  1184 | 10656 |     5   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 42 |        TABLE ACCESS BY INDEX ROWID    | LAB_ORDER_OCC_TEST             |     8 |   144 |     5   (0)| 00:00:01 |                                                                                                                                                                                   
    |  43 |         NESTED LOOPS                  |                                |  1345 |   126K|  6276   (1)| 00:01:16 |                                                                                                                                                                                   
    |* 44 |          HASH JOIN                    |                                |   170 | 13260 |  5425   (1)| 00:01:06 |                                                                                                                                                                                   
    |* 45 |           HASH JOIN                   |                                |   170 |  8670 |  5403   (1)| 00:01:05 |                                                                                                                                                                                   
    |* 46 |            TABLE ACCESS BY INDEX ROWID| LAB_ORDER_OCC                  | 12775 |   336K|   569   (1)| 00:00:07 |                                                                                                                                                                                   
    |* 47 |             INDEX SKIP SCAN           | LAB_ORDER_OCC_IX_07            |  2218 |       |    13   (8)| 00:00:01 |                                                                                                                                                                                   
    |* 48 |            TABLE ACCESS BY INDEX ROWID| ORDER_REQUISITION_HEADER       | 56952 |  1334K|  4833   (1)| 00:00:58 |                                                                                                                                                                                   
    |* 49 |             INDEX SKIP SCAN           | ORDER_REQUISITION_HEADER_IX_04 |  4905 |       |  1707   (1)| 00:00:21 |                                                                                                                                                                                   
    |  50 |           TABLE ACCESS FULL           | FACILITY                       |  4252 |   112K|    22   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 51 |          INDEX RANGE SCAN             | LAB_ORDER_OCC_TEST_IX_01       |     8 |       |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 52 |       INDEX RANGE SCAN                | INTERFACE_ADT_AOE_MASTER_IX_01 |     1 |     4 |     0   (0)| 00:00:01 |                                                                                                                                                                                   
    |  53 |    SORT AGGREGATE                     |                                |     1 |    12 |            |          |                                                                                                                                                                                   
    |* 54 |     TABLE ACCESS BY INDEX ROWID       | INTERFACE_ADT_AOE_MASTER       |     1 |    12 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 55 |      INDEX RANGE SCAN                 | INTERFACE_ADT_AOE_MASTER_IX_01 |     4 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |  56 |       TABLE ACCESS BY INDEX ROWID     | TEST                           |     1 |     9 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 57 |        INDEX UNIQUE SCAN              | TEST_PK                        |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 58 |         INDEX RANGE SCAN              | LAB_ORDER_OCC_TEST_AOE_PK      |     1 |    10 |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    |  59 |      SORT AGGREGATE                   |                                |     1 |    29 |            |          |                                                                                                                                                                                   
    |* 60 |       FILTER                          |                                |       |       |            |          |                                                                                                                                                                                   
    |* 61 |        TABLE ACCESS BY INDEX ROWID    | EMR_ADTAOE_DTL                 |     1 |    29 |    30   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 62 |         INDEX RANGE SCAN              | EMR_ADTAOE_DTL_IX_01           |   174 |       |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 63 |        INDEX RANGE SCAN               | LAB_ORDER_OCC_TEST_AOE_PK      |     1 |    10 |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 64 |         INDEX RANGE SCAN              | LAB_ORDER_OCC_TEST_AOE_PK      |     1 |    10 |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    Query Block Name / Object Alias (identified by operation id):                                                                                                                                                                                                                                              
       1 - SEL$2        / P@SEL$2                                                                                                                                                                                                                                                                              
       2 - SEL$2        / P@SEL$2                                                                                                                                                                                                                                                                              
       3 - SEL$3        / P@SEL$3                                                                                                                                                                                                                                                                              
       4 - SEL$3        / P@SEL$3                                                                                                                                                                                                                                                                              
       5 - SEL$4        / P@SEL$4                                                                                                                                                                                                                                                                              
       6 - SEL$4        / P@SEL$4                                                                                                                                                                                                                                                                              
       7 - SEL$5                                                                                                                                                                                                                                                                                               
      10 - SEL$5        / P@SEL$5                                                                                                                                                                                                                                                                              
      11 - SEL$5        / PFM@SEL$5                                                                                                                                                                                                                                                                            
      12 - SEL$5        / FAM@SEL$5                                                                                                                                                                                                                                                                            
      13 - SEL$5        / FAM@SEL$5                                                                                                                                                                                                                                                                            
      14 - SEL$5        / FAD@SEL$5                                                                                                                                                                                                                                                                            
      15 - SEL$5        / FAD@SEL$5                                                                                                                                                                                                                                                                            
      16 - SEL$6                                                                                                                                                                                                                                                                                               
      19 - SEL$6        / P@SEL$6                                                                                                                                                                                                                                                                              
      20 - SEL$6        / PFM@SEL$6                                                                                                                                                                                                                                                                            
      21 - SEL$6        / FAM@SEL$6                                                                                                                                                                                                                                                                            
      22 - SEL$6        / FAM@SEL$6                                                                                                                                                                                                                                                                            
      23 - SEL$6        / FAD@SEL$6                                                                                                                                                                                                                                                                            
      24 - SEL$6        / FAD@SEL$6                                                                                                                                                                                                                                                                            
      25 - SEL$7                                                                                                                                                                                                                                                                                               
      28 - SEL$7        / P@SEL$7                                                                                                                                                                                                                                                                              
      29 - SEL$7        / PFM@SEL$7                                                                                                                                                                                                                                                                            
      30 - SEL$7        / FAM@SEL$7                                                                                                                                                                                                                                                                            
      31 - SEL$7        / FAM@SEL$7                                                                                                                                                                                                                                                                            
      32 - SEL$7        / FAD@SEL$7                                                                                                                                                                                                                                                                            
      33 - SEL$7        / FAD@SEL$7                                                                                                                                                                                                                                                                            
      34 - SEL$AA3B83ED                                                                                                                                                                                                                                                                                        
      38 - SEL$AA3B83ED / C@SEL$1                                                                                                                                                                                                                                                                              
      41 - SEL$AA3B83ED / TEST_REQUIRED@SEL$8                                                                                                                                                                                                                                                                  
      42 - SEL$AA3B83ED / LOCT@SEL$1                                                                                    

    Hi Karthick,
    Thanks for the response. The suggestion is really good. But we have some tables accessed like "lab_order_occ" which size is more than 8GB also having no partitions. If I'll ask for altering DB structure, this will be finalized not less than 6 months. Please do have a look at the plan now. It's generating more cost.
    explain plan succeeded.
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                         
    Plan hash value: 2523654849                                                                                                                                                                                                                                                                               
    | Id  | Operation                               | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                                                                                                                
    |   0 | SELECT STATEMENT                        |                                |  1057 |   293K| 25324   (2)| 00:05:04 |                                                                                                                                                                                
    |*  1 |  FILTER                                 |                                |       |       |            |          |                                                                                                                                                                                
    |*  2 |   HASH JOIN RIGHT SEMI                  |                                |  1057 |   293K| 25317   (2)| 00:05:04 |                                                                                                                                                                                
    |   3 |    VIEW                                 | VW_NSO_1                       |   224 |  2912 |     5   (0)| 00:00:01 |                                                                                                                                                                                
    |*  4 |     FILTER                              |                                |       |       |            |          |                                                                                                                                                                                
    |   5 |      NESTED LOOPS                       |                                |   224 |  2912 |     5   (0)| 00:00:01 |                                                                                                                                                                                
    |   6 |       TABLE ACCESS FULL                 | TEST_REQUIRED                  |  1184 | 10656 |     5   (0)| 00:00:01 |                                                                                                                                                                                
    |*  7 |       INDEX RANGE SCAN                  | INTERFACE_ADT_AOE_MASTER_IX_01 |     1 |     4 |     0   (0)| 00:00:01 |                                                                                                                                                                                
    |*  8 |    TABLE ACCESS BY INDEX ROWID          | LAB_ORDER_OCC_TEST             |     8 |   144 |     5   (0)| 00:00:01 |                                                                                                                                                                                
    |   9 |     NESTED LOOPS                        |                                |  1345 |   355K| 25311   (2)| 00:05:04 |                                                                                                                                                                                
    |* 10 |      HASH JOIN                          |                                |   170 | 43010 | 24460   (2)| 00:04:54 |                                                                                                                                                                                
    |  11 |       TABLE ACCESS FULL                 | CORPORATION                    |   291 | 11640 |     3   (0)| 00:00:01 |                                                                                                                                                                                
    |* 12 |       HASH JOIN                         |                                |   170 | 36210 | 24457   (2)| 00:04:54 |                                                                                                                                                                                
    |  13 |        NESTED LOOPS OUTER               |                                |   170 | 31620 | 24434   (2)| 00:04:54 |                                                                                                                                                                                
    |* 14 |         HASH JOIN                       |                                |   170 | 14960 |  5403   (1)| 00:01:05 |                                                                                                                                                                                
    |* 15 |          TABLE ACCESS BY INDEX ROWID    | LAB_ORDER_OCC                  | 12775 |   598K|   569   (1)| 00:00:07 |                                                                                                                                                                                
    |* 16 |           INDEX SKIP SCAN               | LAB_ORDER_OCC_IX_07            |  2218 |       |    13   (8)| 00:00:01 |                                                                                                                                                                                
    |* 17 |          TABLE ACCESS BY INDEX ROWID    | ORDER_REQUISITION_HEADER       | 56952 |  2224K|  4833   (1)| 00:00:58 |                                                                                                                                                                                
    |* 18 |           INDEX SKIP SCAN               | ORDER_REQUISITION_HEADER_IX_04 |  4905 |       |  1707   (1)| 00:00:21 |                                                                                                                                                                                
    |  19 |         VIEW PUSHED PREDICATE           |                                |     1 |    98 |   112   (2)| 00:00:02 |                                                                                                                                                                                
    |* 20 |          HASH JOIN                      |                                |    93 |  8835 |   112   (2)| 00:00:02 |                                                                                                                                                                                
    |* 21 |           HASH JOIN                     |                                |    93 |  6231 |    56   (2)| 00:00:01 |                                                                                                                                                                                
    |* 22 |            HASH JOIN                    |                                |    93 |  5301 |    48   (3)| 00:00:01 |                                                                                                                                                                                
    |  23 |             NESTED LOOPS                |                                |    68 |  2924 |    44   (0)| 00:00:01 |                                                                                                                                                                                
    |  24 |              TABLE ACCESS BY INDEX ROWID| PATIENT                        |     1 |    34 |     2   (0)| 00:00:01 |                                                                                                                                                                                
    |* 25 |               INDEX UNIQUE SCAN         | PATIENT_PK                     |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                
    |  26 |              TABLE ACCESS BY INDEX ROWID| LAB_ORDER_OCC                  |    68 |   612 |    42   (0)| 00:00:01 |                                                                                                                                                                                
    |* 27 |               INDEX RANGE SCAN          | LAB_ORDER_OCC_IX_02            |    53 |       |     2   (0)| 00:00:01 |                                                                                                                                                                                
    |* 28 |             INDEX RANGE SCAN            | PATIENT_FACILITY_MOD_IX_01     |   111 |  1554 |     3   (0)| 00:00:01 |                                                                                                                                                                                
    |  29 |            TABLE ACCESS FULL            | FACILITY_ACCOUNT_MODALITY      |  9159 | 91590 |     8   (0)| 00:00:01 |                                                                                                                                                                                
    |  30 |           TABLE ACCESS FULL             | FACILITY_ACCOUNT_DETAIL        |  7266 |   198K|    55   (0)| 00:00:01 |                                                                                                                                                                                
    |  31 |        TABLE ACCESS FULL                | FACILITY                       |  4252 |   112K|    22   (0)| 00:00:01 |                                                                                                                                                                                
    |* 32 |      INDEX RANGE SCAN                   | LAB_ORDER_OCC_TEST_IX_01       |     8 |       |     2   (0)| 00:00:01 |                                                                                                                                                                                
    |  33 |   SORT AGGREGATE                        |                                |     1 |    12 |            |          |                                                                                                                                                                                
    |* 34 |    TABLE ACCESS BY INDEX ROWID          | INTERFACE_ADT_AOE_MASTER       |     1 |    12 |     2   (0)| 00:00:01 |                                                                                                                                                                                
    |* 35 |     INDEX RANGE SCAN                    | INTERFACE_ADT_AOE_MASTER_IX_01 |     4 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                
    |  36 |      TABLE ACCESS BY INDEX ROWID        | TEST                           |     1 |     9 |     2   (0)| 00:00:01 |                                                                                                                                                                                
    |* 37 |       INDEX UNIQUE SCAN                 | TEST_PK                        |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                
    |* 38 |        INDEX RANGE SCAN                 | LAB_ORDER_OCC_TEST_AOE_PK      |     1 |    10 |     3   (0)| 00:00:01 |                                                                                                                                                                                
    |  39 |     SORT AGGREGATE                      |                                |     1 |    29 |            |          |                                                                                                                                                                                
    |* 40 |      FILTER                             |                                |       |       |            |          |                                                                                                                                                                                
    |* 41 |       TABLE ACCESS BY INDEX ROWID       | EMR_ADTAOE_DTL                 |     1 |    29 |    30   (0)| 00:00:01 |                                                                                                                                                                                
    |* 42 |        INDEX RANGE SCAN                 | EMR_ADTAOE_DTL_IX_01           |   174 |       |     3   (0)| 00:00:01 |                                                                                                                                                                                
    |* 43 |       INDEX RANGE SCAN                  | LAB_ORDER_OCC_TEST_AOE_PK      |     1 |    10 |     3   (0)| 00:00:01 |                                                                                                                                                                                
    Query Block Name / Object Alias (identified by operation id):                                                                                                                                                                                                                                             
       1 - SEL$19EEE7EA                                                                                                                                                                                                                                                                                       
       3 - SEL$9DB3EFF9 / VW_NSO_1@SEL$19EEE7EA                                                                                                                                                                                                                                                               
       4 - SEL$9DB3EFF9                                                                                                                                                                                                                                                                                       
       6 - SEL$9DB3EFF9 / TEST_REQUIRED@SEL$3                                                                                                                                                                                                                                                                 
       7 - SEL$9DB3EFF9 / INTERFACE_ADT_AOE_MASTER@SEL$4                                                                                                                                                                                                                                                      
       8 - SEL$19EEE7EA / LOCT@SEL$1                                                                                                                                                                                                                                                                          
      11 - SEL$19EEE7EA / C@SEL$1                                                                                                                                                                                                                                                                             
      15 - SEL$19EEE7EA / LOC@SEL$1                                                                                                                                                                                                                                                                           
      16 - SEL$19EEE7EA / LOC@SEL$1                                                                                                                                                                                                                                                                           
      17 - SEL$19EEE7EA / ORD@SEL$1                                                                                                                                                                                                                                                                           
      18 - SEL$19EEE7EA / ORD@SEL$1                                                                                                                                                                                                                                                                           
      19 - SEL$639F1A6F / P@SEL$1                                                                                                                                                                                                                                                                             
      20 - SEL$639F1A6F                                                                                                                                                                                                                                                                                       
      24 - SEL$639F1A6F / P@SEL$2                                                                                                                                                                                                                                                                             
      25 - SEL$639F1A6F / P@SEL$2                                                                                                                                                                                                                                                                             
      26 - SEL$639F1A6F / LOC@SEL$2                                                                                                                                                                                                                                                                           
      27 - SEL$639F1A6F / LOC@SEL$2                                                                                                                                                                                                                                                                           
      28 - SEL$639F1A6F / PFM@SEL$2                                                                                                                                                                                                                                                                           
      29 - SEL$639F1A6F / FAM@SEL$2                                                                                                                                                                                                                                                                           
      30 - SEL$639F1A6F / FAD@SEL$2                                                                                                                                                                                                                                                                           
      31 - SEL$19EEE7EA / F@SEL$1                                                                                                                                                                                                                                                                             
      32 - SEL$19EEE7EA / LOCT@SEL$1                                                                                                                                                                                                                                                                          
      33 - SEL$5                                                                                                                                                                                                                                                                                              
      34 - SEL$5        / INTERFACE_ADT_AOE_MASTER@SEL$5                                                                                                                                                                                                                                                      
      35 - SEL$5        / INTERFACE_ADT_AOE_MASTER@SEL$5                                                                                                                                                                                                                                                      
      36 - SEL$6        / TEST@SEL$6                                                                                                                                                                                                                                                                          
      37 - SEL$6        / TEST@SEL$6                                                                                                                                                                                                                                                                          
      38 - SEL$7        / LAB_ORDER_OCC_TEST_AOE@SEL$7                                                                                                                                                                                                                                                        
      39 - SEL$8                                                                                                                                                                                                                                                                                              
      41 - SEL$8        / EMR_ADTAOE_DTL@SEL$8                                                                                                                                                                                                                                                                
      42 - SEL$8        / EMR_ADTAOE_DTL@SEL$8                                                                                                                                                                                                                                                                
      43 - SEL$9        / LAB_ORDER_OCC_TEST_AOE@SEL$9                                                                                                                                                                                                                                                        
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                       
       1 - filter( (SELECT /*+ */ COUNT(*) FROM "KORUS2XPROD_OWN"."INTERFACE_ADT_AOE_MASTER"                                                                                                                                                                                                                  
                  "INTERFACE_ADT_AOE_MASTER" WHERE "TEST_CODE"= (SELECT /*+ */ "TEST_CODE" FROM "KORUS2XPROD_OWN"."TEST" "TEST"                                                                                                                                                                               
                  WHERE "TEST_ID"= (SELECT /*+ */ "AOE_TEST_ID" FROM "KORUS2XPROD_OWN"."LAB_ORDER_OCC_TEST_AOE"                                                                                                                                                                                               
                  "LAB_ORDER_OCC_TEST_AOE" WHERE "LAB_ORDER_OCC_TEST_ID"=:B1)) AND "SOURCE_SYSTEM"=:B2)<> (SELECT /*+ */ COUNT(*)                                                                                                                                                                             
                  FROM "KORUS2XPROD_OWN"."EMR_ADTAOE_DTL" "EMR_ADTAOE_DTL" WHERE "TEST_ID"= (SELECT /*+ */ "AOE_TEST_ID" FROM                                                                                                                                                                                 
                  "KORUS2XPROD_OWN"."LAB_ORDER_OCC_TEST_AOE" "LAB_ORDER_OCC_TEST_AOE" WHERE "LAB_ORDER_OCC_TEST_ID"=:B3) AND                                                                                                                                                                                  
                  "PATIENT_ID"=:B4 AND "FACILITY_ID"=:B5 AND "STATUS"='Y' AND (TO_CHAR(TRUNC(INTERNAL_FUNCTION("DRAW_DATE"))) LIKE                                                                                                                                                                            
                  TO_CHAR(TRUNC(:B6)) OR TRUNC(INTERNAL_FUNCTION("DRAW_DATE"))=TO_DATE(' 2999-12-31 00:00:00', 'syyyy-mm-dd                                                                                                                                                                                   
                  hh24:mi:ss')) AND "ANSWER" IS NOT NULL))                                                                                                                                                                                                                                                    
       2 - access("LOCT"."TEST_ID"="$nso_col_1")                                                                                                                                                                                                                                                              
       4 - filter(TRUNC(SYSDATE@!)-7<=TRUNC(SYSDATE@!))                                                                                                                                                                                                                                                       
       7 - access("REQUIRED_TEST_CODE"="TEST_CODE")                                                                                                                                                                                                                                                           
       8 - filter("LOCT"."STATUS"<>'R')                                                                                                                                                                                                                                                                       
      10 - access("F"."CORPORATION_ID"="C"."CORPORATION_ID")                                                                                                                                                                                                                                                  
      12 - access("LOC"."FACILITY_ID"="F"."FACILITY_ID")                                                                                                                                                                                                                                                      
      14 - access("ORD"."PATIENT_ID"="LOC"."PATIENT_ID" AND "ORD"."FACILITY_ID"="LOC"."FACILITY_ID" AND                                                                                                                                                                                                       
                  "ORD"."DRAW_DT"="LOC"."ORDER_DRAW_DT")                                                                                                                                                                                                                                                      
      15 - filter("LOC"."PATIENT_ID" IS NOT NULL AND "LOC"."MSG_SENT_TO_LAB_YN"='Y')                                                                                                                                                                                                                          
      16 - access("LOC"."ORDER_DRAW_DT">=TRUNC(SYSDATE@!)-7 AND "LOC"."STATUS"='A' AND                                                                                                                                                                                                                        
                  "LOC"."ORDER_DRAW_DT"<=TRUNC(SYSDATE@!))                                                                                                                                                                                                                                                    
           filter("LOC"."STATUS"='A')                                                                                                                                                                                                                                                                         
      17 - filter("ORD"."PATIENT_ID" IS NOT NULL)                                                                                                                                                                                                                                                             
      18 - access("ORD"."DRAW_DT">=TRUNC(SYSDATE@!)-7 AND "ORD"."DRAW_DT"<=TRUNC(SYSDATE@!))                                                                                                                                                                                                                  
           filter("ORD"."DRAW_DT">=TRUNC(SYSDATE@!)-7 AND "ORD"."DRAW_DT"<=TRUNC(SYSDATE@!))                                                                                                                                                                                                                  
      20 - access("FAM"."FACILITY_ACCOUNT_DETAIL_ID"="FAD"."FACILITY_ACCOUNT_DETAIL_ID")                                                                                                                                                                                                                      
      21 - access("PFM"."FACILITY_ACCOUNT_MODALITY_ID"="FAM"."FACILITY_ACCOUNT_MODALITY_ID")                                                                                                                                                                                                                  
      22 - access("PFM"."FACILITY_ID"="LOC"."FACILITY_ID")                                                                                                                                                                                                                                                    
      25 - access("P"."PATIENT_ID"="LOC"."PATIENT_ID")                                                                                                                                                                                                                                                        
      27 - access("LOC"."PATIENT_ID"="LOC"."PATIENT_ID")           

  • Need help for the query columns to rows

    Hi everyone,
    I have two tables TABLE1 and TABLE2; TABLE1 is Master table,TABLE2 is child table.
    The key for TABLE1 is C1 column
    The key for TABLE2 is C1,C_MONTH Columns
    The sample data is as follows
    TABLE1
    ======
    C1 C2
    1 A
    2 B
    3 C
    4 D
    TABLE2
    ======
    C1 C_MONTH C3
    1 JAN AAA
    1 FEB BBB
    1 MAR CCC
    1 APR DDD
    2 JAN ZZZ
    2 FEB YYY
    2 MAR XXX
    2 APR UUU
    I want to display the data as follows
    1 A JAN AAA FEB BBB MAR CCC APR DDD
    2 B JAN ZZZ FEB YYY MAR XXX APR UUU
    Can any one help me how to write this query?
    Thanks in advance

    [email protected] wrote:
    Thanks for the update
    but I want the out put as column values rather than one column as follows
    C1 C2 J_MONTH J_VALUE F_MONTH F_VALUE M_MONTH M_VALUE A_MONTH A_VALUE
    1 A JAN AAA FEB BBB MAR CCC APR DDD
    2 B JAN ZZZ FEB YYY MAR XXX APR UUUThis is a standard pivot.
    In 10g or below you can do something like...
    SQL> ed
    Wrote file afiedt.buf
      1  with table1 as (
      2                  select 1 c1, 'A' c2 from dual union all
      3                  select 2, 'B' from dual union all
      4                  select 3, 'C' from dual union all
      5                  select 4, 'D' from dual
      6                 ),
      7       table2 as (
      8                  select 1 c1, 'JAN' C_MONTH,'AAA' C3 from dual union all
      9                  select 1,'FEB','BBB' C3 from dual union all
    10                  select 1,'MAR','CCC' C3 from dual union all
    11                  select 1,'APR','DDD' C3 from dual union all
    12                  select 2,'JAN','ZZZ' C3 from dual union all
    13                  select 2,'FEB','YYY' C3 from dual union all
    14                  select 2,'MAR','XXX' C3 from dual union all
    15                  select 2,'APR','UUU' C3 from dual
    16                 )
    17  -- end of test data
    18  select table1.c1, table1.c2
    19        ,max(decode(c_month, 'JAN', c_month)) as jan_month
    20        ,max(decode(c_month, 'JAN', c3)) as jan_value
    21        ,max(decode(c_month, 'FEB', c_month)) as feb_month
    22        ,max(decode(c_month, 'FEB', c3)) as feb_value
    23        ,max(decode(c_month, 'MAR', c_month)) as mar_month
    24        ,max(decode(c_month, 'MAR', c3)) as mar_value
    25        ,max(decode(c_month, 'APR', c_month)) as apr_month
    26        ,max(decode(c_month, 'APR', c3)) as apr_value
    27  from table1 join table2 on (table1.c1 = table2.c1)
    28* group by table1.c1, table1.c2
    SQL> /
            C1 C JAN JAN FEB FEB MAR MAR APR APR
             1 A JAN AAA FEB BBB MAR CCC APR DDD
             2 B JAN ZZZ FEB YYY MAR XXX APR UUU
    SQL>From 11g upwards you can use the new PIVOT keyword.

Maybe you are looking for

  • What about my old music?

    Hello, I picked something up from a friend that made me really curious..I don't know if I understood him right. I think he said, that if u already bought a song on iTunes then there is a way to "reload" it without having to buy again. Is that correct

  • Failed (bad environment) Deploying MSU Packages on SCCM 2012 R2

    Hi All, I am trying to deploy the following updates to a test collection of computers running Windows 8.1 Enterprise: Windows8.1-KB2919442-x64.msu Windows8.1-KB2919355-x64.msu  (These are the Windows 8.1 Interface Updates, the first file is a pre-req

  • Problem with two audio tracks

    When I add music to a2 the video, audio and music play fine in editing program but when I export media the complete audio is lost I only see visual?

  • Belle navigation 3.09 guidance over bluetooth

    Navigation guidance on belle works, when music is on! Music volume (tom tom bluetooth) can be adjusted at bluetooth device and the navigation guidance on the phone. On N9 and N97 navigation guidance worked normally with bluetooth. Nokia developers, p

  • Blackberry 8330 Video Format

    I took a video with my BB8330 and transferred the file to my laptop.  The file extension is not recognized by the computer (VID 00003.3GP).  How do I get it to play on my computer?  Thank you