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

Similar Messages

  • [RESOLVED] Flag Lowest/Leaf Level in multi-dimensions

    Sample Data: http://www.sendspace.com/file/uwjz9p
    Hi,
    I'm having issue by flagging lowest/leaf level for CUBE rollup purpose, due to there's no parent or child relationship parameter table, thus the is_leaf / connect by function cannot be use :(
    However it is pretty obvious to be differentiate because the data is at follow:
    1
    1.2
    1.2.1
    1.2.2
    1.3
    But when mixed up two or more columns it is very hard to flag the lowest level flag.
    LOWEST_FG COL_A COL_B COL_C
    N - 1
    N - 1.2
    Y - 1.2.1 - 1.1
    N - 1.2.1 - 1.2
    Y - 1.2.1 - 1.2.1
    Y - 1.2.1 - 1.2.2
    N - 1.2.1 - 1.2.2 - 1
    Y - 1.2.1 - 1.2.2 - 1.1
    Y - 1.2.1 - 1.2.2 - 1.2
    N - 1.2.1 - 1.2.3
    Y - 1.2.1 - 1.2.3.1
    Y - 1.2.2
    Y - 1.3 - 1.1
    Y - 1.3 - 1.2
    Y - 1.3 - 1.3.1
    Y - 1.3 - 1.3.2
    Y - 1.3 - 1.3.3 - 1.1
    Y - 1.3 - 1.3.3 - 1.2
    Y - 1.3 - - 1.1
    N - 1.3 - - 1.2
    Y - 1.3 - - 1.2.1
    Y - 1.3 - - 1.2.2
    Y - 1.3 - - 1.3.2
    Edited by: Sphenix on 14-Sep-2012 10:16
    Edited by: Sphenix on 14-Sep-2012 10:21
    SAMPLE DATA
    -- DDL for Table SAMPLE_LOWEST_FG_02
    CREATE TABLE "DBO"."SAMPLE_LOWEST_FG_02"
    (     "LVL_ID" VARCHAR2(20 BYTE),
         "CUST_ID" VARCHAR2(10 BYTE),
         "CORP_ID" VARCHAR2(10 BYTE),
         "PURPOSE_ID" VARCHAR2(10 BYTE)
    ) SEGMENT CREATION IMMEDIATE
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
    TABLESPACE "SYSTEM" ;
    SAMPLE DATA
    REM INSERTING into DBO.SAMPLE_LOWEST_FG_02
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'1.1.3.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'1.1.3.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'1.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'3.1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'3.1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'3.1.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'3.1.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'3.1.1.5');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'3.1.1.6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'3.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'3.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'3.2.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'3.2.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'3.2.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'4.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'4.2.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'4.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'4.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'4.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'5.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'5.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'7');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'8');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,'9');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2',null,null);
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2.1',null,null);
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2.2',null,null);
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.2.3',null,null);
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'1.1.3.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'1.1.3.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'1.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'3.1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'3.1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'3.1.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'3.1.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'3.1.1.5');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'3.1.1.6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'3.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'3.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'3.2.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'3.2.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'3.2.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'4.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'4.2.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'4.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'4.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'4.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'5.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'5.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'7');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'8');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,'9');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1',null,null);
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'1.1.3.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'1.1.3.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'1.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'3.1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'3.1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'3.1.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'3.1.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'3.1.1.5');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'3.1.1.6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'3.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'3.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'3.2.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'3.2.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'3.2.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'4.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'4.2.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'4.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'4.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'4.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'5.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'5.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'7');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'8');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,'9');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3',null,null);
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'1.1.3.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'1.1.3.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'1.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'3.1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'3.1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'3.1.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'3.1.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'3.1.1.5');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'3.1.1.6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'3.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'3.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'3.2.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'3.2.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'3.2.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'4.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'4.2.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'4.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'4.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'4.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'5.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'5.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'7');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'8');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,'9');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.1',null,null);
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'1.1.3.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'1.1.3.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'1.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'3.1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'3.1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'3.1.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'3.1.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'3.1.1.5');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'3.1.1.6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'3.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'3.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'3.2.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'3.2.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'3.2.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'4.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'4.2.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'4.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'4.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'4.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'5.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'5.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'7');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'8');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,'9');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.2',null,null);
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'1.1.3.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'1.1.3.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'1.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'3.1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'3.1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'3.1.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'3.1.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'3.1.1.5');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'3.1.1.6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'3.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'3.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'3.2.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'3.2.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'3.2.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'4.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'4.2.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'4.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'4.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'4.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'5.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'5.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'7');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'8');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,'9');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.3.99',null,null);
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.1.99',null,null);
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','1.1.3.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','1.1.3.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','1.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','3.1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','3.1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','3.1.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','3.1.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','3.1.1.5');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','3.1.1.6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','3.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','3.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','3.2.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','3.2.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','3.2.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','4.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','4.2.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','4.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','4.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','4.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','5.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','5.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','7');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','8');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2','9');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2','2',null);
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'1.1.3.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'1.1.3.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'1.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'3.1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'3.1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'3.1.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'3.1.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'3.1.1.5');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'3.1.1.6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'3.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'3.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'3.2.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'3.2.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'3.2.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'4.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'4.2.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'4.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'4.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'4.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'5.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'5.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'7');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'8');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,'9');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2',null,null);
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','1.1.3.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','1.1.3.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','1.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','3.1.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','3.1.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','3.1.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','3.1.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','3.1.1.5');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','3.1.1.6');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','3.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','3.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','3.2.1.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','3.2.1.4');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','3.2.1.99');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','4.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','4.2.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','4.2.1.1');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','4.2.1.2');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','4.3');
    Insert into DBO.SAMPLE_LOWEST_FG_02 (LVL_ID,CUST_ID,CORP_ID,PURPOSE_ID) values ('1.1','1.3.2.2.1','2','5.2');
    Edited by: S

    Hi,
    Sphenix wrote:
    Sample Data: http://www.sendspace.com/file/uwjz9p
    Post the sample data (CREATE TABLE and INSERT statements) and requirements right in your message. If that information is already availabel on some other web page or file, it should be easy for you to copy and paste it.
    Hi,
    I'm having issue by flagging lowest/leaf level for CUBE rollup purpose, due to there's no parent or child relationship parameter table, thus the is_leaf / connect by function cannot be use :(Acutally, the data you posted (if I interpret it correctly) does have a parent-child relationship: '1' is the parent of '1.x' , where x is any number. You could use CONNECT BY and CONNECT_BY_ISLEAF, but I think it will be more efficient to use a semi-join (as shown below) or an EXISTS sub-query.
    However it is pretty obvious to be differentiate because the data is at follow:Different things are obvious to different people. Even if you and I agree that the results are obvious, we might disagree on what those results are. Say what you want.
    I'm guessing you want something like this:
    SELECT     p.*
    FROM          table_x  p
    LEFT OUTER JOIN     table_x      c  ON  c.col_a  LIKE p.col_a || '.%'
                               OR  (    c.col_a  = p.col_a
                            AND  c.col_b  LIKE p.col_b || .%'
                       OR  (    c.col_a  = p.col_a
                            AND  c.col_b  = p.col_b
                        AND  c.col_c  LIKE p.col_c || '.%'
    WHERE   c.col_a  IS NULL
    ;This assumes that col_a can not be NULL.
    If you'd post CREATE TABLE and INSERT statements for the sample data, then I could test this.
    Edited by: Frank Kulash on Sep 14, 2012 5:37 PM

  • SP2-0575: Use of Oracle SQL feature not in SQL92 Entry Level.

    Hi,
    When I tried to login I am able to login but getting the following message:SP2-0575: Use of Oracle SQL feature not in SQL92 Entry Level.
    After loging, when I tried to "SELECT SYSDATE FROM DUAL;" I am getting the following error.
    ORA-00942: table or view does not exist
    Can somebody please help me ?

    this error may be related to glogin.sql files content, what are the outputs for these -
    SQL> describe dual ;
    Name                                      Null?    Type
    DUMMY                                              VARCHAR2(1)
    SQL> select * from dual ;
    D
    Xbest regards.

  • 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>

  • 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

  • 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/

  • 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

  • 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

  • Oracle sql query works

    Can any body tell , how the sql select statement will works ? how it will come across the 3 phases 1.pharse 2.execute and 3. fetch
    what is the parameter in oracle 9i and 10g for compress the dumpfile in export and import?

    Hi,
    Welcome to forums.. !!
    Can any body tell , how the sql select statement will works ? how it will come across the 3 phases 1.pharse 2.execute and 3. fetch Try to refer to : How the select Query Works
    Oracle documentation explains every thing, just spend some time.
    what is the parameter in oracle 9i and 10g for compress the dumpfile in export and import?You must check the Oracle documentation. From high level the compress parameter works different for both versions while allocations the extents.
    - Pavan Kumar N

  • 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]

Maybe you are looking for

  • How do you delete outgoing (SMTP) servers???

    Due to the fact many SMTP servers require you to be on their network to login, I have at varioius times set up 3 different SMTP servers in the mail app setup. The mail app never forgets them once you set them up. It even remembers multiple copies of

  • Os Lion epson printer error

    Macbook Air (new, with Lion) Epson all in one SX600FW connected WiFi With my previous MacBook air, no problem With the new one, the first document of a session i want to print generates an "error" message. The next ones print just fine. I removed and

  • How to put a Dashboard with Prompts in the Cache?

    Hi, I want to make Dashboards more efficiently by putting them in the Cache, but they have defined lot of prompts that can take several values. How should I proceed so as the the cache generated contains data required for this dashboards no matter th

  • Auto-Id Cockpit Link Issue

    Hi I am using SAP AII 4.0. When I open the Auto-Id Cockpit link this error message is displayed 500 Internal Server Error The initial exception that caused the request to fail, was:   com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: Faile

  • Why doesn't the loop exit?

    I have my program prompting the user for a code in letters. System.out.print("Enter Code: "); code = TextIO.getlnString(); code = code.toUpperCase(); //uppercase so I don't have to code for small letters tooFollowing this I'm using a while loop to ch