Query- Alternative way

Hi All,
Below is the query used to retrieve records based on organization and responsibility parameters
select * from WIP_DISCRETE_JOBS where ORGANIZATION_ID = :ORG_ID
and :ORG_ID !=-1
union all
select * from WIP_DISCRETE_JOBS where ORGANIZATION_ID in
select ORGANIZATION_ID from HR_ALL_ORGANIZATION_UNITS
where ORGANIZATION_ID in (select ORGANIZATION_ID
from MTL_PARAMETERS
and not exists (
select 1
from ORG_ACCESS AB,
HR_ALL_ORGANIZATION_UNITS B
where AB.ORGANIZATION_ID = B.ORGANIZATION_ID
and AB.RESPONSIBILITY_ID = :P_RESP_ID
union
select AB.ORGANIZATION_ID
from ORG_ACCESS AB, HR_ALL_ORGANIZATION_UNITS B
where AB.ORGANIZATION_ID = B.ORGANIZATION_ID
and AB.RESPONSIBILITY_ID = :P_RESP_ID
AND :ORG_ID = -1
Here user can enter specific ORG_ID to get the results. Also user has provision to get all the organization belonging to particular P_RESP_ID parameter. When user pass ORG_ID = -1 then it mean, he wants all organization for the entered parameter P_RESP_ID.
Note: If user enters -1, only last part of ' union all' returns results, otherwise first part of 'union all' returns results. Also tables will have 0 records for parameter ORG_ID = -1 . So I have selected -1 as decision parameter.
Now my question is, Is there any other way of writing this query? I want to have query with good performance and more optimized. As per my knowledge this is the optimized query. Can anyone suggest if there is good optimized way of writing the same query?
Regards,
SK

Hi,
Maybe:
WITH     good_organization_ids     AS
     SELECT     oa.oraganiztion_id
     FROM     org_access             oa
     JOIN     hr_all_organization_units  haou      ON  oa.organization_id = haou.organization_id
     WHERE     oa.responsibility_id     = :p_resp_id
SELECT     *
FROM     wip_discrete_jobs
WHERE     (     :org_id     != 1
     AND     :org_id     = organizatiOn_id
OR     (     :org_id     = 1
     AND      (     organization_id IN (
                              SELECT  organization_id
                              FROM     good_organization_ids
          OR     NOT EXISTS        (
                              SELECT     1
                              FROM     good_organization_ids
;If you'd care to post a little sample data (CREATE TABLE and INSERT statements) for all tables, a couple of sets of parameters (:org_id and :p_resp_id), and the results you want from the same sample data for each set or parameters, then I could test it.
See the forum FAQ
SQL and PL/SQL FAQ
for how to ask questions in general, and how to ask about performance problems in particular.

Similar Messages

  • Alternative way to create temporary table with better performace?

    Hi guys,
    Do you happen to a better alternative way for creating a global temporary table with better performance?
    I am creating a table and then using it in a big query but is taking a lot of time.
    Thanks for any help you can provide.

    I am not very familiar with explains plans, but I believe it is ok.
    The first query I had was repeating part of it in every subquery that is why I decided to create the temporary table. I have also tried using the WITH but it seems to take the same amount of time. I also thought of creating indexed but was told that it would work in this case.
    I have another discussion named "SQL Query Having performance issues" in this discussion I have included the query just in case you want to look at it.
    Thanks

  • Alternative way to fetch the data into single row.

    we have a query
    SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME='XXX';
    This query will return the data in multiple rows.
    May know the alternative way to retrieve all the multiple rows in **single row with each row as a seperate column**.

    Why specifically an array - and do you want the SQL projection as an array, or collect the SQL projection into an array?
    E.g.
    SQL> create or replace type TStrings is table of varchar2(4000);
      2  /
    Type created.
    SQL> --// SQL projection casted into an array
    SQL> select
      2          cast(
      3                  MultiSet(
      4                          select column_name from all_tab_columns where table_name = 'KU$_DATAPUMP_MASTER_11_2' and owner = 'SYS'
      5                  )
      6                  as TStrings
      7          )                       as COLUMN_ARRAY
      8  from       dual
      9  /
    COLUMN_ARRAY
    TSTRINGS('REMOTE_LINK', 'VERSION', 'JOB_VERSION', 'DB_VERSION', 'TIMEZONE', 'STATE', 'PHASE', 'GUID', 'START_TIME', 'BLOCK_SIZE', 'METADATA_BUFFER_SIZE', 'DATA_BUFFER_SIZE', 'DEGREE', 'PLATFORM', 'ABO
    RT_STEP', 'INSTANCE', 'CLUSTER_OK', 'SERVICE_NAME', 'OBJECT_INT_OID', 'PROCESS_ORDER', 'DUPLICATE', 'DUMP_FILEID', 'DUMP_POSITION', 'DUMP_LENGTH', 'DUMP_ORIG_LENGTH', 'DUMP_ALLOCATION', 'COMPLETED_ROW
    S', 'ERROR_COUNT', 'ELAPSED_TIME', 'OBJECT_TYPE_PATH', 'OBJECT_PATH_SEQNO', 'OBJECT_TYPE', 'IN_PROGRESS', 'OBJECT_NAME', 'OBJECT_LONG_NAME', 'OBJECT_SCHEMA', 'ORIGINAL_OBJECT_SCHEMA', 'ORIGINAL_OBJECT
    _NAME', 'PARTITION_NAME', 'SUBPARTITION_NAME', 'DATAOBJ_NUM', 'FLAGS', 'PROPERTY', 'TRIGFLAG', 'CREATION_LEVEL', 'COMPLETION_TIME', 'OBJECT_TABLESPACE', 'SIZE_ESTIMATE', 'OBJECT_ROW', 'PROCESSING_STAT
    E', 'PROCESSING_STATUS', 'BASE_PROCESS_ORDER', 'BASE_OBJECT_TYPE', 'BASE_OBJECT_NAME', 'BASE_OBJECT_SCHEMA', 'ANCESTOR_PROCESS_ORDER', 'DOMAIN_PROCESS_ORDER', 'PARALLELIZATION', 'UNLOAD_METHOD', 'LOAD
    _METHOD', 'GRANULES', 'SCN', 'GRANTOR', 'XML_CLOB', 'PARENT_PROCESS_ORDER', 'NAME', 'VALUE_T', 'VALUE_N', 'IS_DEFAULT', 'FILE_TYPE', 'USER_DIRECTORY', 'USER_FILE_NAME', 'FILE_NAME', 'EXTEND_SIZE', 'FI
    LE_MAX_SIZE', 'PROCESS_NAME', 'LAST_UPDATE', 'WORK_ITEM', 'OBJECT_NUMBER', 'COMPLETED_BYTES', 'TOTAL_BYTES', 'METADATA_IO', 'DATA_IO', 'CUMULATIVE_TIME', 'PACKET_NUMBER', 'INSTANCE_ID', 'OLD_VALUE', '
    SEED', 'LAST_FILE', 'USER_NAME', 'OPERATION', 'JOB_MODE', 'QUEUE_TABNUM', 'CONTROL_QUEUE', 'STATUS_QUEUE')
    SQL> --// collecting the SQL projection as an array
    SQL> declare
      2          colArray        TStrings;
      3  begin
      4          select
      5                  column_name bulk collect into colArray
      6          from    all_tab_columns
      7          where   table_name = 'KU$_DATAPUMP_MASTER_11_2'
      8          and     owner = 'SYS';
      9 
    10          --// process array
    11  end;
    12  /
    PL/SQL procedure successfully completed.
    SQL>

  • Alternative way instead of BDC to Improve performance  of teh ABAP report

    Hi All,
    Our requirement is to delete buffered entries of credit card expences for terminated/ inavtive staff of teh organization.
    For that we are using BDC call transaction in order do so for each employee (terminated/inactive). I mean technically speaking BDC is perfomred inside the loop.
    Can any one suggest me some other alternative way to do this other than BDC, so that we can improve the performance of teh report?
    Thanks in advance.
    Regards,
    Ashwini

    Hi,
    But  the FM /BAPI were using BDC call transaction internally.So same effect. No improvement in performance.
    Kindly suggest related FM/BAPI for creating/deleting expences for a trip.
    Thanks.
    Regards,
    Ashwini

  • Apple says my epson perfection 1240u scanner no longer supported with 10.7. Is there an alternative way to get it to work?

    Apple says my epson perfection 1240u scanner is no longer supported with 10.7.
    Is there an alternative way to get it to work?

    Download updates from the manufacturers pages:
    http://www.epson.com/cgi-bin/Store/support/supDetail.jsp?oid=14549&BV_UseBVCooki e=yes&infoType=Downloads&platform=OSF_M_…

  • Alternative way to transfer file from pc to iphone other than using itunes

    i need an alternative way to transfer vedios, pictures, and docs from pc to iphone

    You could try Bluetooth on both.

  • Alternative way of Updating of Subinventory Accounts

    Hi.
    Issue at hand : How to update (alternative way) the subinventory accounts of FIN and STAGE?
    Facts :
    1. Current setup includes - OM, Financials, INV ( but only to a very minimum level, having 2 Subinventories FIN and STAGE used for Order-to-Cash Cycle )
    2. Recently, MFG and INV are being implemented.
    3. Standard Costing
    Since, there are already onhand and transactions using FIN and STAGE, we are looking at updating the accounts (setup) of FIN and STAGE to a different set.
    I am aware of the procedure provided by Oracle on updating Subinnventory accounts, creating a new subinv and transferring onhand to that new subinv, handle reservations, etc., then update the account setup, and return the onhand, etc.
    One team member suggested that we update the subinventory accounts directly from the database, similar to the script below:
    Update MTL_SECONDARY_INVENTORIES
    set material_overhead_account = 78373,
    overhead_account = 78373,
    resource_account = 78373,
    outside_processing_account = 78373
    where organization_id in (1234, 9999) and secondary_inventory_name in ('FIN', 'STAGE');
    Question: What do you think is/are the implications of this process?
    Your help would be very much appreciated.
    Thank you.

    Basically I have windows server with Oracle 11g (11.2.0.1) server and the database on this server needs to retired and move the data of it to a new server has Linux 64 and Oracle 11g built on it. Here are my answers below:
    What exactly have you tried and done?
    A.  I used "Cross-Platform Transportable Database" to transfer data from Windows to Linux and I am already done, database on the new server (Linux) has been tested and upgraded to latest release (11.2.0.4), my next step is the cutover but the data is too old (2 weeks ago) so I need to take a new data from the current prod server.
    How long did it take and what is your downtime requirement for this migration and what how do you define a "huge database"?
    A. RMAN convert took approximately 5hrs to convert data files from Windows to Linux (Please note that I used rman convert on source server)
    and It took me a day and half to copy the converted files remotely from source in which files been placed to the destination server (the network bandwidth was about 100kb/s so it was so slow) next time I will copy data files on external hard disk then mount them on the new server if I use RMAN convert again.
    End users accepts that the database can be in read only mode for one day business hours but they can't take it more so I'm really concern about the time when taking a new snapshot of data. Also, the size of data is about 380G and that's why I asked again if data pump will be more useful and faster than RMAN for copying data to the new platform.
    Sorry if I made you confused!
    Thanks again for all the support on here.

  • Alternative ways to use NAS with FCPX

    So here is my dilemma, I would like to use my NAS to have an "archived" library of all my video files that I've worked on in FCPX. Thing is I've tried opening the library file directly from my NAS, but FCPX will not recognize it.  It give me an error something that I have to use "SAN"...  I've read some other threads where you can create sparse images but I don't want to have a set size as my "archived" library as it keeps growing.  So I guess my question is, are there any alternative ways to utilize my NAS with FCPX. I want to be able to easily access these "archived" files every so often. TIA!

    Youn can't use it in FCP, only with Compressor. In Compressor make a new QuickTime preset or duplicate an Apple preset and change the codec to x264.

  • Alternative ways of displaying image from database?

    hi - I'm working with some legacy/inherited/already-written Forms that just use block triggers to 'select values into :Fields..' to populate the text boxes on the canvas.
    Whenever I've managed to display db-based images before, it's always been on blocks that are based just on the table, and Forms shows the image okay.
    These forms I'm using at the moment though aren't based on tables, they just get populated from the trigger.
    I don't believe you can select into a blob/image, or at least I haven't been able to get that to work.
    Are there any alternative ways of populating an image place-holder, with a blob field from the database? (other than using a table-based block)??
    thanks.

    May be you can separate the image item to a DB block with primary key of the table and create a relation between two blocks. So when the first block is populated through trigger, it would fetch the image on 2nd block automatically.

  • Alternative way to create delivery for STO

    Hi all,
    Is there an alternative way to create a delivery for STO aside from going to tcode VL04?
    Thanks!

    >
    AA wrote:
    > Hi
    > You may try VL10B.
    >
    > Regards
    > Amitesh Anand
    Hi,
    Thanks for the info.
    Can you give some overview on how to use it?
    Thanks!

  • Alternative Way ?

    Hello !
    i have a low speed internet connection where it takes a long time to download the updating software of Nokia 6630.i just want to know that is there any alternative way to download the updates and then install them through Nokia Software Updater ? Because i want to avoid my cell to be connected to the internet for a long time.
    I Hope you could get my point.seeking replies
    Regards
    Unknown Singer !

    ohh Thank You So Much Sir ..
    and atlast i m done with it it took too much long to complete but Thanx god it is done and now i have upgraded my cellphone thankyou soo much ! !
    Unknown Singer !

  • Nokia Lumia 520 - Alternative way of locking/unloc...

    Hello!
    I've got Nokia Lumia 520 before a week and overall the phone seems really good for my needs, but I found yesterday that the only way to lock/unlock the screen is by using the Power button every time.
    My question is: Is there an alternative way of doing this like for example double tapping the touchscreen or by some app that can perform such function?
    Thanks!

    The 52x hardware does not support the Glace screen functionality. I would guess that in sleep mode the used screen has no power thus would not sense the tap or be able to display the clock. It's a budget phone for a reason..
    That said, pressing the power button is the only  action to wake up the phone..
    Click on the blue Star Icon below if my advice has helped you or press the 'Accept As Solution' link if I solved your problem..

  • Alternative ways to help....

    I'm having antenna issues like other. I don't really like a case on my iPhone 4 so what are some alternative ways to help with the antenna problem? Someone please help me

    Only a handful of methods will work:
    * buy a plastic case - protects the antenna and glass
    * non-conductive tape - placed over the antenna mark prevents a force current from interrupting it
    * never hold it by the palm - hold the iPhone in landscape mode during typing or by the fingers in the center to avoid touching the current.

  • My cd drive on my mac w/ itunes is busted, so i'm looking for an alternative way to get mp3 files (large, for an audiobook) from a cd to my iphone. Any suggestions? Thanks

    My cd drive on my mac w/ itunes is busted, so i'm looking for an alternative way to get mp3 files (large, for an audiobook) from a cd to my iphone. Any suggestions? Thanks

    Copy them to a thumb drive using a different computer then use that to transfer them to your machine. Over a network from a machine with a working CD drive...
    What does this have to do with using the iPhone in an enterprise environment?

  • Is there any alternative way to upadate lumia ?

    I am from India, here in my locality I don't have acess to any Wi-Fi and my phone cant update using GPRS connection so pls let me know about any alternative way to upadate it like any PC software updater or any pc app. And pls provide a link to that app if u can. Thank you.
    IF MY POST IS A SOLUTION FOR YOU THEN HIT THE STAR BUTTON and ACCEPT AS A SOLUTION.

    The official way which is HERE
    If  i have helped at all a click on the white star below would be nice thanks.
    Now using the Lumia 1520

Maybe you are looking for

  • Problem with Java Application after upgrade to 10g

    after upgrading to 10g if I enable coloumn of varchar255 to load into memory of my middleware orm following error is thrown, javax.servlet.jsp.JspException     at jsp.viewsinglerecord.throwError(_viewsinglerecord.java:31)     [SRC:/jsp/standardinclud

  • Service po created with reference to preq , in po some fields data was miss

    i was created preq with item type D and account assignment category = network  , uploading point data and recipient data. after that i was created po with reference to that preq , in that  po uploading field , recipient field data was missing , how t

  • JFRAME- JPANEL question

    I have a JFrame that holds a JPanel. If that JPanel needs to contact the JFrame how do I get access to parent? I tried panelname.getParent, when I did I got a java.lang.ClassCastException Any help would be great. Brock

  • Apps store purchase problem

    I chance my crediy card number but I cant buy somethıng. that says itunes connect problem... please help me

  • WAR deployment problem

              ok this is really confusing and annoying!!! I have a .war file (servlet + jsps           + descriptor) packaged up in the correct way, I have checked the docs like 100           times.. the problem is, I'm running win NT and when I create t