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      

Similar Messages

  • JSP FORMS WITH MULTIPLE INPUT ROWS

    HI,
    I NEED USE A FORM IN JSP WITH MULTIPLE INPUT ROWS TO IMPLEMENT A SALES ITEM PROGRAM.
    I HAVE TRIED WITH INSTRUCTIONS -- WHILE AND DO.. WHILE -- BUT TOMCAT 4.0 DOES NOT PROCESS THEM CORRECTLY BECAUSE IS IN A DEAD LOCK.
    ANY BODY CAN HELP ME?

    Thank you. But i don?t use caps lock. My program look like this:
    <form method="pos" action="echo.jsp">
    <table align="center" cellpadding="0" cellspacing="0" border="1" width="100%" bgcolor="#ffffff">
    <tr>
    <th class="titulo3">C?digo</th>
    <th class="titulo3">Descripci?n</th>
    <th class="titulo3">Nivel seguridad</th>
    <th class="titulo3">Moldes</th>
    <th class="titulo3">j</th>
    </tr>
    <%
    do {                    
    %>                                   
    <tr>
    <td class="titulo3">
    <input name="codigo" type="text" size="10" maxlength="10">               
    </td>
    <td class="titulo3">
    <input name="nombre" type="text" size="30" maxlength="100">               
    </td>          
    <td class="titulo3">
    <SELECT NAME="codopc" >                         
         <OPTION VALUE="nivel1"> Nivel 1                
         <OPTION VALUE="nivel2"> Nivel 2      
         <OPTION VALUE="nivel3"> Nivel 3
         <OPTION VALUE="nivel4"> Nivel 4
         <OPTION VALUE="nivel5"> Nivel 5           
    </SELECT>                                    
    </td>     
    <td class="titulo3">
    <input name="moldes" type="checkbox" size="30" maxlength="20">          
    </td>     
    <td class="titulo3">
    <input name="moldes" type="text" size="10" maxlength="20" value="<%= j %>">     
    </td>                                   
    </tr>               
    <%
    } while ( newlines );
    %>                                        
    </table>
    ....... more code about submit and clear buttons...
    </form>

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

  • 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

  • Connecting MG3570 printer with multiple MAC books

    I connected MG3570 printer with my Mac book wirelessly. Everything fine till my son also connect the printer with his Mac book. My computer can not connect so I started set up again and connect it. Then my son can not connect again. What should we do to be able to connect all Mac books to printer? thanks

    You might want to look at this article on troubleshooting Mag Safe adaptors:
    http://support.apple.com/kb/TS1713
    Check for things like stuck pins.
    Also, be sure that you are not mixing up the MacBook charger (65 watts) with the MacBook Pro charger (85 watts). The MBP charger should be able to charge the MB, but not the other way around.
    If the charger is good and the battery and its connections are good, then it is possible that the Left I/O Board (which contains the power port) is bad.
    For the battery to charge, three things have to be working--the charger, the battery, and the Left I/O Board. If you have access to an Apple Store, the genius bar should be able to try a known good battery and a known good power adaptor and be able to pinpoint what is really at fault.
    Good luck!

  • Business Contact Manager 2010 - is it possible to connect a Contact with multiple Accounts

    Hi, I'm proficient with Outlook but new to BCM. Currently setting things up but have some Contacts who own more than one company or are on another companies Board etc.  
    My questions is - Is it possible to connect a Contact to more than one Account?
    Many thanks

    Hi,
    Currently it's not possible. The workaround may be to duplicate the contact in Business Contacts to make that happen.
    Regards,
    Melon Chen
    TechNet Community Support

  • How to Connect crystal report with multiple databases?

    I Think my question is really clear
    I ask this because i think i already used every way logic in my head
    ConnectionInfo
    IConnectionInfo
    PropertyBag
    DataDefModel
    Etc
    i found Ludek's post about "Ras Connection Info Code" i think this will solve my case but still no luck 
    Dear Ludek i try your suggestion from here  Until the "Ras Connection Info Code" give an Error
    See the end of this message for details on invoking
    just-in-time (JIT) debugging instead of this dialog box.
    ************** Exception Text **************
    System.IndexOutOfRangeException: Index was outside the bounds of the array.
       at CodeBuilder_RasConnectionInfo.frmRasConnectionInfo.VBConnectionCode(ReportDocument boReportDocument) in C:\Reza\Development\CodeBuilder-RasConnectionInfo\Form1.vb:line 183
       at CodeBuilder_RasConnectionInfo.frmRasConnectionInfo.btnLoadReport_Click(Object sender, EventArgs e) in C:\Reza\Development\CodeBuilder-RasConnectionInfo\Form1.vb:line 16
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    ************** Loaded Assemblies **************
    mscorlib
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
    CodeBuilder-RasConnectionInfo
        Assembly Version: 1.0.0.0
        Win32 Version: 1.0.0.0
        CodeBase: file:///C:/Reza/Development/CodeBuilder-RasConnectionInfo/bin/Debug/CodeBuilder-RasConnectionInfo.exe
    Microsoft.VisualBasic
        Assembly Version: 8.0.0.0
        Win32 Version: 8.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
    System
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
    System.Windows.Forms
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    System.Drawing
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    System.Configuration
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    System.Xml
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
    System.Runtime.Remoting
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
    CrystalDecisions.CrystalReports.Engine
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.0.99
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.CrystalReports.Engine/13.0.2000.0__692fbea5521e1304/CrystalDecisions.CrystalReports.Engine.dll
    CrystalDecisions.Shared
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.0.99
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.Shared/13.0.2000.0__692fbea5521e1304/CrystalDecisions.Shared.dll
    CrystalDecisions.ReportAppServer.CommLayer
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.0.99
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.CommLayer/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.CommLayer.dll
    CrystalDecisions.ReportAppServer.ClientDoc
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.0.99
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.ClientDoc/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.ClientDoc.dll
    System.Data
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
    CrystalDecisions.ReportAppServer.Controllers
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.0.99
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.Controllers/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.Controllers.dll
    CrystalDecisions.ReportAppServer.DataDefModel
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.0.99
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.DataDefModel/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.DataDefModel.dll
    CrystalDecisions.ReportAppServer.DataSetConversion
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.0.99
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.DataSetConversion/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.DataSetConversion.dll
    CrystalDecisions.ReportAppServer.CubeDefModel
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.0.99
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.CubeDefModel/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.CubeDefModel.dll
    CrystalDecisions.ReportAppServer.ReportDefModel
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.0.99
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.ReportDefModel/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.ReportDefModel.dll
    log4net
        Assembly Version: 1.2.10.0
        Win32 Version: 1.2.10.0
        CodeBase: file:///C:/Windows/assembly/GAC_32/log4net/1.2.10.0__692fbea5521e1304/log4net.dll
    System.Web
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_32/System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll
    CustomMarshalers
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_32/CustomMarshalers/2.0.0.0__b03f5f7f11d50a3a/CustomMarshalers.dll
    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.
    For example:
    <configuration>
        <system.windows.forms jitDebugging="true" />
    </configuration>
    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.
    i don't know what happen
    is there any way to solve my case??
    actually i only need 3 databases connected in my report
    in each databases i insert about 3 - 8 command
    i'm using VS2010 Ultimate
    CR Version=13.0.2000.0 (ASP.Net)
    SQL Server Standard Edition 10.50.2500.0
    and
    SQL Server Standard Edition 10.50.1600.1 to test move the datasources
    can someone give me an enlightment about my case
    every suggestion would be great
    Thanks
    Zeal

    Just as an FYI. there is a utility that will actually write the code out for you. See KBA 1553921 - Is there a utility that would help in writing database logon code?
    - Ludek
    Senior Support Engineer AGS Product Support, Global Support Center Canada
    Follow us on Twitter

  • Problem with multiple table row selection

    Hi all
           I have a rfc which fetches me a bunch of records and displays them in a table,say A.
           I have to select multiple records from this table and hit a button to navigate to next screen..where I will review the selected entries from table A..
           Cardinality is 0..N,Selection cardinality is 1..N.
    and selection mode as "multi"
    But I am not able to select multiple entries in tableA..
    Pl send me some sample code which would help me solving this issue...
    Thanks in advance

    hi,
    this is the code i have written.
    int size = wdContext.nodeHeader().size();
           IPrivateGetView.IItemElement e1 = wdContext.createItemElement("instance");
           for(int i=0;i<size;i++)
           if(wdContext.nodeHeader().isMultiSelected(i))
               e1.setDel(wdContext.nodeHeader().getHeaderElementAt(i).getDel());
                wdContext.nodeItem().addElement(e1);
    // i am trying to add the selected rows from one table to another table.
    By using above logic i couldn't select more than one row.
    Can u help me how to select more than one row and add them to another table.
    Thanks in advance.

  • Compare of 2 tables with multiple output rows???

    I have two table which hold port and process information from a network scan.  One table is a baseline and the other is a recent scan.  The tables contain the ports and services from all the systems scanned for each system.  
    I need to compare the two tables and show what the difference is.  One report showing just the unique ports not in the baseline and another to show a complete list of all the ports not in the baseline and the associated computer name.  I need both
    the reports to be able to show if the difference is a port that was in the baseline that is not in the new scan or is a new port not in the baseline.
    Here are the table formats I have:
    Baseline
    Date
    Plant
    ComputerName
    Protocol
    LocalAddress
    LocalPort
    RemoteAddress
    RemotePort
    State
    ProcessName
    Scan
    Date
    Plant
    ComputerName
    Protocol
    LocalAddress
    LocalPort
    RemoteAddress
    RemotePort
    State
    ProcessName

    tablediff:- Just find the tablediff.exe and change the sourceserver,source database  -sourcetable and same thing you need to do it for destination.
    Interchange it for the second run
    C:\Program Files\Microsoft SQL Server\100\COM>tablediff.exe -SourceServer hqvd0026\kat -SourceDatabase dssp -sourcetable Baseline -DestinationServer hqvd0026\kat -DestinationDatabase dssp -destinationtable Scan -c -f c:\tablediff.sql
    OR 
    A=A-B
    The following query returns any distinct values from the query to the left of the EXCEPT operand
    that are not also found on the right query.
    select * from dbo.baseline
    except
    select * from dbo.scan
    The following query returns any distinct values that are returned by both the query on the left and right sides of the INTERSECT operand.
    select * from dbo.baseline
    INTERSECT
    select * from dbo.scan
    -Prashanth

  • Connect By with too many rows

    Hello,
    I have a table of contracts. Each can have different intervalls of payment: M monthly, Q quaterly, Y yearly or E single payment.
    Now I want a select that shows all dates from begin to maturity (duration) when the collection of outstanding accounts takes place.
    DROP TABLE contract;
    CREATE TABLE contract (
         nr             NUMBER (5)
        ,dat_begin      DATE
        ,invoiced       VARCHAR(1)
        ,duration       NUMBER(5)
    INSERT INTO contract (nr,dat_begin,invoiced,duration)
        VALUES (345,TO_DATE('01.01.2008','dd.mm.yyyy'),'M',1);
    --INSERT INTO contract (nr,dat_begin,invoiced,duration)
    --    VALUES (456,TO_DATE('01.01.2008','dd.mm.yyyy'),'Q',2);
    INSERT INTO contract (nr,dat_begin,invoiced,duration)
        VALUES (567,TO_DATE('01.01.2007','dd.mm.yyyy'),'Y',1);
    --INSERT INTO contract (nr,dat_begin,invoiced,duration)
    --    VALUES (678,TO_DATE('01.01.2008','dd.mm.yyyy'),'E',2);
    WITH
    first_month AS(
        SELECT  TRUNC(dat_begin,'MM') AS first_date
               ,nr
               ,DECODE (invoiced
                        ,'M',1
                        ,'Q',3
                        ,'Y',12
                        ,'E',1000
                        ) AS intervall
               ,duration
        FROM    contract
    SELECT  ADD_MONTHS(first_date,(LEVEL - 1) * intervall)  AS all_dates
           ,nr
           ,duration
           ,intervall
           ,CONNECT_BY_ROOT nr
    FROM    first_month
    CONNECT BY  LEVEL <= duration * 12 / intervallNow I expect to get 12 dates for contract 345 and one for 567. But...
    ALL_DATE   NR DURATION INTERVALL LEVEL CONNECT_BY_ROOTNR
    01.01.08  345        1         1     1               345
    01.02.08  345        1         1     2               345
    01.03.08  345        1         1     3               345
    01.04.08  345        1         1     4               345
    01.05.08  345        1         1     5               345
    01.06.08  345        1         1     6               345
    01.07.08  345        1         1     7               345
    01.08.08  345        1         1     8               345
    01.09.08  345        1         1     9               345
    01.10.08  345        1         1    10               345
    01.11.08  345        1         1    11               345
    01.12.08  345        1         1    12               345
    01.01.07  567        1        12     1               567
    01.02.08  345        1         1     2               567
    01.03.08  345        1         1     3               567
    01.04.08  345        1         1     4               567
    01.05.08  345        1         1     5               567
    01.06.08  345        1         1     6               567
    01.07.08  345        1         1     7               567
    01.08.08  345        1         1     8               567
    01.09.08  345        1         1     9               567
    01.10.08  345        1         1    10               567
    01.11.08  345        1         1    11               567
    01.12.08  345        1         1    12               567every row after row 13 '01.01.07 567' I didn't expect.
    Of course I can add a predicate CONNECT_BY_ROOT = NR. But I would like to understand why I get 11 rows for nr 345 with root 567.
    Regards
    Marcus

    Hi,
    In a counter sub-query, where you use "CONNECT BY LEVEL < x" to generate the integers 1, 2, ..., x, the table
    in the FROM-clause must have only one row.
    Do this:
    WITH
    first_month AS(
        SELECT  TRUNC(dat_begin,'MM') AS first_date
               ,nr
               ,DECODE (invoiced
                        ,'M',1
                        ,'Q',3
                        ,'Y',12
                        ,'E',1000
                        ) AS intervall
               ,duration
               ,cntr.n
        FROM    contract
    cntr AS
    (   -- Begin counter sub-query
        SELECT  LEVEL   AS n
        FROM    dual
        CONNECT BY  LEVEL <=
         (     -- Begin scalar sub-query to get max range
         SELECT     MAX (duration * 12 / intervall)
         FROM     first_month
         )     -- End scalar sub-query to get max range
    )   -- End counter sub-query
    SELECT  ADD_MONTHS(first_date,(cntr.n - 1) * intervall)  AS all_dates
           ,nr
           ,duration
           ,intervall FROM    first_month
    JOIN     cntr          ON cntr.n <= duration * 12 / intervall
    ;As you can see, this solution is very similar to Blushadow's.
    "CONNECT BY" implies a parent-child relationship.
    When the CONNECT BY condition does not refer to any values stored in the table, as in "CONNECT BY LEVEL <= x",
    then every row in the table will be considered the parent of every other row. So if you have J rows in the table,
    you will have J rows at LEVEL=1, J*J rows at LEVEL=2, J*J*J rows at LEVEL=3, ..., POWER (j, k) rows at LEVEL=k.
    I don't think the query you posted produced the results you posted.
    The query has five columns in the SELECT-clause, but the result set has six.
    What is the purpose of the last column, with CONNECT_BY_ROOT? If it's supposed to be the same as nr,
    then you can have another column containing nr.

  • Find average at group level of multiple grouped fields

    Can this not be done in Crystal
    I am trying to total and average at the group level like this:
    ((Sum ({@Unscheduled}, {@monthName}))/(Sum ({@total}, {@monthName}))*100)
    --  {@Unscheduled} =           if ({Table_Name.status} = "Unscheduled" and not({Table_Name.StartDate}>= currentdate))
    then 1
    I am grouping by month. The formula {@Unscheduled} gave me the total for each month of that ticket type and I was able to sum 3 other ticket types and sum total of all ticket types. But when I try to find the average of each with this
    ((Sum ({@Unscheduled}, {@monthName}))/(Sum ({@total}, {@monthName}))*100)
    I get an error saying division canu2019t be done with zero, but there are no zeros  when shown separately on the report.
    I guess my question is Can you not perform calculations at the group level with multiple fields.
    Any insight would be appreciated and I apologize if this is somewhat incoherent.

    You could do this like this, I think:
    If Sum ({@total}, {@monthName}) = 0 Then
        0
    Else
        Sum ({@Unscheduled}, {@monthName}) / Sum ({@total}, {@monthName}) * 100;

  • 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

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

  • 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

Maybe you are looking for

  • Help with a java program

    Hello. I'm posting in these forums because I really don't know where else to go. I have been trying for the past several days to figure out how to go about writing my program but to no avail. The project requires reading many lines each containing se

  • Transformation of Data During User Reconciliation

    Hi all, I'd want transform data during user reconciliation from a trusted source SAP HR. In my case I have to transform the userid coming from SAP to generated a custom OIM User Login attribute. As described in the "Connector Guide for SAP Employee R

  • WAS ABAP - Keep prompting for credentials

    Hi All, We have couple WD ABAP applications deployed and running in our ECC backend. These are integrated in our Portal environment as well. At times, whenever user click on WD ABAP applications it keep prompting the user to enter ECC credentials. Pl

  • Filtering columns on condition

    Hi, I want to be able to select a few columns depending on a key. for instance, if my key is 'FA' then I want my FA columns to be the ones returned and not PG even though PG's columns are also declared. Here's the idea: table1 id  key  val FA  1  5th

  • Start position of scroll effect

    Just a simple scroll up only on a rectangle, preview in browser and the start position has moved? Thought it was me but today I have gotten it to preview in the start position sometimes. Have tried everything blank page, new site etc. Is it a bug or