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.

Similar Messages

  • Need help with an analytic function I think

    I have a table as such:
    BID, POSITIONDATE
    1 3/10/2009
    1 3/11/2009
    1 3/12/2009
    1 3/13/2009
    1 3/13/2009
    1 3/13/2009
    1 3/14/2009
    I need to select a count(*) from this table for EACH day in MARCH, but the table is missing the days of 3/1 - 3/9
    I need my result set to be:
    BID, POSITIONDATE, COUNT(*)
    1 3/1/2009 0
    1 3/2/2009 0
    1 3/3/2009 0
    1 3/10/2009 1
    1 3/11/2009 1
    1 3/12/2009 1
    1 3/13/2009 3
    1 3/14/2009 1
    I thought LAG would do it but I cannot figure out how to get it to "make up the dates of 3/1-3/9 since those dates aren't actually in the table)
    I also tried creating a "FAKE" table (T1) with the dates of 3/1 -> 3/31 and outer joining to it, but that didn't seem to work either.
    Any tips/suggestions??
    Chris

    with t1
    as
    select to_date('03/01/2009','MM/DD/YYYY')-1 + level as Date1
    from dual
    where (to_date('03/01/2009','MM/DD/YYYY')-1+level) <= last_day(to_date('03/01/2009','MM/DD/YYYY'))
    connect by level<=31
    select * from t1
    DATE1
    3/1/2009     
    3/2/2009     
    3/3/2009     
    3/4/2009     
    3/5/2009     
    3/6/2009     
    3/7/2009     
    3/8/2009     
    3/9/2009     
    3/10/2009     
    3/11/2009     
    3/12/2009     
    3/13/2009     
    3/14/2009     
    3/15/2009     
    3/16/2009     
    3/17/2009     
    3/18/2009     
    3/19/2009     
    3/20/2009     
    3/21/2009     
    3/22/2009     
    3/23/2009     
    3/24/2009     
    3/25/2009     
    3/26/2009     
    3/27/2009     
    3/28/2009     
    3/29/2009     
    3/30/2009     
    3/31/2009     
    31 Rows Selected
    with t1
    as
    select to_date('02/01/2009','MM/DD/YYYY')-1 + level as Date1
    from dual
    where (to_date('02/01/2009','MM/DD/YYYY')-1+level) <= last_day(to_date('02/01/2009','MM/DD/YYYY'))
    connect by level<=31
    select * from t1
    DATE1
    2/1/2009     
    2/2/2009     
    2/3/2009     
    2/4/2009     
    2/5/2009     
    2/6/2009     
    2/7/2009     
    2/8/2009     
    2/9/2009     
    2/10/2009     
    2/11/2009     
    2/12/2009     
    2/13/2009     
    2/14/2009     
    2/15/2009     
    2/16/2009     
    2/17/2009     
    2/18/2009     
    2/19/2009     
    2/20/2009     
    2/21/2009     
    2/22/2009     
    2/23/2009     
    2/24/2009     
    2/25/2009     
    2/26/2009     
    2/27/2009     
    2/28/2009     
    28 Rows Selected
    I probably should change the variable to MM/YYYY and leave out day I guess, because if they put a day larger than 1, then I would end up with less than a full month.

  • Help with oracle 11g pivot operator

    i need some help with oracle 11g pivot operator. is it possible to use multiple columns in the FOR clause and then compare it against multiple set of values.
    here is the sql to create some sample data
    create table pivot_data ( country_code number , dept number, job varchar2(20), sal number );
    insert into pivot_data values (1,30 , 'SALESMAN', 5000);
    insert into pivot_data values (1,301, 'SALESMAN', 5500);
    insert into pivot_data values (1,30 , 'MANAGER', 10000);     
    insert into pivot_data values (1,301, 'MANAGER', 10500);
    insert into pivot_data values (1,30 , 'CLERK', 4000);
    insert into pivot_data values (1,302, 'CLERK',4500);
    insert into pivot_data values (2,30 , 'SALESMAN', 6000);
    insert into pivot_data values (2,301, 'SALESMAN', 6500);
    insert into pivot_data values (2,30 , 'MANAGER', 11000);     
    insert into pivot_data values (2,301, 'MANAGER', 11500);
    insert into pivot_data values (2,30 , 'CLERK', 3000);
    insert into pivot_data values (2,302, 'CLERK',3500);
    using case when I can write something like this and get the output i want
    select country_code
    ,avg(case when (( dept = 30 and job = 'SALESMAN' ) or ( dept = 301 and job = 'SALESMAN' ) ) then sal end ) as d30_sls
    ,avg(case when (( dept = 30 and job = 'MANAGER' ) or ( dept = 301 and job = 'MANAGER' ) ) then sal end ) as d30_mgr
    ,avg(case when (( dept = 30 and job = 'CLERK' ) or ( dept = 302 and job = 'CLERK' ) ) then sal end ) as d30_clrk
    from pivot_data group by country_code;
    output
    country_code          D30_SLS               D30_MGR               D30_CLRK
    1      5250      10250      4250
    2      6250      11250      3250
    what I tried with pivot is like this I get what I want if I have only one ( dept,job) for one alias name. I want to call (30 , 'SALESMAN') or (301 , 'SALESMAN') AS d30_sls. any help how can I do this
    SELECT *
    FROM pivot_data
    PIVOT (SUM(sal) AS sum
    FOR (dept,job) IN ( (30 , 'SALESMAN') AS d30_sls,
              (30 , 'MANAGER') AS d30_mgr,               
    (30 , 'CLERK') AS d30_clk
    this is a simple example .... my real life scenario is compliated with more fields and more combinations .... So something like using substr(dept,1,2) won't work in my real case .
    any suggestions get the result similar to what i get in the case when example is really appreciated.

    Hi,
    Sorry, I don't think there's any way to get exactly what you requested. The values you give in the PIVOT ... IN clause are exact values, not alternatives.
    You could do something like this to map all alternatives to a common value:
    WITH     got_dept_grp     AS
         SELECT     country_code, job, sal
         ,     CASE
                  WHEN  job IN ('SALESMAN', 'MANAGER') AND dept = 301 THEN 30
                  WHEN  job IN ('CLERK')               AND dept = 302 THEN 30
                                                                     ELSE dept
              END     AS dept_grp
         FROM     pivot_data
    SELECT     *
    FROM     got_dept_grp
    PIVOT     (     AVG (sal)
         FOR     (job, dept_grp)
         IN     ( ('SALESMAN', 30)
              , ('MANAGER' , 30)
              , ('CLERK'   , 30)
    ;In your sample data (and perhaps in your real data), it's about as easy to explicitly define the pivoted groups individually, like this:
    WITH     got_pivot_key     AS
         SELECT     country_code, sal
         ,     CASE
                  WHEN  job = 'SALESMAN' AND dept IN (30, 301) THEN 'd30_sls'
                  WHEN  job = 'MANAGER'  AND dept IN (30, 301) THEN 'd30_mgr'
                  WHEN  job = 'CLERK'    AND dept IN (30, 302) THEN 'd30_clrk'
              END     AS pivot_key
         FROM    pivot_data
    SELECT     *
    FROM     got_pivot_key
    PIVOT     (     AVG (sal)
         FOR     pivot_key
         IN     ( 'd30_sls'
              , 'd30_mgr'
              , 'd30_clrk'
    ;Thanks for posting the CREATE TABLE and INSERT statements; that really helps!

  • Wired problem with LEAD Analytical function

    I am having wired problem with LEAD Analytical function. It works fine as a standalone query
    but when used in sub-query it is not behaving as expected (explained below). I unable to troubleshoot
    the issue. Please help me.
    Detail explanation and the data follows:
    ========================= Table & Test Data =======================================
    CREATE TABLE "TESTSCHED"
    (     "SEQ" NUMBER NOT NULL ENABLE,
         "EMPL_ID" NUMBER NOT NULL ENABLE,
         "SCHED_DT" DATE NOT NULL ENABLE,
         "START_DT_TM" DATE NOT NULL ENABLE,
         "END_DT_TM" DATE NOT NULL ENABLE,
         "REC_STAT" CHAR(1) NOT NULL ENABLE,
         CONSTRAINT "TESTSCHED_PK" PRIMARY KEY ("SEQ")     
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (1, 39609, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 07:00:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 11:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (2, 39609, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 11:00:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 11:30:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (3, 39609, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 07:00:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 11:30:00', 'dd-mm-yyyy hh24:mi:ss'), 'I');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (4, 39609, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 07:15:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 11:30:00', 'dd-mm-yyyy hh24:mi:ss'), 'I');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (5, 39609, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 07:15:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 11:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'I');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (6, 39609, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 07:00:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 11:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'I');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (7, 39609, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 07:00:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 11:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'U');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (8, 39609, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 07:00:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 11:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'I');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (9, 118327, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 17:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 22:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (10, 120033, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 19:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('04-03-2008', 'dd-mm-yyyy'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (11, 120033, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 19:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('04-03-2008', 'dd-mm-yyyy'), 'I');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (12, 120033, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 17:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 19:30:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (13, 120033, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 17:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 19:30:00', 'dd-mm-yyyy hh24:mi:ss'), 'U');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (14, 126690, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 18:45:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 21:15:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (15, 126690, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 12:45:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 16:45:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (16, 126690, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 12:45:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 21:15:00', 'dd-mm-yyyy hh24:mi:ss'), 'I');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (17, 126690, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 16:45:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 18:45:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (18, 126690, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 16:45:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 18:45:00', 'dd-mm-yyyy hh24:mi:ss'), 'U');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (19, 169241, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 05:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 14:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (20, 169241, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 05:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 14:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'I');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (21, 169241, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 17:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 22:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (22, 169241, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 17:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 22:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'U');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (23, 200716, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 17:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 22:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'I');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (24, 200716, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 17:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 22:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (25, 200716, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 17:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 22:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'U');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (26, 252836, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 19:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 22:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (27, 252836, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 17:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 22:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'I');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (28, 252836, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 17:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 19:30:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (29, 252836, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 17:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 19:30:00', 'dd-mm-yyyy hh24:mi:ss'), 'U');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (30, 260774, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 07:00:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 10:30:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (31, 260774, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 10:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 14:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (32, 260774, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 05:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 07:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (33, 260774, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 07:15:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 10:35:00', 'dd-mm-yyyy hh24:mi:ss'), 'I');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (34, 260774, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 07:15:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 10:35:00', 'dd-mm-yyyy hh24:mi:ss'), 'I');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (35, 260774, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 05:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 14:00:00', 'dd-mm-yyyy hh24:mi:ss'), 'I');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (36, 260774, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 07:00:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 10:30:00', 'dd-mm-yyyy hh24:mi:ss'), 'U');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (37, 289039, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 16:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 22:15:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (38, 289039, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 13:45:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 22:15:00', 'dd-mm-yyyy hh24:mi:ss'), 'I');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (39, 289039, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 13:45:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 16:30:00', 'dd-mm-yyyy hh24:mi:ss'), 'A');
    insert into testsched (SEQ, EMPL_ID, SCHED_DT, START_DT_TM, END_DT_TM, REC_STAT)
    values (40, 289039, to_date('03-03-2008', 'dd-mm-yyyy'), to_date('03-03-2008 13:45:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('03-03-2008 16:30:00', 'dd-mm-yyyy hh24:mi:ss'), 'U');
    ========================= Problem Statement =======================================
    Problem Statement:
    Select all employees whose active schedule (rec_stat = 'A') start date & time falls
    between "16:30" and "17:45".
    An employee may be having multiple schedules on a day. It may be continuous or may be
    having breaks in between the schedules.
    If an employee schedule is continuous then the minimum schedule start date & time is
    considered as the start date & time of the work.
    If an employee is having breaks in the schedule, then each schedule start date & time is
    considered as start date & time.
    e.g:-1
    1     39609     2008/03/03     2008/03/03 07:00:00     2008/03/03 11:00:00     A
    2     39609     2008/03/03     2008/03/03 11:00:00     2008/03/03 11:30:00     A
    In above case, the employee schedule is continuous. The start date & time is 2008/03/03 07:00:00
    e.g:-2
    19     169241     2008/03/03     2008/03/03 05:30:00     2008/03/03 14:00:00     A
    21     169241     2008/03/03     2008/03/03 17:30:00     2008/03/03 22:00:00     A
    In above case, the employee is having a break in between. Then both records
    start date & time (i.e. 2008/03/03 05:30:00, 2008/03/03 05:30:00 ) is considered
    as start date & time.
    e.g:-3
    30     260774     2008/03/03     2008/03/03 07:00:00     2008/03/03 10:30:00     A
    31     260774     2008/03/03     2008/03/03 10:30:00     2008/03/03 14:00:00     A
    32     260774     2008/03/03     2008/03/03 05:30:00     2008/03/03 07:00:00     A
    In above case, the employee schedule is continuous. The start date & time is 2008/03/03 05:30:00
    ========================= Query to test Individual Employees =======================================
    Query-1: Test query to see the CASE and LEAD function works fine. If "CAL = 0" means that all
    schedules are continuous and the employee needs to ignored.
    SELECT fw.*,
    CASE WHEN LEAD(FW.END_DT_TM, 1)
    OVER(ORDER BY FW.START_DT_TM DESC ) IS NULL AND
    fw.start_dt_tm BETWEEN
    TO_DATE('03/03/2008 16:30:00','mm/dd/yyyy hh24:mi:ss') AND
    TO_DATE('03/03/2008 17:45:00','mm/dd/yyyy hh24:mi:ss')
    THEN Fw.seq
    WHEN LEAD(FW.END_DT_TM, 1)
    OVER(ORDER BY FW.START_DT_TM DESC) != FW.START_DT_TM AND
    fw.start_dt_tm BETWEEN
    TO_DATE('03/03/2008 16:30:00','mm/dd/yyyy hh24:mi:ss') AND
    TO_DATE('03/03/2008 17:45:00','mm/dd/yyyy hh24:mi:ss')
    THEN Fw.seq
    ELSE 0
    END AS "CAL"
    FROM TESTSCHED fw
    WHERE fw.empl_id = 289039
    and fw.rec_stat = 'A'
    Query Results
    SEQ     EMPL_ID     SCHED_DT     START_DT_TM          END_DT_TM          REC_STAT     CAL
    37     289039     2008/03/03     2008/03/03 16:30:00     2008/03/03 22:15:00     A          0
    39     289039     2008/03/03     2008/03/03 13:45:00     2008/03/03 16:30:00     A          0
    Since all "CAL" column is zero, the employee should be ignored.
    ========================= Query to be used in the application =======================================
    Query-2: Actual Query executed in the application which is not working. Query-1 is used as subquery
    here.
    SELECT
    F1.SEQ,
    F1.EMPL_ID,
    F1.SCHED_DT,
    F1.START_DT_TM,
    F1.END_DT_TM,
    F1.REC_STAT
    FROM TESTSCHED F1
    WHERE F1.SEQ IN
    (SELECT CASE
    WHEN LEAD(FW.END_DT_TM, 1)
    OVER(ORDER BY FW.START_DT_TM DESC) IS NULL AND
    FW.START_DT_TM BETWEEN
    TO_DATE('03/03/2008 16:30:00', 'mm/dd/yyyy hh24:mi:ss') AND
    TO_DATE('03/03/2008 17:45:00', 'mm/dd/yyyy hh24:mi:ss') THEN FW.SEQ
    WHEN LEAD(FW.END_DT_TM, 1)
    OVER(ORDER BY FW.START_DT_TM DESC) != FW.START_DT_TM AND
    FW.START_DT_TM BETWEEN
    TO_DATE('03/03/2008 16:30:00', 'mm/dd/yyyy hh24:mi:ss') AND
    TO_DATE('03/03/2008 17:45:00', 'mm/dd/yyyy hh24:mi:ss') THEN FW.SEQ
    ELSE 0
    END
    FROM TESTSCHED FW
    WHERE FW.EMPL_ID = F1.EMPL_ID
    AND FW.REC_STAT = 'A')
    Query-2 Results
    SEQ     EMPL_ID     SCHED_DT     START_DT_TM          END_DT_TM          REC_STAT
    9     118327     2008/03/03     2008/03/03 17:30:00     2008/03/03 22:00:00     A
    12     120033     2008/03/03     2008/03/03 17:30:00     2008/03/03 19:30:00     A
    17     126690     2008/03/03     2008/03/03 16:45:00     2008/03/03 18:45:00     A
    21     169241     2008/03/03     2008/03/03 17:30:00     2008/03/03 22:00:00     A
    24     200716     2008/03/03     2008/03/03 17:30:00     2008/03/03 22:00:00     A
    28     252836     2008/03/03     2008/03/03 17:30:00     2008/03/03 19:30:00     A
    37     289039     2008/03/03     2008/03/03 16:30:00     2008/03/03 22:15:00     A
    Problem with Query-2 Results:
    Employee IDs 126690 & 289039 should not appear in the List.
    Reason: Employee 126690: schedule start date & time is 2008/03/03 12:45:00 and falls outside
    "16:30" and "17:45"
    14     126690     2008/03/03     2008/03/03 18:45:00     2008/03/03 21:15:00     A
    17     126690     2008/03/03     2008/03/03 16:45:00     2008/03/03 18:45:00     A
    15     126690     2008/03/03     2008/03/03 12:45:00     2008/03/03 16:45:00     A
    Reason: Employee 289039: schedule start date & time is 2008/03/03 13:45:00 and falls outside
    37     289039     2008/03/03     2008/03/03 16:30:00     2008/03/03 22:15:00     A
    39     289039     2008/03/03     2008/03/03 13:45:00     2008/03/03 16:30:00     A

    Your LEAD function is order by fw.start_dt_tm, in your first sql, the where clause limited the records return to REC_STAT = A and EMPL_ID = 289039.
    In your 2nd query, there is no where clause, so to the LEAD function, the next record after seq 37 is seq 38 which has an end date of 2003-03-03 10:15 pm, not equal to the start time of record seq 37.
    Message was edited by:
    user477455

  • I need help with oracle

    Hi,
    I need some help... if someone can help its great.
    I need to make a statement in Oracle SQL that read data from a file and insert in a Oracle Database ... if someone can show me the syntax of it i appreciate..
    Thanks

    Okay, I see you followed the advice in that other thread and started a new post for you question. Congratulations. Your next lesson in forum etiquette is to give your posts a more relevant subject. Pretty much everybody who posts here needs help with oracle; if they need help with cooking catfish they've come to the wrong place.
    It that other thread I suggested using SQL*Loader or External Tables might be a more suitable solution. Find out more.
    Cheers, APC

  • Power Query for Excel - Need Help with Oracle SQL Syntax

    Hello everyone,
    I am new to Power Query and am not able to figure this out.  I am trying to pull in data into my Excel spreadsheet using a specific Oracle SQL query.  While in query editor, how do I take the Oracle.Database function and add my SQL statement? 
    I already know what I want, I don't want it to download all the table names.  According to the help page, I should be able to do this but it does not provide a syntax example
    Also, I don't understand what "optional options as nullable record" means.
    Below is what function and arguments the help page notes.  How do I use this?
    Oracle.Database(server as text, optional options as nullable record) as table
    Any help is greatly appreciated.
    Thank you,
    Jessica

    When I try this, I get an error 
    DataSource.Error: Oracle: Sql.Database does not support the query option 'Query' with value '"Select * from Owner.View_Name"'. Details: null
    I'm trying to download oracle data from a view into power query - Power Query navigator does not list th eviews from my source, it lists only the tables. When I try write sql statements, it throws me the above
    error. This is what I tried
     Oracle.Database("Source/Service",[Query="Select * from Owner.View_Name"])
    Any ideas how to fix this? 

  • 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

  • Problem with Oracle Analytic Workspace Manager ver 10.1.0.4

    Hi,
    I am running Oracle Analytic Workspace Manager ver 10.1.0.4. When I tried getting connected to Analytical workspace I get the following error. Any help could be appreciated.
    java.sql.SQLException: ORA-00904: "O"."SF_VERSION": invalid identifier
    at oracle.olap.awm.businessobject.aw.WorkspaceBO.getWorkspacesOwnedBySchemaInStandardForm(WorkspaceBO.java:191)
    at oracle.olap.awm.navigator.node.WorkspaceFolderNode.getChildren(WorkspaceFolderNode.java:101)
    at oracle.olap.awm.navigator.node.BaseNodeModel.refreshData(BaseNodeModel.java:74)
    at oracle.olap.awm.navigator.node.BaseNodeModel.dTreeItemExpanding(BaseNodeModel.java:221)
    at oracle.bali.ewt.dTree.DTreeDeferredParent.__fireExpansionChanging(Unknown Source)
    at oracle.bali.ewt.dTree.DTreeDeferredParent.setExpanded(Unknown Source)
    at oracle.olap.awm.navigator.node.BaseNode.expandHelper(BaseNode.java:1813)
    at oracle.olap.awm.navigator.node.BaseNode.access$000(BaseNode.java:93)
    at oracle.olap.awm.navigator.node.BaseNode$ExpansionThread.run(BaseNode.java:1763)
    Thanking u,
    Amudha

    There are posts on the OLAP forum covering this problem. Anthony Waite from the OLAP Product Management team has provided the following information:
    e new, default Model View in AWM 10.1.0.4.0 is based upon the OLAP Analytic Workspace API (a.k.a. AW/XML). Just to recap and further clarify my earlier post, you must pass the following requirements in order to use it:
    1) Be sure to be using the Enterprise Edition of the Oracle Database 10g.
    SQL> select banner from v$version where banner like 'Oracle%';
    You should see Oracle Database 10g Enterprise Edition.
    2) Be sure to have the Data Warehouse database configuration or the OLAP Option enabled.
    SQL> select parameter, value from v$option where parameter='OLAP';
    You should see OLAP TRUE.
    3) Be sure that the RDBMS 10.1.0.4 patch set has been completely installed. Users often miss the required Post-Installation Steps such as running catpatch.sql.
    SQL> select comp_name, version, status from dba_registry;
    You should see VALID and 10.1.0.4.0 for the OLAP components.
    4) The Oracle Database must have the compatibility mode of 10.1 to use the Model View as it relies on the unique features found in Oracle Database 10g.
    SQL> select name, value, description from v$parameter where name ='compatible';
    You should see 10.1, not 9.2 or earlier.
    5) Please refer to the patchnote.htm that is bundled with 10.1.0.4.0 patch set. Only you are aware of what type of database configuration you have. You will want to pay close attention to "7.2.1.3 Set the SHARED_POOL_SIZE and JAVA_POOL_SIZE Initialization Parameters" and "7.2.2 Upgrade the Release 10.1 Database".
    Basically, I believe you have missed these required steps after installing the 10.1.0.4.0 patch set from the OUI: (pasted from the patchnote.htm)
    For the full discussion please refer to this link:
    Re: Error trying to Analytic Workspace using latest version AWM 10.1.0.4
    Hope this helps
    Keith
    Oracle Business Intelligence Product Management
    BI on Oracle: http://www.oracle.com/bi/
    BI on OTN: http://www.oracle.com/technology/products/bi/
    BI Beans http://www.oracle.com/technology/products/bib/index.html
    Discoverer: http://www.oracle.com/technology/products/discoverer/
    BI Software: http://www.oracle.com/technology/software/products/ias/devuse.html
    Documentation: http://www.oracle.com/technology/documentation/appserver1012.html
    BI Samples: http://www.oracle.com/technology/products/bi/samples/
    Blog: http://oraclebi.blogspot.com/

  • Help with Oracle PL/SQL and Objects...

    Hi,
    I wonder if you can help me, I am having some trouble dealing with Oracle objects in PL/SQL. I can declare them, populate them and read from them without any issues.
    But I am having some problems with trying to copy records in to other records of the same type, and also with updating existing records. I've made a mock up piece of code below to explain what I mean, it may have a few mistakes as I've written it in notepad but should be reasonably clear.
    First I have created a record type, which contains attributes relating to a person.....
    CREATE OR REPLACE
    TYPE PERSON_RECORD_TYPE AS object (
                        Person_ID          NUMBER(3),
                        Person_Name     VARCHAR(20),
                        Person_Age          NUMBER(2),
                        static function new return PERSON_RECORD_TYPE );
    CREATE OR REPLACE
    TYPE BODY PERSON_RECORD_TYPE as
    static function new return PERSON_RECORD_TYPE is
    BEGIN
    return PERSON_RECORD_TYPE (
         NULL,
                             NULL,
                             NULL,
                             NULL,
                             NULL
    END;
    END;
    Then I have created a table type, which is a table of the person record type......
    CREATE OR REPLACE
    type PERSON_TABLE_TYPE as table of PERSON_RECORD_TYPE;
    Finally I have created a procedure which recieves an instance of the person table type and reads through it using a cursor.....
    PROCEDURE ADMIN_PERSON (incoming_person     IN     PERSON_TABLE_TYPE)
    IS
    -- This is a local record declared as the same type as the incoming object
    local_person PERSON_TABLE_TYPE;
    -- Cursor to select all from the incoming object
    CURSOR select_person
    IS
    SELECT      *
    FROM      TABLE ( cast (incoming_person AS PERSON_TABLE_TYPE));
    BEGIN
    -- Loop to process cursor results
    FOR select_person_rec IN select_person
         LOOP
              /* Up to this point works fine...*/
              -- If I want to store the current cursor record in a local record of the same type, I can do this....
              local_person.person_id          := select_person_rec.person_id;
              local_person.person_name      := select_person_rec.person_name;
              local_person.person_age          := select_person_rec.person_age;
    -- QUESTION 1
              -- The above works fine, but in my real example there are a lot more fields          
              -- Why cant I set the local record to the value of the cursor record like this below..     
              local_person := select_person_rec;
    -- The above line gives a pl/sql error - expression is of wrong type, (as far as I can see the records are of the same type?)
    -- QUESTION 2
              --Also how do you update an existing record within the original object, I have tried the following but it does not work
              UPDATE incoming_person
              SET          age = (age + 1)
              WHERE     incoming_person.person_id = '123';
    -- The error here is that the table does not exist
         END LOOP;
    END;
    So I hope that you can see from this, I have two problems. The first is that I can store the current cursor record in a local record if I assign each attribute one at a time, but my real example has a large number of attributes. So why can't I just assign the entire cursor record to the local cursor record?
    I get a PL/SQL error "Expression is of wrong type" when I try to do this.
    The second question is with regards to the update statement, obviously this doesn't work, it expects a table name here instead. So can anyone show me how I should update existing person records in the incoming table type to the procedure?
    I hope this makes sense, but I don't think I have explained it very well!!
    Any help will be gratefully recieved!!
    Thanks

    I understand why you are having trouble - my own brain started to hurt looking at your questions :)
    First off, database types are not records. They can act like records but are "objects" with different characterstics.
    You can create a record in PL/SQL but the "type" is of RECORD. You created an OBJECT as BODY_PERSON_RECORD_TYPE.
    I don't use database types unless I really need them, such as for working with pipelined functions.
    -- QUESTION 1
    -- The above works fine, but in my real example there are a lot more fields
    -- Why cant I set the local record to the value of the cursor record like this below..
    local_person := select_person_rec; local_person is set to the (misnamed) BODY_PERSON_RECORD_TYPE, while SELECT_PERSON_REC is anchored to the cursor and is a RECORD of SELECT_PERSON%ROWTYPE with a field for each column selected in the query. Different types, not compatible.
    You should be able to manually assign the object items one by one as object.attribute := record.field one field at a time.
    -- QUESTION 2
    --Also how do you update an existing record within the original object, I have tried the following but it does not workCheck the on-line documentation for the syntax. You'll probably have to reference the actual value through the table; this is one reason why I don't work with nested tables - the syntax to do things like updates is much more complex.

  • Help with Oracle Report Builder and SQL Server2000

    Hey guys,
    I just installed it Oracle Developer Suite10g with Report Builder and I am trying to use Report builder and wants to connect with SQL Server 2000. The problem that I am running in to is SQL Server 2000 i have is Window Authentication so Does not required to enter user name and password. So how can i connect my report builder to SQL server or is it possible to connect Report builder to SQL server?
    Also, I want to create small practice version of database in Oracle how do i do it? what i mean by that is I installed trial version or Oracle developer 10g from www.oracle.com and now trying to get some knowledge with oracle. Could any one can give me some direction in this matter please.
    Thank You
    Key

    Have a look at the reports help for the purpose header and trailer sections. Here is an exert:
    "Report sectioning enables you to define multiple layouts in the same report, each with a different target audience, output format, page layout, page size, or orientation. You can define up to three report sections, each with a body area and a margin area: the names of the sections are Header, Main, and Trailer. By default, a report is defined in the Main section. In the other sections, you can define different layouts, rather than creating multiple separate reports. If you wish, you can use the margin and body of the Header and Trailer sections to create a Header and Trailer page for your reports."

  • Need some help with the Table Function Operator

    I'm on OWB 10gR2 for Sun/Solaris 10 going against some 10gR2 DB's...
    I've been searching up and down trying to figure out how to make OWB use a Table Function (TF) which will JOIN with another table; allowing a column of the joined table to be a parameter in to the TF. I can't seem to get it to work. I'm able to get this to work in regular SQL, though. Here's the setup:
    -- Source Table:
    DROP TABLE "ZZZ_ROOM_MASTER_EX";
    CREATE TABLE "ZZZ_ROOM_MASTER_EX"
    ( "ID" NUMBER(8,0),
    "ROOM_NUMBER" VARCHAR2(200),
    "FEATURES" VARCHAR2(4000)
    -- Example Data:
    Insert into ZZZ_ROOM_MASTER_EX (ID,ROOM_NUMBER,FEATURES) values (1,'Room 1',null);
    Insert into ZZZ_ROOM_MASTER_EX (ID,ROOM_NUMBER,FEATURES) values (2,'Room 2',null);
    Insert into ZZZ_ROOM_MASTER_EX (ID,ROOM_NUMBER,FEATURES) values (3,'Room 3','1,1;2,3;');
    Insert into ZZZ_ROOM_MASTER_EX (ID,ROOM_NUMBER,FEATURES) values (4,'Room 4','5,2;5,4;');
    Insert into ZZZ_ROOM_MASTER_EX (ID,ROOM_NUMBER,FEATURES) values (5,'Room 5',' ');
    -- Destination Table:
    DROP TABLE "ZZZ_ROOM_FEATURES_EX";
    CREATE TABLE "ZZZ_ROOM_FEATURES_EX"
    ( "ROOM_NUMBER" VARCHAR2(200),
    "FEATUREID" NUMBER(8,0),
    "QUANTITY" NUMBER(8,0)
    -- Types for output table:
    CREATE OR REPLACE TYPE FK_Row_EX AS OBJECT
    ID NUMBER(8,0),
    QUANTITY NUMBER(8,0)
    CREATE OR REPLACE TYPE FK_Table_EX AS TABLE OF FK_Row_EX;
    -- Package Dec:
    CREATE OR REPLACE
    PACKAGE ZZZ_SANDBOX_EX IS
    FUNCTION UNFK(inputString VARCHAR2) RETURN FK_Table_EX;
    END ZZZ_SANDBOX_EX;
    -- Package Body:
    CREATE OR REPLACE
    PACKAGE BODY ZZZ_SANDBOX_EX IS
    FUNCTION UNFK(inputString VARCHAR2) RETURN FK_Table_EX
    AS
    RETURN_VALUE FK_Table_EX := FK_Table_EX();
    i NUMBER(8,0) := 0;
    BEGIN
    -- TODO: Put some real code in here that will actually read the
    -- input string, parse it out, and put data in to RETURN_VALUE
    WHILE(i < 3) LOOP
    RETURN_VALUE.EXTEND;
    RETURN_VALUE(RETURN_VALUE.LAST) := FK_Row_EX(4, 5);
    i := i + 1;
    END LOOP;
    RETURN RETURN_VALUE;
    END UNFK;
    END ZZZ_SANDBOX_EX;
    I've got a source system built by lazy DBA's and app developers who decided to store foreign keys for many-to-many relationships as delimited structures in driving tables. I need to build a generic table function to parse this data and return it as an actual table. In my example code, I don't actually have the parsing part written yet (I need to see how many different formats the source system uses first) so I just threw in some stub code to generate a few rows of 4's and 5's to return.
    I can get the data from my source table to my destination table using the following SQL statement:
    -- from source table joined with table function
    INSERT INTO ZZZ_ROOM_FEATURES_EX(
    ROOM_NUMBER,
    FEATUREID,
    QUANTITY)
    SELECT
    ZZZ_ROOM_MASTER_EX.ROOM_NUMBER,
    UNFK.ID,
    UNFK.QUANTITY
    FROM
    ZZZ_ROOM_MASTER_EX,
    TABLE(ZZZ_SANDBOX_EX.UNFK(ZZZ_ROOM_MASTER_EX.FEATURES)) UNFK
    Now, the big question is--how do I do this from OWB? I've tried several different variations of my function and settings in OWB to see if I can build a single SELECT statement which joins a regular table with a table function--but none of them seem to work, I end up getting SQL generated that won't compile because it doesn't see the source table right:
    INSERT
    /*+ APPEND PARALLEL("ZZZ_ROOM_FEATURES_EX") */
    INTO
    "ZZZ_ROOM_FEATURES_EX"
    ("ROOM_NUMBER",
    "FEATUREID",
    "QUANTITY")
    (SELECT
    "ZZZ_ROOM_MASTER_EX"."ROOM_NUMBER" "ROOM_NUMBER",
    "INGRP2"."ID" "ID_1",
    "INGRP2"."QUANTITY" "QUANTITY"
    FROM
    (SELECT
    "UNFK"."ID" "ID",
    "UNFK"."QUANTITY" "QUANTITY"
    FROM
    TABLE ( "ZZZ_SANDBOX_EX"."UNFK2" ("ZZZ_ROOM_MASTER_EX"."FEATURES")) "UNFK") "INGRP2",
    "ZZZ_ROOM_MASTER_EX" "ZZZ_ROOM_MASTER_EX"
    As you can see, it's trying to create a sub-query in the FROM clause--causing it to just ask for "ZZZ_ROOM_MASTER_EX"."FEATURES" as an input--which isn't available because it's outside of the sub-query!
    Is this some kind of bug with the code generator or am I doing something seriously wrong here? Any help will be greatly appreciated!

    Hello Everybody!
    Thank you for all your response!
    I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table 
    select vkorg abgru from ZADS into it_rej.
    Earlier :
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    Now :
    DATA : BEGIN OF IT_REJ occurs 0,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    I guess this will fix the issue correct?
    PLease suggest!
    Regards,
    Developer.

  • Need some help with a counting function

    Hello,
    I use a simple sheet to organize the timetable of my patients. Now I'd like to count how many different patients I attend, without counting a patient twice if I attend him twice a week for example. My sheet looks like this:
    Mon
    Tue
    Wed
    Thu
    John
    Steve
    John
    Wesley
    Mary
    Harry
    Deborah
    Peter
    Arnold
    Carol
    Chris
    Mary
    Sarah
    Karen
    Karen
    Carol
    Larry
    Peter
    So the answer would be 13, because I attend 13 different patients a week. Fields in blank should no be counted, the cell contend changes frequently.
    A friend of mine tried to help me with a countif function but it didn't work out for me, it would count the fields left blank too.
    Any idea?
    Thanks, gabriel

    Hi Gabriel,
    Here's another, more generalized, approach that doesn't need adjusting for maximum number of visits/week at the cost of just a few more formulas.  But only two tables!
    Formula in A2 and copied down:
      =ROUNDUP((ROW(cell)−1)÷$B$27,0)
    Formula in B2 and copied down:
      =IF(MOD(ROW(cell)−1,$B$27)=0,$B$27,MOD(ROW(cell)−1,$B$27))
    The formula in C2 and copied down:
      =OFFSET(Schedule::$A$1,0,B−1)
    The formula in D2 and copied down:
      =IFERROR(OFFSET(Schedule::$A$1,A2,B2−1,rows,columns),"")
    The formula in E2 and copied down:
      =IF(AND(D2≠0,LEN(D2)>0),COUNTIF($D$1:D2,D2),"")
    The formula in F2 and copied down:
      =IFERROR(IF(E=1,1,""),"")
    The formula in F27:  =SUM(F)
    The value in B27 is 4, the number of day columns in the Schedule table. You would change that if you increase or decrease the number of days on which you see patients.
    Column C is cosmetic, not needed in the calculation.
    The error triangle means all of the cells in the Schedule table are already accounted for in the rows above.
    Probably more compact ways to do this but it gets the job done.
    SG

  • Need some help with a remove function

    Design and code a program that will maintain a list of product names. Use a String type to represent the product name and an array of strings to implement the list. Your program must implement the following methods:
    Add a product to the list
    Remove a product from the list
    Display then entire list
    Find out if a particular product is on the list.
    You need to create a command command loop with a menu() function. The program must continue asking for input until the user stops.
    This is the assignment and this is what I have so far. I need some help writing the remove function.
    Thanks
    * Title: SimpleSearchableList.java
    * Description: this example will show a reasonably efficient and
    * simple algorithm for rearranging the value in an array
    * in ascending order.
    public class SimpleSearchableList {
         private static String[] List = new String[25]; //These variables (field variables)
         private static int Size; //are common to the entire class, but unavailable
         //except to the methods of the class...
         public static void main(String[] args)
              String Cmd;
              for(;;) {
                   Menu();
                   System.out.print("Command: ");
                   Cmd = SimpleIO.inputString();
                   if(Cmd.equals("Quit"))
                        break;
                   else if(Cmd.equals("Fill"))
                        FillList();
                   else if(Cmd.equals("Search"))
                        SearchList();
                   else if(Cmd.equals("Show"))
                        ShowList();
                   else if(Cmd.equals("Remove"))
                        Remove();
         //Tells you what you can do...
         public static void Menu()
              System.out.println("Choices..................................");
              System.out.println("\tFill to Enter Product");
              System.out.println("\tShow to Show Products");
              System.out.println("\tSearch to Search for Product");
              System.out.println("\tRemove a Product");
              System.out.println("\tQuit");
              System.out.println(".........................................");
         //This method will allow the user to fill an array with values...
         public static void FillList()
              int Count;
              System.out.println("Type Stop to Stop");
              for(Count = 0 ; Count < List.length ; Count++)
                   System.out.print("Enter Product: ");
                   List[Count] = SimpleIO.inputString();
                   if(List[Count].equals("Stop"))
                        break;
              Size = Count;
         //This method will rearrange the values in the array so that
         // go from smallest to largest (ascending) order...
         public static void SearchList()
              String KeyValue;
              boolean NotFoundFlag;
              int Z;
              System.out.println("Enter Product Names Below, Stop To Quit");
              while(true)
                   System.out.print("Enter: ");
                   KeyValue = SimpleIO.inputString();
                   if(KeyValue.equals("Stop")) //Note the use of a method for testing
                        break; // for equality...
                   NotFoundFlag = true; //We'll assume the negative
                   for(Z = 0 ; Z < Size ; Z++)
                        if(List[Z].equals(KeyValue)) {
                             NotFoundFlag = false; //If we fine the name, we'll reset the flag
              System.out.println(List[Z] + " was found");
                   if(NotFoundFlag)
                        System.out.println(KeyValue + " was not found");     
         //This method will display the contents of the array...
         public static void ShowList()
              int Z;
              for(Z = 0 ; Z < Size ; Z++)
                   System.out.println("Product " + (Z+1) + " = " + List[Z]);
         public static void Remove()
    }

    I need help removing a product from the arrayYes. So what's your problem?
    "Doctor, I need help."
    "What's wrong?"
    "I need help!"
    Great.
    By the way, you can't remove anything from an array. You'll have to copy the remaining stuff into a new one, or maybe maintain a list of "empty" slots. Or null the slots and handle that. The first way will be the easiest though.

  • Help with Oracle 9i/10g on RedHat 4?

    If anybody can help would be greatly appreciated...
    I get the same error with Oracle 9i & 10g when installing on Red Hat Fedora 4, it's java related...
    Exception in thread "main" java.lang.UnsatisfiedLinkError: /tmp/OraInstall2007-03-16_01-09PM/jre/lib/i386/libawt.so: connat restore segment prot after reloc: Permission Denied
    Red Hat Fedora is weak on java, it only has the Java 1.4 JRE installed. I tried to upgrade to Sun's JRE 6 but got dependency errors.
    Jon

    Red Hat Fedora 4Does not exist.
    Exception in thread "main" java.lang.UnsatisfiedLinkError: /tmp/OraInstall2007-03-16_01-09PM/jre/lib/i386/libawt.so: connat restore segment prot after reloc: Permission DeniedSolution 1: Modify /etc/selinux/config and change value of SELINUX to "disabled" and reboot computer.
    Solution 2: Upgrade selinux-policy-targeted-1.25.2-4.noarch.rpm (Use command: "yum upgrade selinux-policy-targeted")
    Red Hat Fedora is weak on java, it only has the Java 1.4 JRE installed. I tried to upgrade to Sun's JRE 6 but got dependency errors.??? OUI does not have to do with external JRE.
    Oracle Installation comes with bunled JRE.
    If you are using Fedora then you might consider these articles useful:
    http://ivan.kartik.sk/oracle/install_ora9_fedora.html
    http://ivan.kartik.sk/oracle/install_ora10gR2_fedora.html

  • Help with writing a function

    Hello there
    I got a table with data like this:
    http://www.geocities.com/crisrobin100/ex_input.gif
    This table give me the amount of hours (value) starting in a date I can query from another table according to the owner_id and the amount of consecutive days(Repeats_count) this amount of hours refer to.
    I need to select this table and get something more friendlily so I can sum the hour for each month.
    The result need to look something like this:
    http://www.geocities.com/crisrobin100/ex_output.gif
    How can I do it?
    Chris

    SQL> create table mytable
      2  as
      3  select 30020 owner_id
      4       , 'FORECAST' owner_type
      5       , 0 compressed_entry_seq
      6       , 4 repeats_count
      7       , 8 value
      8    from dual union all
      9  select 30020, 'FORECAST', 1, 2, 0 from dual union all
    10  select 30020, 'FORECAST', 2, 5, 8 from dual union all
    11  select 30020, 'FORECAST', 3, 2, 0 from dual union all
    12  select 30020, 'FORECAST', 4, 5, 8 from dual union all
    13  select 30020, 'FORECAST', 5, 2, 0 from dual union all
    14  select 30020, 'FORECAST', 6, 5, 8 from dual union all
    15  select 30020, 'FORECAST', 7, 3, 0 from dual union all
    16  select 30020, 'FORECAST', 8, 3, 8 from dual
    17  /
    Tabel is aangemaakt.
    SQL> var P_STARTDATE varchar2(8)
    SQL> exec :P_STARTDATE := '01052007'
    PL/SQL-procedure is geslaagd.
    SQL> select owner_id
      2       , owner_type
      3       , d
      4       , value
      5    from mytable t
      6   model
      7         partition by (owner_id,owner_type,compressed_entry_seq)
      8         dimension by (0 i)
      9         measures ( to_date(:P_STARTDATE,'ddmmyyyy')
    10                    + sum(repeats_count) over (partition by owner_id,owner_type order by compressed_entry_seq)
    11                    - repeats_count d
    12                  , repeats_count rc
    13                  , value
    14                  )
    15         rules
    16         ( d[for i from 1 to rc[0]-1 increment 1] = d[0] + cv(i)
    17         , value[i<>0] = value[0]
    18         )
    19   order by owner_id
    20       , owner_type
    21       , d
    22  /
      OWNER_ID OWNER_TY D                        VALUE
         30020 FORECAST 01-05-2007 00:00:00          8
         30020 FORECAST 02-05-2007 00:00:00          8
         30020 FORECAST 03-05-2007 00:00:00          8
         30020 FORECAST 04-05-2007 00:00:00          8
         30020 FORECAST 05-05-2007 00:00:00          0
         30020 FORECAST 06-05-2007 00:00:00          0
         30020 FORECAST 07-05-2007 00:00:00          8
         30020 FORECAST 08-05-2007 00:00:00          8
         30020 FORECAST 09-05-2007 00:00:00          8
         30020 FORECAST 10-05-2007 00:00:00          8
         30020 FORECAST 11-05-2007 00:00:00          8
         30020 FORECAST 12-05-2007 00:00:00          0
         30020 FORECAST 13-05-2007 00:00:00          0
         30020 FORECAST 14-05-2007 00:00:00          8
         30020 FORECAST 15-05-2007 00:00:00          8
         30020 FORECAST 16-05-2007 00:00:00          8
         30020 FORECAST 17-05-2007 00:00:00          8
         30020 FORECAST 18-05-2007 00:00:00          8
         30020 FORECAST 19-05-2007 00:00:00          0
         30020 FORECAST 20-05-2007 00:00:00          0
         30020 FORECAST 21-05-2007 00:00:00          8
         30020 FORECAST 22-05-2007 00:00:00          8
         30020 FORECAST 23-05-2007 00:00:00          8
         30020 FORECAST 24-05-2007 00:00:00          8
         30020 FORECAST 25-05-2007 00:00:00          8
         30020 FORECAST 26-05-2007 00:00:00          0
         30020 FORECAST 27-05-2007 00:00:00          0
         30020 FORECAST 28-05-2007 00:00:00          0
         30020 FORECAST 29-05-2007 00:00:00          8
         30020 FORECAST 30-05-2007 00:00:00          8
         30020 FORECAST 31-05-2007 00:00:00          8
    31 rijen zijn geselecteerd.Regards,
    Rob.
    Message was edited by:
    Rob van Wijk
    Added owner_type to the partition clause of the sum analytic function. Output wasn't affected.

Maybe you are looking for

  • Cheque writer process issue

    In payroll International HRMS i have defined 2 payment methods with 2 different currencies. USD - BG currency KSH - Kenyian Shilling There are 50 employees attached to the USD currency payment method and 800 employees are attached to KSH currency pay

  • How to convert Xstring to PDF format and send pdf to multiple user

    Hi to all can any one provide me saple code to convert Xstring to PDF format and send pdf to multiple user i have searched the SDN , but cant get any proper soulution. I shall be thankful to you for this. Regards Pavneet Rana

  • XE look and feel in Oracle 10g Enterprise Edition

    Hi! I have both Enterprise Edition 10gR2 and XE installed on Linux. I want to use Enterprise Edition as my main database. But I want XE "look and feel" for 10gR2 What do I have to do to accomplish this? regards Paal

  • IPad Air stuck - will I lose images?

    My iPad air seems to be stuck-on screen is the iTunes logo and image of the USB connection cord, when I connect it asks me to RESTORE factory settings, but I will lose all data. I took 800 photo's this week and it also seems my iCloud was not downloa

  • Print out library listing

    Is there a way to get a printout of all the songs in the library?