CONNECT BY LEVEL IN TRIGGER IS IN WAITING STATE

WITH emp_data
     AS (SELECT 1 empno,
                'mgr1' name,
                NULL mgr,
                5 num_of_reportees,
                'Create' Status
           FROM DUAL
         UNION ALL
         SELECT 2,
                'mgr2',
                NULL,
                6,
                'Wait'
           FROM DUAL)
SELECT *
  FROM emp_data;
create sequence emp_data_seq start with 3 increment by 1;
now I want to insert num of employees based on num_of_reportees column in the table for the emp status = 'Create' and below code is doing the same.
INSERT INTO emp_data
   SELECT emp_data_seq.NEXTVAL,
          name,
          NULL,
          NULL,
          NULL
     FROM (    SELECT DISTINCT 'emp' || LEVEL name
                 FROM emp_data
           CONNECT BY LEVEL <= num_of_reportees AND status = 'Create');
Initiall status will be Wait, whenever user changes it from Wait to Create only this operation has to perform, when I place this insert statment in trigger it's not executing and is in waiting state
Could you please let me know how to achieve this requirement using trigger,
I couldn't use the procedure for this requirement, Its a standard application and we are doing customization

SQL> SELECT  *
  2    FROM  emp_data
  3  /
     EMPNO NAME        MGR NUM_OF_REPORTEES STATUS
         1 mgr1                           5 Create
         2 mgr2                           6 Wait
