Oracle Analytic function tuning

Hi all,
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for IBM/AIX RISC System/6000: Version 10.2.0.3.0 - Productio
NLSRTL Version 10.2.0.3.0 - Production
I have a query which has analytic function uses large space on temporary tablespace resulting in direct path temp read and direct path temp write wait events taking too much time. Is there any way to tune such query?
Thanks in advance.

user9074365 wrote:
Hi all,
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for IBM/AIX RISC System/6000: Version 10.2.0.3.0 - Productio
NLSRTL Version 10.2.0.3.0 - Production
I have a query which has analytic function uses large space on temporary tablespace resulting in direct path temp read and direct path temp write wait events taking too much time. Is there any way to tune such query?
With your version of Oracle, and high-volumes of data going through analytic function, it's likely that this blog note applies. You may need an upgrade or special patch. http://jonathanlewis.wordpress.com/2009/09/07/analytic-agony/
Regards
Jonathan Lewis

Similar Messages

  • Help with Oracle Analytic Function scenario

    Hi,
    I am new to analytic functions and was wondering if someone could help me with the data scenario below. I have a table with the following data
    COLUMN A COLUMN B COLUMN C
    13368834 34323021 100
    13368835 34438258 50
    13368834 34438258 50
    13368835 34323021 100
    The output I want is
    COLUMN A COLUMN B COLUMN C
    13368834 34323021 100
    13368835 34438258 50
    A simple DISTINCT won't give me the desired output so i was wondering if there is any way that I can get the result using ANALYTIC FUNCTIONS and DISTINCT ..
    Any help will be greatly appreciated.
    Thanks.

    Hi,
    Welcome to the forum!
    Whenever you have a question, please post your sample data in a form that people can use to re-create the problem and test their solutions.
    For example:
    CREATE TABLE     table_x
    (      columna     NUMBER
    ,      columnb     NUMBER
    ,      columnc     NUMBER
    INSERT INTO table_x (columna, columnb, columnc) VALUES (13368834, 34323021, 100);
    INSERT INTO table_x (columna, columnb, columnc) VALUES (13368835, 34438258, 50);
    INSERT INTO table_x (columna, columnb, columnc) VALUES (13368834, 34438258, 50);
    INSERT INTO table_x (columna, columnb, columnc) VALUES (13368835, 34323021, 100);Do you want something that works in your version or Oracle? Of course you do! So tell us which version that is.
    How do you get the results that you want? Explain what each row of output represents. It looks like
    the 1st row contains the 1st distinct value from each column (where "first" means descending order for columnc, and ascending order for the others),
    the 2nd row contains the 2nd distinct value,
    the 3rd row contains the 3rd distinct value, and so on.
    If that's what you want, here's one way to get it (in Oracle 9 and up):
    WITH     got_nums     AS
         SELECT     columna, columnb, columnc
         ,     DENSE_RANK () OVER (ORDER BY  columna        )     AS a_num
         ,     DENSE_RANK () OVER (ORDER BY  columnb        )     AS b_num
         ,     DENSE_RANK () OVER (ORDER BY  columnc  DESC)     AS c_num
         FROM     table_x
    SELECT       MAX (a.columna)          AS columna
    ,       MAX (b.columnb)          AS columnb
    ,       MAX (c.columnc)          AS columnc
    FROM              got_nums     a
    FULL OUTER JOIN  got_nums     b     ON     b.b_num     =           a.a_num
    FULL OUTER JOIN  got_nums     c     ON     c.c_num     = COALESCE (a.a_num, b.b_num)
    GROUP BY  COALESCE (a.a_num, b.b_num, c.c_num)
    ORDER BY  COALESCE (a.a_num, b.b_num, c.c_num)
    ;I've been trying to find a good name for this type of query. The best I've heard so far is "Prix Fixe Query", named after the menus where you get a choice of soups (listed in one column), appetizers (in another column), main dishes (in a 3rd column), and so on. The items on the first row don't necessaily have any relationship to each other.
    The solution does not assume that there are the same number of distinct items in each column.
    For example, if you add this row to the sample data:
    INSERT INTO table_x (columna, columnb, columnc) VALUES (13368835, 34323021, 99);which is a copy of the last row, except that there is a completely new value for columnc, then the output is:
    `  COLUMNA    COLUMNB    COLUMNC
      13368834   34323021        100
      13368835   34438258         99
                                  50starting in Oracle 11, you can also do this with an unpivot-pivot query.

  • Oracle Analytic Function Issue

    Hi, I have created a simple table contaning 3 columns and 3 records.
    Insert into MYTABLE (ID, AMOUNT, RESULT) Values (1, 1, 1);
    Insert into MYTABLE (ID, AMOUNT, RESULT) Values (2, 4, 1);
    Insert into MYTABLE (ID, AMOUNT, RESULT) Values (3, 7, 0);
    COMMIT;
    I can SUM the AMOUNT using the analytic functions as
    SELECT ID, AMOUNT, RESULT, SUM(AMOUNT) OVER() as TOTAL
    FROM MYTABLE;
    ID      AMOUNT      RESULT      TOTAL
    1      1      1      12
    2      4      1 12
    3      7      0      12
    What I want to be able to do is summing the AMOUNTs by RESULT in this case 0 and 1.
    To get the following result, how should I rewrite the query?
    ID      AMOUNT      RESULT      TOTAL RESULT_0_TOTAL RESULT_1_TOTAL
    1 1 1      12 7 5
    2      4      1      12 7 5
    3      7      0      12 7 5

    SELECT ID, AMOUNT, RESULT
    , SUM(CASE WHEN RESULT = 0 THEN AMOUNT ELSE 0 END) OVER() as TOTAL_0
    , SUM(CASE WHEN RESULT = 1 THEN AMOUNT ELSE 0 END) OVER() as TOTAL_1
    FROM MYTABLE;

  • BO4 - Oracle Analytic Function within agg_aware measure

    Hi,
    We can use an analytic function within idt tool and when in a measures by itself it parses ok.
    However when include in an agg_aware measure it gives an ORA-00937 not a single group group function.
    When create queries with the agg_aware measure behaves ok, generates sql ok and runs ok - please advise.
    Thanks

    Nice, am I coming in here to read the English docs again?

  • Oracle analytic functions

    Hello,
    I must use the integral operator in PL/SQL.
    Does anybody know if Oracle provides a PL/SQL procedure or package to apply directly the integral operator?
    Or is there some package with statistics functions? E.g: Gaussian distribution?
    If not, could you help me with some ideas on how to develop a procedure that calculates the integral of a function?
    Thanks a lot for your help,
    Martha

    Martha:
    Maybe it would be better to export the data to Excel and then apply the functions you want.
    Just a thought.
    There are ohter statistical packages (not Oracle) which you can also use once you expert the data.
    Hope this helps.

  • Help - tuning analytic functions

    Where can I find information on hints to speed up oracle analytic functions?
    The table xyz has about 12 million rows.
    The col1 / col2 combinations are effective dated and have an Active /Inactive status.
    Table xyz: col1, col2, effdt, status.
    Goal: I want to eliminate the col1 / col2 combinations where all rows over time have an Inactive status.
    The sq I wrote looks like this:
    select * from
    select col1, col2,
    SUM (1) OVER (PARTITION BY f.col1, f.col2 ORDER BY fcol1, f.col2) total_cnt,
    SUM (CASE WHEN f.status = 'I' THEN 1 ELSE 0 END) OVER
    (PARTITION BY f.col1, f.col2 ORDER BY f.col1) inactive_cnt
    from table xyz f
    where total_cnt > inactive_cnt
    Thanks,
    Frank

    Have a look at these standard threads:
    How to post a tuning request:
    HOW TO: Post a SQL statement tuning request - template posting
    When your query takes too long:
    When your query takes too long ...

  • How to use sum analytic function in adf

    Hi
    jdev 11.1.1.5
    oracle 11g r2
    I want to use analytic function (sum,count,avg and ...) .
    I see [url http://andrejusb.blogspot.co.uk/2013/02/oracle-analytic-functions-for-total-and.html]Oracle Analytic Functions for Total and Average Calculation in ADF BC
    and use it in my vo and jsf page,my vo have too much record and I want to have sum in table footer on demand (because of performance) and if user do not want to see the sum in footer of table it do not calculate sum,
    what is your idea?

    Before I read that blog I use another vo for sum but after that blog decide to use analytic fuction becuase we have some page that have to many dvt graph and table and know we use seperate vo for them and it has not good performance and too many query must run in database ,I want to have 1 vo with some analytic function for graph and tables

  • Error using Analytic function in reports

    Hi,
    I am trying to use Oracle analytic function (lag) in a report. But am getting the below error:
    Encountered the symbol "(" when expecting one of the following:
    ,from into bulk
    This is the code in the formula column:
    function extend_lifeFormula return VARCHAR2 is
    l_extend_life VARCHAR2(80);
    l_life_in_months VARCHAR2(80);
    l_asset_id NUMBER;
    begin
    SRW.REFERENCE(:P_BOOK_NAME);
    SRW.REFERENCE(:ASSET_ID);
    SELECT asset_id,
         lag(life_in_months,1,0) over (PARTITION BY asset_id
                   ORDER BY transaction_header_id_in) Extend_Life
    INTO l_asset_id,
    l_life_in_months
    FROM fa_books
    WHERE book_type_code = 'US GAAP'
    AND asset_id = 1;
    return life_in_months;
    end;
    Has anyone experienced this error before? Does client pl/sql engine not support Analytic functions? The above query runs fine in SQL.
    Thanks,
    Ashish

    From our version of 6i Reports Builder Help, I got ...
    Oracle ORACLE PL/SQL V8.0.6.3.0 - Production
    You may check yours.

  • Max  date in analytic function

    I have records that has repeating load dates.
    I would like to pick the records that has the maximum load_dates.
    My source data looks like this -
    ( select 60589 as C_number, to_date('01/08/2012','DD/MM/YYYY') as load_dt from dual union all
    select 60768, to_date('01/08/2012','DD/MM/YYYY') from dual union all
    select 60888, to_date('01/08/2012','DD/MM/YYYY') from dual union all
    select 12345, to_date('01/09/2012','DD/MM/YYYY') from dual union all
    select 54321, to_date('01/09/2012','DD/MM/YYYY') from dual union all
    select 66666, to_date('01/10/2012','DD/MM/YYYY') from dual union all
    select 55555, to_date('01/10/2012','DD/MM/YYYY') from dual)
    I would like to pick records with the max load_dt that means
    C_number load_dt
    666666 01-Oct-12
    555555 01-Oct-12
    I have written an oracle analytic function but it's not working the way it should be -
    My query looks like this -
    select a.*
    from
    select
    c_number,
    load_dt,
    max(load_dt) over (partition by load_dt) as mx_dt
    from table_name
    where
    load_dt = mx_dt;
    It returns all the rows for some reason.
    Any help or guidance is highly appreciated
    PJ

    without analytical..
    with mydata as
    ( select 60589 as C_number, to_date('01/08/2012','DD/MM/YYYY') as load_dt from dual union all
    select 60768, to_date('01/08/2012','DD/MM/YYYY') from dual union all
    select 60888, to_date('01/08/2012','DD/MM/YYYY') from dual union all
    select 12345, to_date('01/09/2012','DD/MM/YYYY') from dual union all
    select 54321, to_date('01/09/2012','DD/MM/YYYY') from dual union all
    select 66666, to_date('01/10/2012','DD/MM/YYYY') from dual union all
    select 55555, to_date('01/10/2012','DD/MM/YYYY') from dual)
    select *
              from mydata
              where load_dt = (select max(load_dt) from mydata);

  • Replacing Oracle's FIRST_VALUE and LAST_VALUE analytical functions.

    Hi,
    I am using OBI 10.1.3.2.1 where, I guess, EVALUATE is not available. I would like to know alternatives, esp. to replace Oracle's FIRST_VALUE and LAST_VALUE analytical functions.
    I want to track some changes. For example, there are four methods of travel - Air, Train, Road and Sea. Would like to know traveler's first method of traveling and the last method of traveling in an year. If both of them match then a certain action is taken. If they do not match, then another action is taken.
    I tried as under.
    1. Get Sequence ID for each travel within an year per traveler as Sequence_Id.
    2. Get the Lowest Sequence ID (which should be 1) for travels within an year per traveler as Sequence_LId.
    3. Get the Highest Sequence ID (which could be 1 or greater than 1) for travels within an year per traveler as Sequence_HId.
    4. If Sequence ID = Lowest Sequence ID then display the method of travel as First Method of Travel.
    5. If Sequence ID = Highest Sequence ID then display the method of travel as Latest Method of Travel.
    6. If First Method of Travel = Latest Method of Travel then display Yes/No as Match.
    The issue is cells could be blank in First Method of Travel and Last Method of Travel unless the traveler traveled only once in an year.
    Using Oracle's FIRST_VALUE and LAST_VALUE analytical functions, I can get a result like
    Traveler | Card Issue Date | Journey Date | Method | First Method of Travel | Last Method of Travel | Match?
    ABC | 01/01/2000 | 04/04/2000 | Road | Road | Air | No
    ABC | 01/01/2000 | 15/12/2000 | Air | Road | Air | No
    XYZ | 01/01/2000 | 04/05/2000 | Train | Train | Train | Yes
    XYZ | 01/01/2000 | 04/11/2000 | Train | Train | Train | Yes
    Using OBI Answers, I am getting something like this.
    Traveler | Card Issue Date | Journey Date | Method | First Method of Travel | Last Method of Travel | Match?
    ABC | 01/01/2000 | 04/04/2000 | Road | Road | <BLANK> | No
    ABC | 01/01/2000 | 15/12/2000 | Air | <BLANK> | Air | No
    XYZ | 01/01/2000 | 04/05/2000 | Train | Train | <BLANK> | No
    XYZ | 01/01/2000 | 04/11/2000 | Train | <BLANK> | Train | No
    Above, for XYZ traveler the Match? clearly shows a wrong result (although somehow it's correct for traveler ABC).
    Would appreciate if someone can guide me how to resolve the issue.
    Many thanks,
    Manoj.
    Edited by: mandix on 27-Nov-2009 08:43
    Edited by: mandix on 27-Nov-2009 08:47

    Hi,
    Just to recap, in OBI 10.1.3.2.1, I am trying to find an alternative way to FIRST_VALUE and LAST_VALUE analytical functions used in Oracle. Somehow, I feel it's achievable. I would like to know answers to the following questions.
    1. Is there any way of referring to a cell value and displaying it in other cells for a reference value?
    For example, can I display the First Method of Travel for traveler 'ABC' and 'XYZ' for all the rows returned in the same column, respectively?
    2. I tried RMIN, RMAX functions in the RDP but it does not accept "BY" clause (for example, RMIN(Transaction_Id BY Traveler) to define Lowest Sequence Id per traveler). Am I doing something wrong here? Why can a formula with "BY" clause be defined in Answers but not the RPD? The idea is to use this in Answers. This is in relation to my first question.
    Could someone please let me know?
    I understand that this thread that I have posted is related to something that can be done outside OBI, but still would like to know.
    If anything is not clear please let me know.
    Thanks,
    Manoj.

  • Grouping error in Oracle's analytic function  PERCENTILE_CONT()

    Hi,
    I have a question regarding the usage of Oracle's analytic function PERCENTILE_CONT(). The underlying time data in the table is of hourly granularity and I want to fetch average, peak values for the day along with 80th percentile for that day. For the sake of clarification I am only posting relevant portion of the query.
    Any idea how to rewrite the query and achieve the same objective?
    SELECT   TRUNC (sdd.ts) AS ts,
             max(sdd.maxvalue) AS max_value, avg(sdd.avgvalue) AS avg_value,
             PERCENTILE_CONT(0.80) WITHIN GROUP (ORDER BY  sdd.avgvalue ASC) OVER (PARTITION BY pm.sysid,trunc(sdd.ts)) as Percentile_Cont_AVG
    FROM     XYZ
    WHERE
              XYZ
    GROUP BY  TRUNC (sdd.ts)  
    ORDER BY  TRUNC (sdd.ts)
    Oracle Error:
    ERROR at line 5:
    ORA-00979: not a GROUP BY expression

    You probably mixed up the aggregate and analytical versin of PERCENTILE_CONT.
    The below should work, but i dont know if it produces the desireed results.
    SELECT   TRUNC (sdd.ts) AS ts,
             max(sdd.maxvalue) AS max_value, avg(sdd.avgvalue) AS avg_value,
             PERCENTILE_CONT(0.80) WITHIN GROUP (ORDER BY  sdd.avgvalue ASC)  as Percentile_Cont_AVG
    FROM     XYZ
    sorry, what is this where clause for??
    WHERE
              XYZ
    GROUP BY  TRUNC (sdd.ts)  
    ORDER BY  TRUNC (sdd.ts) Edited by: chris227 on 26.03.2013 05:45

  • Analytical Function in Oracle 8.1.5

    I am using the following sql
    select empno,ename,count(*) over()
    from emp;
    But it shows the error
    ORA-00923: FROM keyword not found where expected
    I am using Oracle 8.1.5
    pls help me

    Analytical function were introduced in ORACLE 8iBut only for the Enterprise Edition. If the OP has the Standard Edition they can't use Analytic functions.
    Cheers, APC

  • Tuning sql with analytic function

    Dear friends I've developed one sql :
    with REP as
    (select /*+ MATERIALIZE */ branch_code,
       row_number() over(partition by branch_code, account order by bkg_date desc  ) R,
             account,
             bkg_date,
             lcy_closing_bal
        from history t
    select REP1.branch_code,
           REP1.account,
           REP1.bkg_date,
           REP1.lcy_closing_bal,
             NULL  AS second,
           REP2.bkg_date        bkg_date2,
           REP2.lcy_closing_bal lcy_closing_bal2,
            NULL  AS third,
           REP3.bkg_date        bkg_date3,
           REP3.lcy_closing_bal lcy_closing_bal3
      from (SELECT * FROM REP WHERE R=1) REP1, (SELECT * FROM REP WHERE R=2) REP2, (SELECT * FROM REP WHERE R=3) REP3
    where
           (REP1.BRANCH_CODE = REP2.BRANCH_CODE(+) AND REP1.ACCOUNT = REP2.ACCOUNT(+)) AND
           (REP1.BRANCH_CODE = REP3.BRANCH_CODE(+) AND REP1.ACCOUNT = REP3.ACCOUNT(+))The point is I want to restrict (tune) REP before it used ,because , as you can see I need maximum three value from REP (where R=1,R=2,R=3) . Which analytic function and with wich options I have to use to receive only 3 values in each branch_code,account groups at the materializing time ?

    Radrigez wrote:
    Dear friends I've developed one sql :
    with REP as
    from (SELECT * FROM REP WHERE R=1) REP1,
    (SELECT * FROM REP WHERE R=2) REP2,
    (SELECT * FROM REP WHERE R=3) REP3
    where
    (REP1.BRANCH_CODE = REP2.BRANCH_CODE(+) AND REP1.ACCOUNT = REP2.ACCOUNT(+)) AND
    (REP1.BRANCH_CODE = REP3.BRANCH_CODE(+) AND REP1.ACCOUNT = REP3.ACCOUNT(+))
    The first step is to put your subquery (which doesn't need to be materialized) into an inline view and restrict the result set on r in (1,2,3) as suggested by thtsang - you don't need to query the same result set three times.
    Then you're looking at a simple pivot operation (assuming the number of rows you want per branch and account is fixed). If you're on 11g search the manuals for PIVOT, on earlier versions you can do this with a decode() or case() operator.
    Step 1 (which could go into another factored subquery) would be something like:
    select
            branch_code, account,
            case r = 1 then bkg_date end bkg_date,
            case r = 1 then lcy_closing_bal end lcy_closing_bal,
            case r = 2 then bkg_date end bkg_date2,
            case r = 2 then lcy_closing_bal end lcy_closing_bal2,
            case r = 3 then bkg_date end bkg_date3,
            case r = 3 then lcy_closing_bal end lcy_closing_bal3
    from
            repThis gives you the eight necessary columns, but still (up to) three rows per branch/account.
    Then you aggregate this (call it rep1) on branch and account.
    select
            branch_code, account,
            max(bkg_date),
            max(lcy_closing_bal),
            max(bkg_date2),
            max(lcy_closing_bal2),
            max(bkg_date3),
            max(lcy_closing_bal3)
    from
            rep1
    group by
            branch_code, account
    order by
            branch_code, accountRegards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    Author: <b><em>Oracle Core</em></b>

  • Analytical Function in Oracle

    I have a situation where i have partitioned a record set. If in any of the partition on that recordset, the value of one field(field name- status) is '45' i need to order the result of that partition by- 'outdate' desc, 'receiveddate' desc and order the other partition by 'key' desc,' sequence' desc, 'outdate' desc.
    So the query looks like -
    select row_number() over (partition by key order by sequence) RowNo, key, seq, status, outdate, receivedate from table1 where .........
    order by ????
    RowNo Key Seq status outdate receiveddate
    1 200 0 24 9/13/2009 9/12/2009
    2 200 1 23 9/10/2009 9/09/2009
    3 200 2 24 9/09/2009 9/08/2009
    1 210 0 24 9/13/2009 9/12/2009
    2 210 1 * 45 * 9/09/2009 9/08/2009
    3 210 2 24 9/10/2009 9/09/2009
    So i need to get the query that will order the first set of partition by 'key' desc,' sequence' desc, 'outdate' desc and the Second set of partition (since the status of '45' exist in second partition) by 'outdate' desc, 'receiveddate' desc .
    The output of the query should look like
    RowNo Key Seq status outdate receiveddate
    1 200 0 24 9/13/2009 9/12/2009
    2 200 1 23 9/10/2009 9/09/2009
    3 200 2 24 9/09/2009 9/08/2009
    1 210 0 24 9/13/2009 9/12/2009
    2 210 2 24 9/10/2009 9/09/2009
    3 210 1 *45 * 9/09/2009 9/08/2009
    I am not sure if this is possible using Analytical function.
    I would really appreciate if any one can light me on this.
    Thanks in advance

    Hi,
    Welcome to the forum!
    You can use analytic functions in the ORDER BY clause.
    I don't have your tables, so I'll use scott.emp to illustrate.
    The following query sorts by deptno first. After that, the sort order for departments that contain at least one Salesman is:
    (a) job
    (b) ename
    Deptno=30 happens to be the only department with a Salesman, so it is the only one sorted as above.
    The other departements will be sorted by
    (a) sal
    (b) job
    SELECT       deptno
    ,       ename
    ,       job
    ,       sal
    FROM       scott.emp
    ORDER BY  deptno
    ,            CASE
              WHEN  COUNT ( CASE
                                   WHEN  job = 'SALESMAN'
                          THEN  1
                         END
                       ) OVER (PARTITION BY deptno) > 0
              THEN  ROW_NUMBER () OVER ( PARTITION BY  deptno
                                          ORDER BY        job
                                ,            ename
              ELSE  ROW_NUMBER () OVER ( PARTITION BY  deptno
                                          ORDER BY        sal
                                ,            job
           END
    ;Output:
    .   DEPTNO ENAME      JOB              SAL
            10 MILLER     CLERK           1300
            10 CLARK      MANAGER         2450
            10 KING       PRESIDENT       5000
            20 SMITH      CLERK            800
            20 ADAMS      CLERK           1100
            20 JONES      MANAGER         2975
            20 SCOTT      ANALYST         3000
            20 FORD       ANALYST         3000
            30 JAMES      CLERK            950
            30 BLAKE      MANAGER         2850
            30 ALLEN      SALESMAN        1600
            30 MARTIN     SALESMAN        1250
            30 TURNER     SALESMAN        1500
            30 WARD       SALESMAN        1250 
    In the small set of sample data you posted, the results you want can be obtained simply using
    ORDER BY  key
    ,         outdate     DESCI assume that's just a coincidence.
    If you need help, post some sample data that really requires looking at the status column to get the right results. Post the data in some executable form, such as CREATE TABLE and INSERT statements, olr, as Salim did, a WITH clause. (Perhaps you can just add or change a couple of rows in the sample data Salim already posted.)

  • Ugent: Regarding Oracle 10g Analytic functions

    Hi,
    EMP TABLE:
    EMPNO     ENAME          JOB          MGR          HIREDATE          SAL          COMM     DEPTNO
    ==================================================================
    7369          SMITH          CLERK          7902          12/17/1980     800                    20
    7499          ALLEN          SALESMAN          7698          2/20/1981          1600          300          30
    7521          WARD          SALESMAN          7698          2/22/1981          1250          500          30
    7566          JONES          MANAGER          7839          4/2/1981          2975                    20
    7654          MARTIN          SALESMAN          7698          9/28/1981          1250          1400          30
    7698          BLAKE          MANAGER          7839          5/1/1981          2850                    30
    7782          CLARK          MANAGER          7839          6/9/1981          2450                    
    7788          SCOTT          ANALYST          7566          12/9/1982          3000                    20
    7839          KING          PRESIDENT                    11/17/1981     5000                    
    7844          TURNER          SALESMAN          7698          9/8/1981          1500          0          30
    7876          ADAMS          CLERK          7788          1/12/1983          1100                    20
    7900          JAMES          CLERK          7698          12/3/1981          950                    30
    7902          FORD          ANALYST          7566          12/3/1981          3000                    20
    7934          MILLER          CLERK          7782          1/23/1982          1300                    
    ================================================================
    I would like the output group by manger and the employees under that manager using analytic functions.
    Output should look like:
    ManagerName EMPNAME
    ==========================================================
    KING JONES,BLAKE,CLARK
    JONES SCOTT,FORD
    BLAKE ALLEN,WARD,MARTIN,TURNER,JAMES
    CLARK MILLER
    FORD SMITH
    SCOTT ADAMS
    Also I would like to run this query in unix shell script in order to create a folder structure like this:
    Root Folder: King -> Jones -> SCOTT -> ADAMS
    -> FORD -> SMITH
    -> BLAKE -> ALLEN
    -> WARD
    -> MARTIN
    -> TURNER
    -> JAMES
    -> CLARK -> MILLER
    On a total 14 folders should be created.
    Thanks in Advance
    G.Vamsi Krishna
    Edited by: user10733211 on Apr 20, 2009 11:30 PM

    user10633982 wrote:
    hey guys can you please give your personal opinions and remarks out of this thread.
    this thread is supposed to be solving query and not for chit chattingNot chit chatting and not just personal opinions, just letting you know how it works around here...
    Urgent is it?
    Why? Have you forgotten to do your coursework and you'll get thrown off your course if you don't hand it in today?
    What makes you believe that your request for help is more important than someone else who has requested help? It's very rude to assume you are more important than somebody else, and I'm sure they would like an answer to their issue as soon as they can get one too, but they've generally been polite and not demanded that it is urgent.
    Also, you assume that people giving answers are all sitting here just waiting to answer your question for you. That's not so. We're all volunteers with our own jobs to do. How dare you presume to demand our attention with urgency.
    If you want help and you want it answering quickly you simply just put your issue forward and provide as much valuable information as possible.
    You will find if you post on here demanding your post is urgent then most people will just ignore it, some will tell you to get lost, and some will explain to you why you shouldn't post "urgent" requests. Occasionally you may find somebody who's got nothing better to do who will actually provide you with an answer, but you really are limiting your options by not asking properly.
    How can something being run against the SCOTT schema be something that is "urgent"?
    For the first part of your enquiry:
    SQL> ed
    Wrote file afiedt.buf
      1  with emps as (select ename, mgr, row_number() over (partition by mgr order by ename) as rn from emp)
      2  select ename as managername
      3        ,(select ltrim(sys_connect_by_path(emps.ename,','),',')
      4          from   emps
      5          where emps.mgr = emp.empno
      6          and connect_by_isleaf = 1
      7          connect by rn = prior rn + 1 and mgr = prior mgr
      8          start with rn = 1
      9         ) as empname
    10  from emp
    11* where empno in (select mgr from emp)
    SQL> /
    MANAGERNAM EMPNAME
    JONES      FORD,SCOTT
    BLAKE      ALLEN,JAMES,MARTIN,TURNER,WARD
    CLARK      MILLER
    SCOTT      ADAMS
    KING       BLAKE,CLARK,JONES
    FORD       SMITH
    6 rows selected.
    SQL>As for using that output in a unix shell script to create directory structures you should consider asking in a unix forum.

Maybe you are looking for