Handling hierarchy in oracle sql query

I have two tables:
The first contains COMPANY_ID and CATEGORY_ID
The second contains CATEGORY_ID and PARENT_CATEGORY_ID
I need to return a list containing COMPANY_ID and CATEGORY_ID. The entries, however, must come not only from the first table, but also include all the descendants listed in the second table.
So for example (and please read the example carefully) - let’s say in the first table I have one row:
COMPANY_ID | CATEGORY_ID
1000 | 1
In the second table, I have three rows:
CATEGORY_ID | PARENT_CATEGORY_ID
1 | null
2 | 1
3 | 2
4 | null
I want to have the following rows as a result:
COMPANY_ID | CATEGORY_ID
1000 | 1
1000 | 2
1000 | 3
How can I do this in oracle 10 in a single SQL statement ?

Hi,
Welcome to the forum!
Whenver you have a question, post your sample data in a form that people can use.
CREATE TABLE and INSERT statements are great:
CREATE TABLE  first
(       company_id     NUMBER (4)
,     category_id     NUMBER (4)
INSERT INTO first (company_id, category_id) VALUES (1000,   1);CREATE TABLE AS is good, too:
CREATE TABLE  second
AS
SELECT     1 AS category_id, NULL AS parent_category_id     FROM dual     UNION ALL
SELECT     2,               1                          FROM dual     UNION ALL
SELECT     3,               2                          FROM dual     UNION ALL
SELECT     4,               NULL                    FROM dual;Without that, people can't test their ideas, and are often unsure about your data.
You should also say what version of Oracle you're using. That's especially important with CONNECT BY queries. Every version since Oracle 7 has had significant improvements in how to do CONNECT BY queries. The query below works in Oracle 10 (and up).
For hierarchies and trees, use CONNECT BY
When you have to join tables and use CONNECT BY, it's usually more efficient to do one in a sub-query, and the other in another query.
In the example below, we're doing the CONNECT BY in sub-query cbq, and the join in the main query.
WITH     cbq     AS
     SELECT     category_id
     ,     CONNECT_BY_ROOT category_id     AS root_category_id
     FROM     second
     START WITH     parent_category_id     IS NULL
           AND     category_id          IN ( SELECT  category_id          -- Maybe; see note below
                                         FROM    first
     CONNECT BY     parent_category_id     = PRIOR category_id
SELECT  first.company_id
,     cbq.category_id
FROM     first
JOIN     cbq     ON     first.category_id     = cbq.root_category_id
;The 2nd condition in the START WITH clause won't change the results any; any rows that are excluded by that condition would also be excluded by the join condition. There can be a big differenece in performance, however. Try the query both ways, and use the 2nd condition if it helps.
Edited by: Frank Kulash on Feb 3, 2010 3:46 PM

Similar Messages

  • Clarification on using function in where clause of oracle sql query

    I have an issue in regarding function using where clause of sql query..
    We are facing performance issue while executing query, so in what ways to improve the performance of the query which i have posted below.
    select col ,case when my_function(parameter)
    from tab1 a ,tab2 b,tabl3 c
    where a.column1=b.column2
    and b.column3 =c.column6
    and my_function(parameter)>0
    Regards
    Dinesh
    Edited by: wild fire on May 18, 2012 4:15 PM

    Dinesh,
    remind that when you use a function in the where clause it normally will get started for each record in the table.
    So your answer is two-fold:
    1. make the function only start when needed by adding a function based index on the table (this will make inserts and updates slower)
    2. make the function faster by adding the DETERMINISTIC clause if possible. this will make Oracle "cache" the result of the function.
    Regards,
    Richard
    blog: http://blog.warp11.nl
    twitter: @rhjmartens
    If this question is answered, please mark the thread as closed and assign points where earned..

  • Oracle Sql Query issue Running on Different DB Version

    Hello All,
    I have come into situation where we are pruning sql queries on different DB version of Oracle and have performance issue. Let me tell you in brief and i really appreciate for your prompt response as its very imperative stuff.
    I have a query which is running on a DB of version 7.3.4 and it takes around 30 mins where as the same query when run on 8i it takes 15sec., its a huge difference. I have run the statistics to analyze on 7.3 and its comparatively very high. Question here is, the sql query trys to select data from same schema table and 2 tables from another DB using DB link and 2 other tables from another DB using DB link.So,how can we optimize this stuff and achieve this run as same time as 8i DB in 7.3. Hope i am clear about my question, Eagerly waiting for your replies.
    Thanks in Advance.
    Message was edited by:
    Ram8

    Difficult to be sure without any more detailed information, but I suspect that O7 is in effect copying the remote tables to local temp space, then joining; 8i is factoring out a better query to send to the remote DBs, which does as much work as possible on the remote DB before shipping remaining rows back to local.
    You should be able to use EXPLAIN PLAN to identify what SQL is being shipped to the remote DB, If you can't (and it's been quite a while since I tried DB links or O7) then get the remote DBs to yourself, and set SQL_TRACE on for the remote instances. Execute the query and then examine the remote trace files, And don't forget to turn off the tracing when you're done.
    Of course it could just be that the CBO got better,,,
    HTH - if not, post your query and plans for the local db, and the remote queries.
    Regards Nigel

  • Oracle SQL Query from EXCEL 2007 with prompt

    Hello,
    I have many excel reports where I am pulling information from our Oracle 9 db through Excel using the following method:
    http://blog.mclaughlinsoftware.com/microsoft-excel/how-to-query-oracle-from-excel-2007/
    http://blog.mclaughlinsoftware.com/2009/11/30/sql-query-in-excel-2007/
    However, I am having trouble when I try the following query due to the prompt:
    SELECT
    IM.ITEM_GROUP,
    IM.ITEM,
    IM.DESCRIPTION
    FROM
    LAWSON.ITEMMAST IM
    WHERE
    IM.ITEM = '&ITEM';
    Does any one know how I can connect a prompt to an excel cell and then pass the query on to Oracle, or have a PL SQL prompt work from Excel?
    Thanks,
    Ben

    The 'prompt' as you call it is a sqlplus feature, so does not belong to the SQL language
    You would need to write a stored procedure returning a resultset.
    create or replace procedure foo(rc in out sys_refcursor, p_item) as
    begin
    open rc for
    'SELECT
    IM.ITEM_GROUP,
    IM.ITEM,
    IM.DESCRIPTION
    FROM
    LAWSON.ITEMMAST IM
    WHERE
    IM.ITEM = '||p_item;
    end;
    and call that using ODBC or asp.net
    Obviously this is profusely documented.
    Sybrand Bakker
    Senior Oracle DBA

  • Oracle SQL query for getting specific special characters from a table

    Hi all,
    This is my table
    Table Name- Table1
    S.no    Name
    1          aaaaaaaa
    2          a1234sgjghb
    3          a@3$%jkhkjn
    4          abcd-dfghjik
    5          bbvxzckvbzxcv&^%#
    6          ashgweqfg/gfjwgefj////
    7          sdsaf$([]:'
    8          <-fdsjgbdfsg
    9           dfgfdgfd"uodf
    10         aaaa  bbbbz#$
    11         cccc dddd-/mnm
    The output has to be
    S.no    Name
    3          a@3$%jkhkjn
    5          bbvxzckvbzxcv&^%#
    7          sdsaf$([]:'
    8          <-fdsjgbdfsg
    10         aaaa  bbbbz#$
    It has to return "Name" column which is having special characters,whereas some special chars like -, / ," and space are acceptable.
    The Oracle query has to print columns having special characters excluding -,/," and space
    Can anyone help me to get a SQL query for the above.
    Thanks in advance.

    You can achieve it in multiple ways. Here are few.
    SQL> with t
      2  as
      3  (
      4  select 1 id, 'aaaaaaaa' name from dual union all
      5  select 2 id, 'a1234sgjghb' name from dual union all
      6  select 3 id, 'a@3$%jkhkjn' name from dual union all
      7  select 4 id, 'abcd-dfghjik' name from dual union all
      8  select 5 id, 'bbvxzckvbzxcv&^%#' name from dual union all
      9  select 6 id, 'ashgweqfg/gfjwgefj////' name from dual union all
    10  select 7 id, 'sdsaf$([]:''' name from dual union all
    11  select 8 id, '<-fdsjgbdfsg' name from dual union all
    12  select 9 id, 'dfgfdgfd"uodf' name from dual union all
    13  select 10 id, 'aaaa  bbbbz#$' name from dual union all
    14  select 11 id, 'cccc dddd-/mnm' name from dual
    15  )
    16  select *
    17    from t
    18   where regexp_like(translate(name,'a-/" ','a'), '[^[:alnum:]]');
            ID NAME
             3 a@3$%jkhkjn
             5 bbvxzckvbzxcv&^%#
             7 sdsaf$([]:'
             8 <-fdsjgbdfsg
            10 aaaa  bbbbz#$
    SQL> with t
      2  as
      3  (
      4  select 1 id, 'aaaaaaaa' name from dual union all
      5  select 2 id, 'a1234sgjghb' name from dual union all
      6  select 3 id, 'a@3$%jkhkjn' name from dual union all
      7  select 4 id, 'abcd-dfghjik' name from dual union all
      8  select 5 id, 'bbvxzckvbzxcv&^%#' name from dual union all
      9  select 6 id, 'ashgweqfg/gfjwgefj////' name from dual union all
    10  select 7 id, 'sdsaf$([]:''' name from dual union all
    11  select 8 id, '<-fdsjgbdfsg' name from dual union all
    12  select 9 id, 'dfgfdgfd"uodf' name from dual union all
    13  select 10 id, 'aaaa  bbbbz#$' name from dual union all
    14  select 11 id, 'cccc dddd-/mnm' name from dual
    15  )
    16  select *
    17    from t
    18   where translate
    19         (
    20            lower(translate(name,'a-/" ','a'))
    21          , '.0123456789abcdefghijklmnopqrstuvwxyz'
    22          , '.'
    23         ) is not null;
            ID NAME
             3 a@3$%jkhkjn
             5 bbvxzckvbzxcv&^%#
             7 sdsaf$([]:'
             8 <-fdsjgbdfsg
            10 aaaa  bbbbz#$
    SQL>

  • Why does Oracle SQL query returning a date field without the time component

    Hi,
    I'm a novice SQL user & hv just installed Oracle SQL developer (Version 3.0.04, Build MAIN-04.34).
    I made the same SQL query using "Oracle SQL developer" & "TOAD for Oracle 9.0.1" but I got 2 different format on the same date field:
    On TOAD, I get the date field extracted as *04/26/2011 23:12:58*
    On Oracle, I get the date field extracted as *26/APR/11*
    Why is the Oracle result in a different format & missing the time component?
    Is there any option/preference that I need to set in Oracle SQL developer to get the full date/time format displayed?
    I've tried to set my the date format to DD/MON/RR HH12:MI:SSXFF AM under the preference -> database NLS but I still get the same format!
    Plse help!

    hokim wrote:
    Hi,
    I'm a novice SQL user & hv just installed Oracle SQL developer (Version 3.0.04, Build MAIN-04.34).
    I made the same SQL query using "Oracle SQL developer" & "TOAD for Oracle 9.0.1" but I got 2 different format on the same date field:
    On TOAD, I get the date field extracted as *04/26/2011 23:12:58*
    On Oracle, I get the date field extracted as *26/APR/11*
    Why is the Oracle result in a different format & missing the time component?
    Is there any option/preference that I need to set in Oracle SQL developer to get the full date/time format displayed?
    I've tried to set my the date format to DD/MON/RR HH12:MI:SSXFF AM under the preference -> database NLS but I still get the same format!
    Plse help!http://edstevensdba.wordpress.com/category/nls_date_format/

  • Some hierarchy related issues, SQL Query is including unselected columns?

    Hello Guys...
    I have something strange happening in my report.. First of all, the RPD I have is built according to JDE model.
    There is a schema which looks like this:
    BU Dim ------->Fact<---------Account Dim <--------BU Account Dim (Indeed a copy of BU Dim)
    A dim hierarchy is created as AccountDim with Account Desc at the lowest bottom level, the dimension key at that level is AcctID which is the unique identifier.
    The issue comes when I created a report using Account, Account Desc, Fact Measures. The measures are not displayed as per account even if the joins and aggr levels are all defined correctly at the proper level..
    I checked the sql that is generately, it is interested that whenever I include Account Desc column in the report, the SQL will include Actid column in the select and groupby part, which results in data being at the wrong level..
    When I remove Actid from Account Hierarchy as the key, the report runs correctly and the SQL query won't include Actid column.. However, since the removal of the ACTid key from Account Hierarchy will cause other reports not running properly, I have to revert the change back to normal.. I'd like to know what to do in order to investigate more deeply as what's going on and as why the SQL will include columns fields that are not selected at answer levels..
    Any suggestions will be greatly appreciately.. I'd like to provide the rpd file, but not sure how to..
    Many Thanks

    Hi, Vikeng,
    Why use the salary table at all, if you're not ever getting any information from it?
    Why not:
    SELECT  EmpName
    ,      DeptName
    ,      'N/A'          AS SalaryValue
    FROM     Employee
    ,     Department
    WHERE      Employee.EmployeeId     = Department.EmployeeId
    Are you saying that somethimes there is a relationship, but not with this sample data?
    If so, post some different sample data (CREATE TABLE and INSERT statements) that has a relationship for some rows, and not for others. Post the results you want from that data, and explain, with specific examples, how you get those results from that data.
    You might just need an outer join.

  • Convert Oracle SQL Query to SQLite Query

    Hi,
    I am new to SQLite and have requirement to write quries in SQLite format. As table structure is same in both the Oracle and SQLite database i have created queries in Oracle SQL. Now wanted to know is there any tool or package available which will convert my simple Oracle queries into SQLite format???
    Please guide..
    Regards,
    Priyanka

    with tree as (
    select
    level lev
    ,id
    ,parent_id
    ,sys_connect_by_path(id, '-') p
    from test_temp
    connect by
    parent_id = prior id
    start with parent_id is null
    select
    from tree t1
    where exists (
    select 1
    from tree t2
    where substr(t2.p, 1, length(t1.p)) = t1.p
      and regexp_count(t2.p, '-') = regexp_count(t1.p, '-') + 2
      -- if regexp_count is not available in your version or performs not well, below is an alternative
      -- and length(t2.p) - length(replace(t2.p, '-')) = length(t1.p) - length(replace(t1.p, '-')) + 2
    LEV
    ID
    PARENT_ID
    P
    1
    1
    -1
    2
    3
    1
    -1-3
    2
    5
    1
    -1-5
    1
    2
    -2
    2
    6
    2
    -2-6
    3
    14
    6
    -2-6-14

  • Oracle sql query execute in the apex

    hi:
    my requirement is, in region i have one text area item and query button.
    in this text area i am typing the any sql query and when i am pressing the query button it should display the query output report..
    pls give solution fast as soon as possible....
    Message was edited by:
    anbarasan

    Hi anbarasan,
    Maybe you can create a report of type "SQL query (PL/SQL Function returning query". Then in the region source, something like:
    DECLARE
    v_sql VARCHAR2 (4000);
    BEGIN
    v_sql := :PX_YOUR_ITEM;
    RETURN v_sql;
    END;
    Paulo Vale
    http://apex-notes.blogspot.com

  • Mysql equivalent oracle sql query is required

    Hi all,
    please help me convert mysql quyery into sql query.
    select u.username, t.name as fullname, p.id as project_id, p.name as project,
                             (select count(a.resource_id) from pd_resource_task_alloc as a left OUTER JOIN pd_resource_task as b on a.task_id=b.task_id where a.task_id=t.id )  as allocatedTask,
                             (select count(a.resource_id) from pd_resource_task_alloc as a left OUTER JOIN pd_resource_task as b on a.task_id=b.task_id where a.task_id=t.id and b.task_status_id='2') as completedTask,
                             (select count(a.resource_id) from pd_resource_task_alloc as a left OUTER JOIN pd_resource_task as b on a.task_id=b.task_id where a.task_id=t.id and b.task_status_id!='2') as pendingTask,
                             c.name as category, sub.task_id, t.name, sub.bucket_date, sum(sub.alloc_time) as s
                             from (select rt.task_id, rt.resource_id, rt.project_id, rta.sequence, rta.alloc_time,DATE(th.creation_date) as creation_date,rt.start_date,th.task_status_id,rt.start_date as bucket_date from resource_task rt, resource_task_alloc rta ,task_history th
                             where rt.task_id = rta.task_id and rt.task_id = th.task_id and th.task_status_id >=2
                             and rt.resource_id = rta.resource_id and rt.project_id = rta.project_id
                             and rta.alloc_time > 0 and rt.start_date is not null ) as sub,
                             pd_tool_user u, pd_task t, pd_project p, pd_category c where sub.resource_id = u.id
                             and sub.start_date >='2011-11-01' and sub.creation_date <= '2011-11-31'
                             and sub.task_id = t.id and sub.project_id = p.id and
                             t.category_id = c.id
                             and sub.project_id='355'
                             group by p.project, u.username, p.id , u.name, sub.task_id, t.name, c.name,
                             sub.bucket_date order by u.username, sub.bucket_date, p.name, c.nameThanks,
    P Prakash

    Not sure as we don't have any tables and data to work with, but firstly...
    a) format your code to make it easier to see what's going on
    b) don't mix ansi joins with regular joins
    c) treat DATEs as DATEs
    d) Table alias names don't use the "AS" keyword
    First guess (obviously unteseted)...
    select u.username
          ,t.name as fullname
          ,p.id as project_id
          ,p.name as project
          ,(select count(a.resource_id)
            from   pd_resource_task_alloc a
                   left OUTER JOIN pd_resource_task b on (a.task_id=b.task_id)
            where  a.task_id=t.id
           ) as allocatedTask
          ,(select count(a.resource_id)
            from   pd_resource_task_alloc a
                   left OUTER JOIN pd_resource_task b on (a.task_id=b.task_id)
            where  a.task_id=t.id
            and    b.task_status_id='2'
           ) as completedTask
          ,(select count(a.resource_id)
            from   pd_resource_task_alloc a
                   left OUTER JOIN pd_resource_task b on (a.task_id=b.task_id)
            where  a.task_id=t.id
            and    b.task_status_id!='2'
           ) as pendingTask
          ,c.name as category
          ,sub.task_id
          ,t.name
          ,sub.bucket_date
          ,sum(sub.alloc_time) as s
    from   (select rt.task_id
                  ,rt.resource_id
                  ,rt.project_id
                  ,rta.sequence
                  ,rta.alloc_time
                  ,th.creation_date -- assuming creation_date is a DATE datatype?
                  ,rt.start_date
                  ,th.task_status_id
                  ,rt.start_date as bucket_date
            from   resource_task rt
                   join resource_task_alloc rta on (rt.task_id = rta.task_id
                                                and rt.resource_id = rta.resource_id
                                                and rt.project_id = rta.project_id)
                   join task_history th on (rt.task_id = th.task_id)
            where  th.task_status_id >=2
            and    rta.alloc_time > 0
            and    rt.start_date is not null
           ) sub
           join pd_tool_user u on (sub.resource_id = u.id)
           join pd_task t on (sub.task_id = t.id)
           join pd_project p on (sub.project_id = p.id)
           join pd_category c on (t.category_id = c.id)
    where  sub.start_date >= to_date('2011-11-01','YYYY-MM-DD') -- assuming start_date is a DATE datatype
    and    sub.creation_date <= to_date('2011-11-31','YYYY-MM-DD') -- assuming creation_date is a DATE datatype
    and    sub.project_id='355'
    group by p.project
            ,u.username
            ,p.id
            ,u.name
            ,sub.task_id
            ,t.name
            ,c.name
            ,sub.bucket_date
    order by u.username
            ,sub.bucket_date
            ,p.name
            ,c.name

  • Oracle SQL query to exclude lowest 2 leaf levels in hierarchy

    Hello!
    I would need to traverse the hierarchy so that I could exclude the 2 lowest levels in the query.
    For eg: Considering the case below the query should return 1, 3, 5, 2, 6, 14.
                  1                                   2
            |             |                       |           |     
            3             5                       4           6
        |         |    |           |           |     |    |      |
        7         9    11          13          8     10   12     14
    |     |   |     |     |    |       |                       |     |
    15    17  19    21    23   27      29                     16     18
                                                                         |
                                                                         20                                                                    
    Quick Script for above structure
    create table test_temp(id number(10), parent_id number(10));
    insert into test_temp(id, parent_id) values(1, null);
    insert into test_temp(id, parent_id) values(3, 1);
    insert into test_temp(id, parent_id) values(5, 1);
    insert into test_temp(id, parent_id) values(7, 3);
    insert into test_temp(id, parent_id) values(9, 3);
    insert into test_temp(id, parent_id) values(11, 5);
    insert into test_temp(id, parent_id) values(13, 5);
    insert into test_temp(id, parent_id) values(15, 7);
    insert into test_temp(id, parent_id) values(17, 7);
    insert into test_temp(id, parent_id) values(19, 9);
    insert into test_temp(id, parent_id) values(21, 9);
    insert into test_temp(id, parent_id) values(23, 11);
    insert into test_temp(id, parent_id) values(27, 13);
    insert into test_temp(id, parent_id) values(29, 13);
    insert into test_temp(id, parent_id) values(2, null);
    insert into test_temp(id, parent_id) values(4, 2);
    insert into test_temp(id, parent_id) values(6, 2);
    insert into test_temp(id, parent_id) values(8, 4);
    insert into test_temp(id, parent_id) values(10, 4);
    insert into test_temp(id, parent_id) values(12, 6);
    insert into test_temp(id, parent_id) values(14, 6);
    insert into test_temp(id, parent_id) values(16, 14);
    insert into test_temp(id, parent_id) values(18, 14);
    insert into test_temp(id, parent_id) values(20, 18);
    Please suggest.
    Thanks...

    with tree as (
    select
    level lev
    ,id
    ,parent_id
    ,sys_connect_by_path(id, '-') p
    from test_temp
    connect by
    parent_id = prior id
    start with parent_id is null
    select
    from tree t1
    where exists (
    select 1
    from tree t2
    where substr(t2.p, 1, length(t1.p)) = t1.p
      and regexp_count(t2.p, '-') = regexp_count(t1.p, '-') + 2
      -- if regexp_count is not available in your version or performs not well, below is an alternative
      -- and length(t2.p) - length(replace(t2.p, '-')) = length(t1.p) - length(replace(t1.p, '-')) + 2
    LEV
    ID
    PARENT_ID
    P
    1
    1
    -1
    2
    3
    1
    -1-3
    2
    5
    1
    -1-5
    1
    2
    -2
    2
    6
    2
    -2-6
    3
    14
    6
    -2-6-14

  • Hierarchy problem in sql query

    Hello Experts,
                   I am using oracle 11g database with sql developer tool at windows 7.I am trying to make hierarchy for my table data.I have a table tbl_state as
    State_Code
    State_Name
    Country_Code
    1
    AH
    0
    2
    BH
    91
    3
    CI
    72
    4
    DI
    72
    5
    EH
    91
    6
    FI
    72
    7
    GJ
    83
    8
    HJ
    83
    I want hierarchy as: set all states under their country for this I have tried a query as:
    SELECT 1, LEVEL, STATE_NM, null, to_char(SATE_CODE) FROM tbl_state CONNECT BY PRIOR SATE_CODE = COUNTRY_CODE start with COUNTRY_CODE=0
    but there is no output as i want.Please suggest me what is going wrong here and if there is any better optimized way to make such hierarchy then please give me.
    thank  you
    regards
    aaditya

    Hi,
    You always need to post CREATE TABLE and INSERT statements for sample data, so that the people who want to help you can re-create the problem and test their ideas.  If you post statements that don't work, you're just wasting your own and other peoples' time.  Do you wnat to get answers that work?  Then show the same courtesy to the people who try to help you.  Test (and, if necessary, correct) your statements before you post them.
    None of the INSERT statements you posted work with the given CREATE TABLE statement.  You should always explicity list the columns in an INSERT statement, like this:
    INSERT INTO tbl_state (sate_code, state_nm, country_code)
                   VALUES (1,         'AA',     0);
    If you add new columns to the table, old INSERT statements like this will still work.
    Here's one way to do what you requested:
    SELECT    CASE
                  WHEN  GROUPING (state_nm) = 1
                  THEN  country_code
              END    AS country_code
    ,         state_nm
    FROM      tbl_state  t
    GROUP BY  country_code
    ,         ROLLUP (state_nm)
    ORDER BY  t.country_code
    ,         state_nm        NULLS FIRST
    Output:
    COUNTRY_CODE STATE_NM
               0
                 AA
              72
                 CI
                 DI
                 FI
              83
                 GJ
                 HJ
              91
                 BH
                 EH
                 IH
    Is the order of countries in your desired output important?  If you really need 91 between 0 and 72, explain why, and we'll find a way to code it.

  • How to tune a oracle sql query to make it run faster ...

    Hi Guys,
    I am very new to this tuning of sql queries. It is taking a lot of time to run a query and give the output. I have a tool called TOAD[ Tool for oracle application development ] and i ran a query in that tool. Its showing that the query is taking 7sec to get its output. I donno the exact procedure what to follow in order to tune that query. What are these actually like : explain plan, sqltrace, tkprof and how to use these to tune the query. I want my query to run faster like in msec.
    Help Appreciated.
    Thanks

    http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96533/toc.htm
    http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96533/sqltrace.htm#1018

  • Loading an Oracle SQL query into an MSSQL table

    I have a select query on an Oracle table. I want to load this data into an MSSQL table.
    Problem is that I cannot create an interim table on the Oracle database (lack of privelages)
    Is there a way to load an Oracle query into the MSSQL table without an interim table?
    Many thanks
    Z

    Yes,
    1) Create an ODI procedure
    2) Create a step inside
    3) at source tab put the oracle query
    4) at target tab put the sql insert code
    Refer to the oracle returned values like "#column_name_from_oracle_query"
    Make sense?
    Cezar Santos
    [www.odiexperts.com]

  • Convert Oracle SQL query to single column output

    Hello All,
    I need to build the query to have multiple columns in a single column with multiple rows.
    select a.customer_trx_id,a.previous_customer_trx_id
    from ra_customer_trx_all a
    where a.customer_trx_id = :customer_trx_id
    here, a.customer_trx_id and a.previous_customer_trx_id are in two columns. I need to bring them into a single column.
    Say: the above output is
    a.customer_trx_id a.previous_customer_trx_id
    123456 87654
    Need to have single column
    As
    123456
    87654
    Please do the needful.
    Thanks,
    Abdul

    Hi,
    Post your question in [SQL and PL/SQL|http://forums.oracle.com/forums/forum.jspa?forumID=75] forum, you would probably get a better/faster response.
    Regards,
    Hussein

Maybe you are looking for

  • Iphoto 9.1.5 wont open

    My iPhoto 9.1.5 will not open. No error messages have popped up, I have ran a disk repair, and restarted the computer. WHAT DO I DO?!?!??!

  • Loop in a loop

    Hello! How do you feel is it ok to use a loop in a loop in a web application? for (Iterator i = collection1.iterator(); i.hasNext();)  {       for (Iterator l = collection2.iterator(); l.hasNext();) {            collection3.add(l.next()); }

  • Level based measure issue

    Hi friends, i am a starter in obiee.I want to develop a following report categoryid, revenue sum of revenue by categoryid in rpd, there is a join between customer to salesfact on category id. i made a duplicate of revenue(sum of revenue) in business

  • Bold text = cannot delete app

    IPad Retina, IOS 8.1.2 When choosen bold text in    screen, light / bold text im cannot delete apps. FOund out after installing some game-apps, when trying to delete them again, the wobling of the apps continued but the speed chanced. THe same contin

  • Thick line through page text Ubuntu 12.04 FF 14.0.1

    Using Ubuntu 12.04, FireFox 14.0.1 When displaying web pages there is a 'thick line' through page text. Unable to take a snapshot, the distortion disappears. This also happens if I reload the page. If I scroll up/down the distortion comes back. I uni