INSERT
  INTO emp_data
  SELECT  emp_data_seq.NEXTVAL,
          'emp' || column_value,
          NULL,
          NULL,
          NULL
    FROM  emp_data,
          TABLE(
                CAST(
                     MULTISET(
                              SELECT  level
                                FROM  dual
                              CONNECT BY LEVEL <= num_of_reportees
                     AS sys.OdciNumberList
    WHERE status = 'Create'
5 rows created.
SQL> SELECT  *
  2    FROM  emp_data
  3  /
     EMPNO NAME        MGR NUM_OF_REPORTEES STATUS
         1 mgr1                           5 Create
         2 mgr2                           6 Wait
         3 emp1
         4 emp2
         5 emp3
         6 emp4
         7 emp5
7 rows selected.
SQL> SY.

Similar Messages

  • SQL Query help ( On connect By level clause)

    Hi all,
    I have this query developed with data in with clause.
    With dat As
      select '@AAA @SSS @DDD' col1 from dual union all
      select '@ZZZ @XXX @TTT @RRR @ZZA' col1 from dual
    Select regexp_substr( col1 , '[^@][A-Z]+',1,level) Show from dat
    connect by level  <= regexp_count(col1, '@');Current output :-
    SHOW
    AAA
    SSS
    DDD
    RRR
    ZZA
    TTT
    RRR
    ZZA
    XXX
    DDD
    RRR
    SHOW
    ZZA
    TTT
    RRR
    ZZA
    . . .1st row comes fine, But next row data is getting duplicated. And total record count = 30. I tried with some but didn't work.
    Expected output :-
    SHOW
    AAA
    SSS
    DDD
    ZZZ
    XXX
    TTT
    RRR
    ZZAI need some change on my query and I am not able to find that. So anybody can add on that or can also provide some different solution too.
    Thanks!
    Ashutosh

    Hi,
    When you use something like "CONNECT BY LEVEL <= x", then at least one of the following must be true:
    (a) the table has no more than 1 row
    (b) there are other conditions in the CONNECT BY clause, or
    (c) you know what you are doing.
    To help see why, run this query
    SELECT     SYS_CONNECT_BY_PATH (dname, '/')     AS path
    ,     LEVEL
    FROM     scott.dept
    CONNECT BY     LEVEL <= 3
    ;and study the results:
    PATH                                     LEVEL
    /ACCOUNTING                                  1
    /ACCOUNTING/ACCOUNTING                       2
    /ACCOUNTING/ACCOUNTING/ACCOUNTING            3
    /ACCOUNTING/ACCOUNTING/RESEARCH              3
    /ACCOUNTING/ACCOUNTING/SALES                 3
    /ACCOUNTING/ACCOUNTING/OPERATIONS            3
    /ACCOUNTING/RESEARCH                         2
    /ACCOUNTING/RESEARCH/ACCOUNTING              3
    /ACCOUNTING/RESEARCH/RESEARCH                3
    /ACCOUNTING/RESEARCH/SALES                   3
    /ACCOUNTING/RESEARCH/OPERATIONS              3
    /ACCOUNTING/SALES                            2
    /ACCOUNTING/SALES/ACCOUNTING                 3
    84 rows selected.

  • Connect by level query is taking too long time to run

    Hello,
    I have a query that returns quarters (YYYYQ) of a begin- and enddate within a specific id, that is built with a connect by level clause, but the query is running to long. I have used explain plan to see what the query is doing, but no silly things to see, just a full table scan, with low costs.
    This is the query:
    select to_char(add_months( cpj.crpj_start_date,3*(level - 1)),'YYYYQ') as sales_quarter
    , cpj.crpj_id as crpj_id
    from mv_gen_cra_projects cpj
    where cpj.crpj_start_date >= to_date('01/01/2009','mm/dd/yyyy')
    and cpj.crpj_start_date <= cpj.crpj_end_date
    and cpj.crpj_routing_type = 'A'
    and ( cpj.crpj_multi_artist_ind = 'N'
    or cpj.crpj_multi_artist_ind is null)
    connect by level <= 1 + ceil(months_between(cpj.crpj_end_date,cpj.crpj_start_date)/3);
    The result have to be like this:
    SALES_QUARTER CRPJ_ID
    20091 100
    20092 100
    20093 100
    20094 100
    20101 100
    20102 100
    Can anyone help me out with this?

    but no silly things to see, just a full table scan, with low costs.Well, maybe an index scan would be faster?
    However:
    You will need to provide us some more details, like:
    - database version (the result of: SQL> select * from v$version;)
    - post the explain plan output (put the tag before and after it, so indentation and formatting are maintained, see the [FAQ|http://forums.oracle.com/forums/help.jspa] for more explanation regarding tags )
    - what are your optimizer settings (the result of: SQL> show parameter optimizer)
    - if applicable: are your table statistics up to date?
    - mv_gen_cra_projects  is a materialized view perhaps?
    Edited by: hoek on Jan 26, 2010 10:50 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Why connect by level isn't working in SQL*Plus?

    This following script isn't working in SQL*Plus, but it working fine in SQL Developer, TOAD, SQL Developer. I've no idea - whats going on here?
    satyaki>
    satyaki>select to_char(add_months(to_date('01-JAN-'||to_char(sysdate,'YYYY'),'DD-MON-YYYY'), level - 1),'MON') mon
      2  from dual
      3  connect by level <= 13;
    MON
    JAN
    satyaki>
    satyaki>Regards.
    Satyaki De.

    Oh! Excellent.
    Yes, now i remembered - William did inform about the buggy nature of old Oracle 9i version.
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production
    PL/SQL Release 9.2.0.1.0 - Production
    CORE    9.2.0.1.0       Production
    TNS for HPUX: Version 9.2.0.1.0 - Production
    NLSRTL Version 9.2.0.1.0 - Production
    satyaki>
    satyaki>
    satyaki>select mon
      2  from (
      3         select to_char(add_months(to_date('01-JAN-'||to_char(sysdate,'YYYY'),'DD-MON-YYYY'), level - 1),'MON') mon
      4         from dual
      5         connect by level <= 12
      6       );
    MON
    JAN
    FEB
    MAR
    APR
    MAY
    JUN
    JUL
    AUG
    SEP
    OCT
    NOV
    MON
    DEC
    12 rows selected.
    satyaki>The reason is my version. Thanks Maxim for pointing this out.
    Regards.
    Satyaki De.

  • I bought elements 13 and downloaded it , but when asked to sign into my adobe account as requested at initial set up of elements 13 , I know my correct password etc and i have a good internet connection But nothing happens even if i wait an hour or so. An

    i bought elements 13 and downloaded it , but when asked to sign into my adobe account as requested at initial set up of elements 13 , I know my correct password etc and i have a good internet connection But nothing happens even if i wait an hour or so. Any help would be appreciated.

    Hi Michael,
    Thanks for posting on the Adobe forums.
    Please follow these steps :
    Go to following location:
    for Win
    C:\Program Files (x86)\Common Files\Adobe
    C:\Users\username\AppData\Local\Adobe
    for MAC
    Finder> Go > Go to Folder
    \Library\Applicaiton Support\Adobe
    ~\Library\Applicaiton Support\Adobe
    Locate folder OOBE and rename it OOBE.old
    Download and install�
    Adobe - Adobe Application Manager : For Windows : Adobe Application Manager
    Adobe - Adobe Application Manager : For Macintosh : Adobe Application Manager
    After the installation
    Try to Open Adobe Application Manager / Creative Cloud App.
    Log in that with Adobe ID and Password.
    If it does not work first try couple of times more.
    Let me know if this resolves the issue.
    Regards,
    Sandeep

  • Connect by level - with multiple inpur rows

    Very simplified I have this table - it has a "table" like structure in varying length.
    I need x output row for each input row (not using pipelined function og PL/SQL)
    Wih only one row as input to the "connect by" - it works of course.
    drop table test3;
    create table test3 (id number, tekst varchar2(20));
    insert into test3 values (1, 'acbdef');
    insert into test3 values (2, '123');
    insert into test3 values (3, 'HUUGHFTT');
    insert into test3 values (4, 'A');
    insert into test3 values (5, 'AKAJKSHKJASHKAJSHJKJ');
    commit;
    with tal as
    select * from
    (select a.*, rownum rn
    from test3 a)
    where rn < 2)
    select tekst, level ,
    substr(tekst,(level-1)*1+1, 1) content
    from tal
    connect by level < length(tekst)
    ;How do I achieve the same thing for multiple input rows ?
    I know I can make in PL/SQL using either plan pl or just a pipelined function, but I prefer a clean SQL if possible.
    I have tried to do it in a cross join test3 and (select various values from dual from the test3 table) and other versions, but all with syntax errors
    with tal as
    select * from
    (select a.*, rownum rn
    from test3 a)
    where rn < 3)
    select * from test3 cross join table
    select tekst, level ,
    substr(tekst,(level-1)*1+1, 1) content
    from dual
    connect by level < length(tekst)
    ;Oracle version will be 10.2 and 11+

    I think this is kind of what you're looking for:
    with tal as
    ( select 1 id, 'acbdef' tekst         from dual union
      select 2   , '123'                  from dual union
      select 3   , 'HUUGHFTT'             from dual union
      select 4   , 'A'                    from dual )
    select  id, tekst, level, substr(tekst,(level-1)*1+1, 1) content
      from  tal
    connect by (    level <= length(tekst)
               and  prior id = id 
               and  prior dbms_random.value is not null
            ID TEKST         LEVEL CONTENT
             1 acbdef            1 a      
             1 acbdef            2 c      
             1 acbdef            3 b      
             1 acbdef            4 d      
             1 acbdef            5 e      
             1 acbdef            6 f      
             2 123               1 1      
             2 123               2 2      
             2 123               3 3      
             3 HUUGHFTT          1 H      
             3 HUUGHFTT          2 U      
             3 HUUGHFTT          3 U      
             3 HUUGHFTT          4 G      
             3 HUUGHFTT          5 H      
             3 HUUGHFTT          6 F      
             3 HUUGHFTT          7 T      
             3 HUUGHFTT          8 T      
             4 A                 1 A      

  • Connect by level with regular expression is consuming more time,

    Oracle 11g R2,
    Dear EXPERTS/GURUS,
    i have a table with 4 columns, say
    ID number,OBJECT_NAME varchar2,OBJECT_MANUFACTURER varchar2,REGIONS varchar2.In the column REGIONS i have information like EMEA,AMERICA,CCC, etc..
    The problem is this column is having redudant copy of same date like EMEA,AMERICA,CCC,EMEA,AMERICA,CCC,EMEA,AMERICA,CCC,EMEA,AMERICA,CCC
    All i want to do is to remove that redundancy, and make as one like EMEA,AMERICA,CCC.
    If i do a query like
    select distinct regexp_substr(REGIONS,'[[:alpha:]]+',1,level),ID,OBJECT_NAME,OBJECT_MANUFACTURER from table_name connect by level<=regexp_count(REGIONS,'[[:alpha:]]+');................ then i can get data as i expected with distinct REGION information, but the heck is this column REGION is having 300 times same copy of data, and more over table is having 10000 records, so the query is not at all completing, even when i tried to limit the query to 1000 rows like where rownum<1001, still query was running for more that 30 Mins.
    I need some query, which do same like above, but with alternative, faster approach.

    902629 wrote:
    Oracle 11g R2,
    Dear EXPERTS/GURUS,
    i have a table with 4 columns, say
    ID number,OBJECT_NAME varchar2,OBJECT_MANUFACTURER varchar2,REGIONS varchar2.In the column REGIONS i have information like EMEA,AMERICA,CCC, etc..
    The problem is this column is having redudant copy of same date like EMEA,AMERICA,CCC,EMEA,AMERICA,CCC,EMEA,AMERICA,CCC,EMEA,AMERICA,CCC
    All i want to do is to remove that redundancy, and make as one like EMEA,AMERICA,CCC.
    If i do a query like
    select distinct regexp_substr(REGIONS,'[[:alpha:]]+',1,level),ID,OBJECT_NAME,OBJECT_MANUFACTURER from table_name connect by level<=regexp_count(REGIONS,'[[:alpha:]]+');................ then i can get data as i expected with distinct REGION information, but the heck is this column REGION is having 300 times same copy of data, and more over table is having 10000 records, so the query is not at all completing, even when i tried to limit the query to 1000 rows like where rownum<1001, still query was running for more that 30 Mins.
    I need some query, which do same like above, but with alternative, faster approach.Sounds like a great time to revisit the data model and fix the design.
    With a sub-optimal design, there's only so much performance you can coax out of anything, at some point it becomes necessary to end the madness and address the source of the problem. Perhaps you've hit that point in time?

  • ORA-01446 Tabular Form with CONNECT BY LEVEL =2

    I created a tabular form where I would like the last 2 lines to be blank so the user can enter new rows immediately (e.g., the first time when no data is found).
    The following is the sql for the tabular form:
    select
    "ID",
    "REQ_ID",
    "QUANTITY",
    "FRAME_SIZE",
    "FRAME_TYPE",
    "PROTECTIVE_COVERING",
    "MATT",
    "MATT_COLOR"
    from "#OWNER#"."CREATIVE_SVC_DESIGN_FRAMING"
    union all
    select
    null id,
    null req_id,
    null quantity,
    null frame_size,
    null frame_type,
    null protective_covering,
    null matt,
    null matt_color
    from dual
    connect by level <= 2 I get the following error:
    failed to parse SQL query:
    ORA-01446: cannot select ROWID from, or sample, a view with DISTINCT, GROUP BY, etc.
    The query is not accessing ROWID from a view at all. And, as you can see, it is not using a DISTINCT, GROUP BY, etc..
    My APEX is Application Express 4.0.2.00.07
    My Database is 10g (10.2.0.5.0)
    Please help!!
    Robert
    http://apexjscss.blogspot.com

    Robert,
    I wish I had a better explanation for you, but I know something new with 4.1 broke this union trick for tabular forms. I had to make a dynamic action that runs on page load and calls the addRow() javascript function instead. I think it has something to do with tabular form validation but I am not sure.
    Cheers,
    Tyson Jouglet

  • How to use CONNECT BY LEVEL to get this result?

    Hi all,
    my DB version is 10gR2.
    here is the table and the data:
    create table t (from_dt date, to_dt date, eno varchar2(2), deptno varchar2(10));
    insert into T values (TO_DATE('2010-01-01','yyyy-mm-dd'),TO_DATE('2010-04-30','yyyy-mm-dd'),'A','DEPTA');
    insert into T valueS (TO_DATE('2010-05-01','yyyy-mm-dd'),TO_DATE('2010-12-31','yyyy-mm-dd'),'A','DEPTB');
    insert into T values (TO_DATE('2010-01-01','yyyy-mm-dd'),TO_DATE('2010-06-30','yyyy-mm-dd'),'B','DEPTA');
    insert into T valueS (TO_DATE('2010-07-01','yyyy-mm-dd'),TO_DATE('2010-12-31','yyyy-mm-dd'),'B','DEPTB');
    from_dt       to_dt           ENO   DEPTNO
    2010-01-01 2010-04-30  A     DEPTA
    2010-05-01 2010-12-31  A     DEPTB
    2010-01-01 2010-06-30  B     DEPTA
    2010-07-01 2010-12-31  B     DEPTBHere is the result I want:
    MONTH    ENO   DEPTNO
    2010-01    A      DEPTA
    2010-02    A      DEPTA
    2010-03    A      DEPTA
    2010-04    A      DEPTA
    2010-05    A      DEPTB
    ...............Here is what I came up with:
    select distinct ADD_MONTHS(TRUNC(FROM_DT,'MON'),level-1) as MONTHS,
           ENO,
           DEPTNO
    from (
        select FROM_DT, TO_DT, ENO, DEPTNO, ROUND(MONTHS_BETWEEN(TO_DT, FROM_DT)) as BET from T
    ) connect by level<=BET
    order by eno, deptno,months ;the problem with this is that, many duplicate rows are generated if I remove DISTINCT from the sql.
    and I don`t know how that happens? How CONNECT BY LEVEL, returns me so many duplicate rows?
    Anyone have any idea about this?
    And is there any other way to do this as well?
    Thanks

    In this case,model clause is one way :-)
    with t(from_dt,to_dt,eno,deptno) as(
    select date '2010-01-01',date '2010-04-30','A','DEPTA' from dual union
    select date '2010-05-01',date '2010-12-31','A','DEPTB' from dual union
    select date '2010-01-01',date '2010-06-30','B','DEPTA' from dual union
    select date '2010-07-01',date '2010-12-31','B','DEPTB' from dual)
    select *
      from t
    model
    partition by(RowNum as PID)
    dimension by(0 as soeji)
    measures(from_dt,to_dt,eno,deptno)
    rules iterate(100)
    UNTIL (add_months(from_dt[0],ITERATION_NUMBER+1) > to_dt[0])
    (from_dt[ITERATION_NUMBER]=add_months(from_dt[0],ITERATION_NUMBER),
    eno[ITERATION_NUMBER]=eno[0],
    deptno[ITERATION_NUMBER]=deptno[0])
    order by eno,from_dt;
    PID  SOEJI  FROM_DT   TO_DT     E  DEPTN
      1      0  10-01-01  10-04-30  A  DEPTA
      1      1  10-02-01  null      A  DEPTA
      1      2  10-03-01  null      A  DEPTA
      1      3  10-04-01  null      A  DEPTA
      3      0  10-05-01  10-12-31  A  DEPTB
      3      1  10-06-01  null      A  DEPTB
      3      2  10-07-01  null      A  DEPTB
      3      3  10-08-01  null      A  DEPTB
      3      4  10-09-01  null      A  DEPTB
      3      5  10-10-01  null      A  DEPTB
      3      6  10-11-01  null      A  DEPTB
      3      7  10-12-01  null      A  DEPTB
      2      0  10-01-01  10-06-30  B  DEPTA
      2      1  10-02-01  null      B  DEPTA
      2      2  10-03-01  null      B  DEPTA
      2      3  10-04-01  null      B  DEPTA
      2      4  10-05-01  null      B  DEPTA
      2      5  10-06-01  null      B  DEPTA
      4      0  10-07-01  10-12-31  B  DEPTB
      4      1  10-08-01  null      B  DEPTB
      4      2  10-09-01  null      B  DEPTB
      4      3  10-10-01  null      B  DEPTB
      4      4  10-11-01  null      B  DEPTB
      4      5  10-12-01  null      B  DEPTB

  • Performance issue with connect by level query

    Hi I have a problem with connect by level in oracle.
    My table is :
    J_USER_CALENDAR
    USER_NAME     FROM_DATE     TO_DATE     COMMENTS
    Uma Shankar     2-Nov-09     5-Nov-09     Comment1
    Veera     11-Nov-09     13-Nov-09     Comment2
    Uma Shankar     15-Dec-09     17-Dec-09     Commnet3
    Vinod     20-Oct-09     21-Oct-09     Comments4
    The above table is the user leave calendar.
    Now I need to display the users who are on leave between 01-Nov-2009 to 30-Nov-2009
    The output should look like:
    USER_NAME     FROM_DATE     COMMENTS
    Uma Shankar     2-Nov-09     Comment1
    Uma Shankar     3-Nov-09     Comment1
    Uma Shankar     4-Nov-09     Comment1
    Uma Shankar     5-Nov-09     Comment1
    Veera     11-Nov-09     Comment2
    Veera     12-Nov-09     Comment2
    Veera     13-Nov-09     Comment2
    For this I have tried with following query , but it is taking too long time to execute.
    select FROM_DATE,user_name,comments from (SELECT distinct FROM_DATE,user_name ,
    comments FROM (SELECT (LEVEL) + FROM_DATE-1 FROM_DATE,TO_DATE, FIRST_NAME||' '|| LAST_NAME
    user_name ,COMMENTS FROM J_USER_CALENDAR
    where
    and J_USER_CALENDAR.IS_DELETED=0
    CONNECT BY LEVEL <= TO_DATE - FROM_DATE+1) a )where (FROM_DATE = '01-Nov-2009' or FROM_DATE = '30-Nov-2009'
    or FROM_DATE between '01-Nov-2009' and '30-Nov-2009') order by from_Date ,lower(user_name)
    Please help me.
    Thanks in advance.
    Regards,
    Phanikanth

    I have not attempted to analyze your SQL statement.
    Here is a test set up:
    CREATE TABLE T1(
      USERNAME VARCHAR2(30),
      FROM_DATE DATE,
      TO_DATE DATE,
      COMMENTS VARCHAR2(100));
    INSERT INTO T1 VALUES ('Uma Shankar', '02-Nov-09','05-Nov-09','Comment1');
    INSERT INTO T1 VALUES ('Veera','11-Nov-09','13-Nov-09','Comment2');
    INSERT INTO T1 VALUES ('Uma Shankar','15-Dec-09','17-Dec-09','Commnet3');
    INSERT INTO T1 VALUES ('Vinod','20-Oct-09','21-Oct-09','Comments4');
    INSERT INTO T1 VALUES ('Mo','20-Oct-09','05-NOV-09','Comments4');
    COMMIT;Note that I included one additional row, where the person starts their vacation in the previous month and ends in the month of November.
    You could approach the problem like this:
    Assume that you would like to list all of the days of a particular month:
    SELECT
      TO_DATE('01-NOV-2009','DD-MON-YYYY')+(ROWNUM-1) MONTH_DAY
    FROM
      DUAL
    CONNECT BY
      LEVEL<=ADD_MONTHS(TO_DATE('01-NOV-2009','DD-MON-YYYY'),1)-TO_DATE('01-NOV-2009','DD-MON-YYYY');Note that the above attempts to calculate the number of days in the month of November - if it is known that the month has a particular number of days, 30 for instance, you could rewrite the CONNECT BY clause like this:
    CONNECT BY
      LEVEL<=30Now, we need to pick up those rows of interest from the table:
    SELECT
    FROM
      T1 T
    WHERE
      (T.FROM_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY')
        OR T.TO_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY'));
    USERNAME        FROM_DATE TO_DATE   COMMENTS
    Uma Shankar     02-NOV-09 05-NOV-09 Comment1
    Veera           11-NOV-09 13-NOV-09 Comment2
    Mo              20-OCT-09 05-NOV-09 Comments4If we then join the two resultsets, we have the following query:
    SELECT
    FROM
      T1 T,
      (SELECT
        TO_DATE('01-NOV-2009','DD-MON-YYYY')+(ROWNUM-1) MONTH_DAY
      FROM
        DUAL
      CONNECT BY
        LEVEL<=ADD_MONTHS(TO_DATE('01-NOV-2009','DD-MON-YYYY'),1)-TO_DATE('01-NOV-2009','DD-MON-YYYY')) V
    WHERE
      (T.FROM_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY')
        OR T.TO_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY'))
      AND V.MONTH_DAY BETWEEN T.FROM_DATE AND T.TO_DATE
    ORDER BY
      USERNAME,
      MONTH_DAY;
    USERNAME        FROM_DATE TO_DATE   COMMENTS   MONTH_DAY
    Mo              20-OCT-09 05-NOV-09 Comments4  01-NOV-09
    Mo              20-OCT-09 05-NOV-09 Comments4  02-NOV-09
    Mo              20-OCT-09 05-NOV-09 Comments4  03-NOV-09
    Mo              20-OCT-09 05-NOV-09 Comments4  04-NOV-09
    Mo              20-OCT-09 05-NOV-09 Comments4  05-NOV-09
    Uma Shankar     02-NOV-09 05-NOV-09 Comment1   02-NOV-09
    Uma Shankar     02-NOV-09 05-NOV-09 Comment1   03-NOV-09
    Uma Shankar     02-NOV-09 05-NOV-09 Comment1   04-NOV-09
    Uma Shankar     02-NOV-09 05-NOV-09 Comment1   05-NOV-09
    Veera           11-NOV-09 13-NOV-09 Comment2   11-NOV-09
    Veera           11-NOV-09 13-NOV-09 Comment2   12-NOV-09
    Veera           11-NOV-09 13-NOV-09 Comment2   13-NOV-09Charles Hooper
    IT Manager/Oracle DBA
    K&M Machine-Fabricating, Inc.

  • Problem with connect  by level

    Hi,
    My requiremet goes some thing like this : I would like to generate the dates from hiredate to systdate with a gap of one month.The code which I have return works good for single empno . I want to generate the dates from hiredate to sysdate with a gap
    of one month for all the employees(empno). commenting the code for where empno = 7369 does not work and the system a lot of CPU usage.
    Assume hiredate to be to_date('01-jan-10') for empno = 7369
    sample codes goes something like this:
    select ADD_MONTHS(trunc(to_date('01-jan-10')),LEVEL-1)
    from dual
    connect by level <= trunc((sysdate-to_Date('01-jan-10'))/30 )code for emp table
    select ADD_MONTHS(trunc(hiredate),LEVEL-1)
    from employee
    where empno = 7369
    connect by level <= trunc((sysdate-trunc(hiredate))/30 )Please advice

    Based on emp table, something like this...
    SQL> ed
    Wrote file afiedt.buf
      1  with emps as (select * from emp where deptno = 10)
      2      ,uppr as (select to_date('31/12/1982','DD/MM/YYYY') as dt from dual)
      3  -- END OF TEST DATA
      4  select empno, ename, add_months(hiredate,rn-1) as dt
      5  from emps, uppr
      6      ,(select rownum rn from dual connect by rownum <= (select max(dt-hiredate) from emps,uppr))
      7  where add_months(hiredate,rn-1) <= uppr.dt
      8* order by empno, rn
    SQL> /
         EMPNO ENAME      DT
          7782 CLARK      09/06/1981 00:00:00
          7782 CLARK      09/07/1981 00:00:00
          7782 CLARK      09/08/1981 00:00:00
          7782 CLARK      09/09/1981 00:00:00
          7782 CLARK      09/10/1981 00:00:00
          7782 CLARK      09/11/1981 00:00:00
          7782 CLARK      09/12/1981 00:00:00
          7782 CLARK      09/01/1982 00:00:00
          7782 CLARK      09/02/1982 00:00:00
          7782 CLARK      09/03/1982 00:00:00
          7782 CLARK      09/04/1982 00:00:00
          7782 CLARK      09/05/1982 00:00:00
          7782 CLARK      09/06/1982 00:00:00
          7782 CLARK      09/07/1982 00:00:00
          7782 CLARK      09/08/1982 00:00:00
          7782 CLARK      09/09/1982 00:00:00
          7782 CLARK      09/10/1982 00:00:00
          7782 CLARK      09/11/1982 00:00:00
          7782 CLARK      09/12/1982 00:00:00
          7839 KING       17/11/1981 00:00:00
          7839 KING       17/12/1981 00:00:00
          7839 KING       17/01/1982 00:00:00
          7839 KING       17/02/1982 00:00:00
          7839 KING       17/03/1982 00:00:00
          7839 KING       17/04/1982 00:00:00
          7839 KING       17/05/1982 00:00:00
          7839 KING       17/06/1982 00:00:00
          7839 KING       17/07/1982 00:00:00
          7839 KING       17/08/1982 00:00:00
          7839 KING       17/09/1982 00:00:00
          7839 KING       17/10/1982 00:00:00
          7839 KING       17/11/1982 00:00:00
          7839 KING       17/12/1982 00:00:00
          7934 MILLER     23/01/1982 00:00:00
          7934 MILLER     23/02/1982 00:00:00
          7934 MILLER     23/03/1982 00:00:00
          7934 MILLER     23/04/1982 00:00:00
          7934 MILLER     23/05/1982 00:00:00
          7934 MILLER     23/06/1982 00:00:00
          7934 MILLER     23/07/1982 00:00:00
          7934 MILLER     23/08/1982 00:00:00
          7934 MILLER     23/09/1982 00:00:00
          7934 MILLER     23/10/1982 00:00:00
          7934 MILLER     23/11/1982 00:00:00
          7934 MILLER     23/12/1982 00:00:00
    45 rows selected.
    SQL>(I limited the upper date to 31/12/1982 rather than sysdate as I didn't want too much data... :D)

  • Access a Connect By Level variable from subquery

       With curr_date_details as
        select   to_date('16-dec-09', 'dd-mon-yy') as businessdate 
              ,  trunc( to_date('16-dec-09', 'dd-mon-yy'), 'iw') as bow
              ,  to_date('23-nov-09', 'dd-mon-yy')  as bop
              ,  trunc(to_date('23-nov-09', 'dd-mon-yy'),'iy')  as boy   
              ,  3 as week_nbr
              ,  3 as per_week_nbr
              ,  12 as per_nbr
       from dual
       select  --== Week Number
                  case when level <= date_rec.per_week_nbr
                     then  level
                     when level = date_rec.per_week_nbr  + 1
                    then 6
                    when level = date_rec.per_week_nbr   + 2
                    then  7
                        when level = date_rec.per_week_nbr   + 3
                    then  0
                end as week_nbr
                --== Start Date
              , case when level <= date_rec.per_week_nbr
                     then  to_date('23-nov-23', 'dd-mon-rr')
                     when level = date_rec.per_week_nbr  + 1
                    then  date_rec.bop
                    when level = date_rec.per_week_nbr   + 2
                    then  date_rec.boy  
                         when level = date_rec.per_week_nbr   + 3
                    then  date_rec.boy  
                end as start_date
                --== End Date
               , case
                    when level <= date_rec.per_week_nbr
                    then   to_date('23-nov-23', 'dd-mon-rr')  + 6  
                      when level = date_rec.per_week_nbr  + 1
                    then  date_rec.bow + 6
                     when level = date_rec.per_week_nbr  + 2
                    then  date_rec.bow + 6
                            when level = date_rec.per_week_nbr   + 3
                    then  date_rec.bop - 1  
                 end as end_date
              --=== Dummy Column
              , case
                    when level <= date_rec.per_week_nbr
                    then ( select 1 + level as t  from dual)
                    else  100
                end as pesky_column
          from dual mydual
          inner join curr_date_details date_rec on  date_rec.businessdate = to_date('16-dec-09', 'dd-mon-yy')
          connect by level <= date_rec.per_week_nbr  + 3gives me error:
    Error at Command Line:9 Column:2
    Error report:
    SQL Error: ORA-01788: CONNECT BY clause required in this query block
    01788. 00000 - "CONNECT BY clause required in this query block"
    *Cause:   
    *Action:
    How can i access variable from subquery?
    this question was taken from another post
    Having trouble selecting from a table function

    Hi,
    Using a joiin:
    WITH     connect_by_query AS
       select  --== Week Number
                  case when level <= date_rec.per_week_nbr
                     then  level
                     when level = date_rec.per_week_nbr  + 1
                    then 6
                    when level = date_rec.per_week_nbr   + 2
                    then  7
                        when level = date_rec.per_week_nbr   + 3
                    then  0
                end as week_nbr
               --=== Dummy Column
           , LEVEL     AS lvl
           , per_week_nbr
          from curr_date_details date_rec
          connect by level <= date_rec.per_week_nbr  + 3
    SELECT       cb.week_nbr
    ,       case
                    when  cb.lvl <= cb.per_week_nbr
                    then  NVL (sd.sales, 0)
                    else  100
                end as pesky_column
    FROM           connect_by_query     cb
    LEFT OUTER JOIN      sample_data          sd     ON     sd.datakey = cb.lvl
    ORDER BY  cb.lvl
    ;You could also compute week_nbr in the main query, rather than the sub-query.
    Using a scalar sub-query:
    WITH     connect_by_query AS
       select  --== Week Number
                  case when level <= date_rec.per_week_nbr
                     then  level
                     when level = date_rec.per_week_nbr  + 1
                    then 6
                    when level = date_rec.per_week_nbr   + 2
                    then  7
                        when level = date_rec.per_week_nbr   + 3
                    then  0
                end as week_nbr
               --=== Dummy Column
           , LEVEL     AS lvl
           , per_week_nbr
          from curr_date_details date_rec
          connect by level <= date_rec.per_week_nbr  + 3
    SELECT       week_nbr
    ,       case
                    when lvl <= per_week_nbr
                    then NVL ( ( select sales from sample_data where datakey = lvl)
                    , 0
                    else  100
                end as pesky_column
    FROM       connect_by_query
    ORDER BY  lvl
    ;Notice that the sub-query connect_by_query is the same in both cases.

  • Problm with 'Connect By Level'

    If I issue a query like :
    select level x from dual connect by level < 30;
    Then I only get a maximum of ten rows back.
    If I wrap the query like this:
    select * from (select level x from dual connect by level < 30);
    Then I get the full rowset back.
    Version Details:
    select * from v$version;
    Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
    PL/SQL Release 9.2.0.4.0 - Production
    CORE     9.2.0.3.0     Production
    TNS for Linux: Version 9.2.0.4.0 - Production
    NLSRTL Version 9.2.0.4.0 - Production
    Sql Developer Version 1.0.0.15.27
    Build MAIN-15.27

    This got raised on AskTom sometime,
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:40476301944675
    The behaviour changed depending on the client, and there was a lot of debate where the fault lay (SQL*Plus, OCI, DB server)
    Don't know whether it ever got resolved in a patchset.
    Maybe Note 185438.1 is relevant (don't have metalink access so can't check).
    "The first statement only works correctly in 10g. "
    There's nothing in the documentation supporting this construct, and the documentation indicates that any hierachial query (ie one with a CONNECT BY) should have a PRIOR operator.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries003.htm#i2053935
    As such, I'd argue that the 'correct' (or at least documented) behaviour would be an error.
    Message was edited by:
    g.myers

  • Convert Oracle "connect by level 10" into MS SQL server 2005

    I want to convert oracle "SELECT LEVEL R FROM CONNECT BY LEVEL <=10" my bottom requirement is  get 1 to 10 as a dynamic table inside a query.
    Ex: Select id, name, R from names N, (1,2,3,4,5,6,7,8,9,10) R WHERE id < 1000 
    If any one know something regarding this please reply me.
    Thx,
    Buddhika

    Hi Buddhika Jayawardhane ,
    Have you sold your problem? I have the same issue to convert from Oracle into SQL Server:
    SELECT all_steps.to_step_id step_id, rownum step_order
    FROM (
    SElECT 0 from_step_id, steps.step_id to_step_id
    FROM steps
    WHERE steps.is_root = 1
    UNION
    SElECT step_transitions.from_step_id, step_transitions.to_step_id
    FROM step_transitions
    ) all_steps
    CONNECT BY all_steps.from_step_id = PRIOR all_steps.to_step_id
    START WITH all_steps.from_step_id = 0
    Please help me find information how to make it!
    Thanks in advance,
    cores

  • Using CONNECT BY LEVEL with For Loop Doesn't Work

    The procedure listed below inserts only one record in table whereas i need 10 records to be inserted in table.
    this is just a test procedure..
    CREATE OR REPLACE PROCEDURE P_TEST
    AS
    BEGIN
    FOR I IN (SELECT LEVEL num FROM dual CONNECT BY LEVEL <= 10)
    LOOP
    INSERT INTO TEMP_VMS VALUES(I.num);
    END LOOP;
    END;
    END;
    /

    Salim Chelabi  wrote:
    Or with 9ir2
    INSERT INTO TEMP_VMS
    SELECT COLUMN_VALUE
    FROM TABLE (SYS.dbms_debug_vc2coll (24, 34, 25));
    SELECT *
    FROM TABLE (SYS.dbms_debug_vc2coll (24, 34, 25));
    COLUMN_VALUE                                                                   
    24                                                                             
    34                                                                             
    25                                                                             
    3 rows selected.
    http://laurentschneider.com/wordpress/2007/12/predefined-collections.html
    That doesn't split strings...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'a,b,c,d,e' str from dual)
      2  --
      3  SELECT *
      4*   FROM t, TABLE (SYS.dbms_debug_vc2coll (t.str))
    SQL> /
    STR
    COLUMN_VALUE
    a,b,c,d,e
    a,b,c,d,e... it only defines a table of values

Maybe you are looking for

  • Sending/receiving files using SFTP

    Hi, Is there a way to use the Secure File Transfer Protocol (SFTP) in ABAP to send/receive files? I already used the FTP functionality from the function group SFTP, but I'm honestly not sure whether ABAP also handles the secure version of FTP. If the

  • Add ons tool bar and tabs disappeared when opened closed browser.

    I have deleted and re-installed 17.01 three times now. The first time was to get into my bank site. The second because I still was having problems with downloading. My browser has been working well for about a couple of weeks. I was using the browser

  • Creating a global layout in CO03

    Hi Expert, Can anyone tell me what authorizations/Parameter IDs are required to create a global variant in transaction CO03 -> goto Costs -> Analysis ? I can create and save a layout that is user-specific, but I cannot make it global. Any ideas? I al

  • Captions in metadata

    If I write captions in Aperture is there any way to have iWeb show them up as captions (instead of it using the title of the image)? Thanks.

  • How to lock ad. website in safari?

    Hello! I want to know how to block advertisement websitr in safai? Please help me.