Connect By with too many lines

Hello
I have a table of contracts. Each may have different payment intervals: M quarterly q, Y annually, monthly or one-time payment of E.
Now I want a select that displays all dates of start to maturity (duration) when the collection of accounts outstanding 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 / intervall
Now, I expect to get 12 dates for contract 345 and the other 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               567
each row after row 13 ' 01.01.07 567' I wasn't expecting.
Of course, I can add a predicate CONNECT_BY_ROOT = NR. But I'd like to understand why I get 11 lines for nr with root 567 345.

Concerning
Marcus

Hello

In a subquery of counter, where you use "CONNECTION BY LEVEL".< x"="" to="" generate="" the="" integers="" 1,="" 2,="" ...,="" x,="" the="">
in the clause FROM must have only one line.

Follow these steps:

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 to Blushadow.

"CONNECT BY" involves a parent-child relationship.
When the CONNECT BY condition does not refer to all the values stored in the table, as in "CONNECT BY LEVEL<=>
then each row of the table is considered the parent of all the other ranks. So if you have lines J in the table,
you will have lines J at LEVEL = 1, lines J * J = 2 level, J * J * J ranks to LEVEL = 3,..., lines power (j, k) = k level.

I don't think that the query you posted has produced the results you've posted.
The query has five columns in the SELECT clause and the result set includes six.

What is the purpose of the last column with CONNECT_BY_ROOT? If this is supposed to be the same as nr.
then you can have another column containing nr.

Tags: Database

Similar Questions

  • too many lines found

    I have two data blocks, a data block joins two tables and second datablock is based on a table.
    first DataBlock has all the fields with a ratio of 1:1 with Packing_id and second details of data block has several lines
    for each Packing_id I wrote 2 procs for 2 rematch are called respective after trigger query.

    My problem is when I am in form gives the Error Message ("too many lines found_orders_begin'");

    Here are my codes.

    PROCEDURE post_query IS
    CURSOR mast_cur IS
    SELECT pa.ship_to_last_name,
    PA.ship_to_first_name,
    PA.ship_to_address1,
    PA.ship_to_address2,
    PA.ship_to_city,
    p.packing_id,
    OF pa, packing p packing_attributes
    WHERE the p.packing_id; = pa.packing_id
    AND p.packing_id; =: PACKING_JOINED. PACKING_ID;

    BEGIN
    Message ("too many lines found_orders_begin'");
    OPEN mast_cur.
    loop
    EXTRACTION mast_cur to: PACKING_JOINED. SHIP_TO_LAST_NAME,
    : PACKING_JOINED. SHIP_TO_FIRST_NAME,
    : PACKING_JOINED. SHIP_TO_ADDRESS1,
    : PACKING_JOINED. SHIP_TO_ADDRESS2,
    : PACKING_JOINED. SHIP_TO_CITY,
    : PACKING_JOINED. PACKING_ID,
    end loop;
    CLOSE Mast_cur;

    EXCEPTION
    WHEN too_many_rows THEN
    Message ("too many lines found '");
    WHEN no_data_found THEN
    Message ("no data has been found it is '");
    WHILE OTHERS THEN
    Message ("do something else'");

    END post_query;
    ***********************************************************************************
    Detail of proc

    PROCEDURE post_query IS
    CURSOR det_cur IS
    SELECT pd.quantity,
    PD.stock_number,
    OF packing_details pd, packing p
    WHERE the p.packing_id; = pd.packing_id
    AND pd.packing_id =: PACKING_JOINED. PACKING_ID;
    BEGIN
    Message ("too many lines found_pack_begin'");
    OPEN det_cur.
    Look FOR det_cur IN
    : DETAILS. QUANTITY,
    : DETAILS. STOCK_NUMBER,
    CLOSE Det_cur;

    EXCEPTION
    WHEN too_many_rows THEN
    Message ("too many lines found '");
    WHEN no_data_found THEN
    Message ("no data has been found it is '");
    WHILE OTHERS THEN
    Message ("do something else'");

    END post_query;


    Thanks in advance for your help.

    Sandy

    If it is an element of data, why you change the database value in POST-QUERY-trigger with your select? At that time you assign a new value to a database element. It's like changed recording (if editing is allowed, otherwise it will trigger an error)

  • Apple ID associated with too many credit cards

    Apple ID associated with too many credit cards

    This can be useful:

    Change or remove your information from payment of Apple ID - Apple Support

  • Adobe Digital Editions will not activate with too many activation error

    Adobe Digital Editions will not be activated with too many activation error.  Technical support refused to help.  What can I do?

    To reset the client contact activation support cat https://helpx.adobe.com/contact.html?step=ADE_adobe-id-signing-in_stillNeedHelp and ask for the reset of the adobe ID.

  • When you try to connect to my email it says he was the block because someone tried to open a session with too many bad passwords.

    Blocked e-mail?

    I have not tried to connect to my email for a week, but when I tried to log on it (I only tried once), it tells me that my email is blocked because someone tried to open a session with too to bad passwords. What is someone trying to hack into my email?

    Hello handset,

    What e-mail account are referring? If it's Hotmail or Live email, then click on the links below and re - ask your question. Thank you.

    Windows Live Mail

    Windows Live Hotmail

  • Problems with too many user profiles on computers Windows 7 Professional?

    Is anyone aware of any issues related to Windows 7 computers when too many user profiles are created on the computer. I work in a school and I recently read an article by someone in another educational environment, indicating that they were having problems when too many profiles have been created on a computer.

    Given that integrated user profiles manager only allows you to delete each one profile, it's almost an option to the volume of user profiles that exist in such a laboratory environment. Remove Group Policy Computer Configuration-> policies-> administrative templates-> system-> user-> user profiles profiles of a certain number of days on system restart
    which exists in Server 2008 R2 does not.

    I appreciate your comments.

    Hi Skenny10,

    Your question of Windows 7 is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the IT Pro TechNet public.

    Please post your question in the Forums in TechNet Windows Server.

    Gokul - Microsoft Support

    [If this post was helpful, please click the button "Vote as helpful" (green triangle). If it can help solve your problem, click on the button 'Propose as answer' or 'mark as answer '. [By proposing / marking a post as answer or useful you help others find the answer more quickly.]

  • Help with too many downloads

    My computer died.  I proceeded to download Lightroom and got an error saying that I had too many downloads.  The old computer is dead.  What should do?

    install the application of office cc, https://creative.adobe.com/products/creative-cloud

    Use it to install your lr cc.

  • histogram with too many pixels

    I use photoshop to design covers and I must get a specific percentage for each color used in the design, so that the carpet manufacturers can dye the suitable amounts of wool.

    I'm simply converting the image to indexed color, and ensuring that if a carpet of three color there is only three colors indexed in the design.

    then I'm selecting colors using the magic wand and work working from the histogram what percentage of this color picture is by dividing the number of selected pixels, by non-contiguous non anti-aliasing of magic wand, by total pixels in the image.

    most of the time it works fine, but sometimes a color area will be clearly read as much having too many pixels, sometimes even more pixels that are read in the image as a whole.

    I do not understand why this happens, there are no layers in the image, certainly, this must be really simple?

    Help, please!

    good if you cut the selection then paste in place and this for each of your indexed color and then go the selected layer in the histogram, this seems to give a specific number of pixels.

  • super slow old laptop with too many startup programs

    RUNNING XP ON AN OLD LAPTOP WHICH IS REALLY SLOW, HOW CAN I DELAY OR SAFELY REMOVE EXCESSIVE STARTUP PROGRAMS

    Follow the tips below and also answer the following questions: brand and model of the pc, current antivirus, operating system and service pack.

    Stanley Zhang tips

    Will probably want to clean this machine...

    Search for malware:

    Download, install, execute, update and perform analyses complete system with the two following applications:

    ·                                 MalwareBytes (FREE)

    ·                                 SuperAntiSpyware (FREE)

    Remove anything they find. Reboot when necessary. (You can uninstall one or both when finished.)

    Search online with eSet Online Scanner.

    The less you have to run all the time, most things you want to run will perform:

    Use Autoruns to understand this all starts when your computer's / when you log in. Look for whatever it is you do not know usingGoogle (or ask here.) You can hopefully figure out if there are things from when your computer does (or connect) you don't not need and then configure them (through their own built-in mechanisms is the preferred method) so they do not - start using your resources without reason.

    You can download and use Process Explorer to see exactly what is taking your time processor/CPU and memory. This can help you to identify applications that you might want to consider alternatives for and get rid of all together.

    Do a house cleaning and the dust of this hard drive:

    You can free up disk space (will also help get rid of the things that you do not use) through the following steps:

    Windows XP should take between 4.5 and 9 GB * with * an Office suite, editing Photo software, alternative Internet browser (s), various Internet plugins and a host of other things installed.

    If you are comfortable with the stability of your system, you can delete the uninstall of patches which has installed Windows XP...
    http://www3.TELUS.NET/dandemar/spack.htm
    (Especially of interest here - #4)
    (Variant: http://www.dougknox.com/xp/utils/xp_hotfix_backup.htm )

    You can run disk - integrated into Windows XP - cleanup to erase everything except your last restore point and yet more 'free '... files cleaning

    How to use disk cleanup
    http://support.Microsoft.com/kb/310312

    You can disable hibernation if it is enabled and you do not...

    When you Hibernate your computer, Windows saves the contents of the system memory in the hiberfil.sys file. As a result, the size of the hiberfil.sys file will always be equal to the amount of physical memory in your system. If you don't use the Hibernate feature and want to reclaim the space used by Windows for the hiberfil.sys file, perform the following steps:

    -Start the Control Panel Power Options applet (go to start, settings, Control Panel, and then click Power Options).
    -Select the Hibernate tab, uncheck "Activate the hibernation", and then click OK. Although you might think otherwise, selecting never under "Hibernate" option on the power management tab does not delete the hiberfil.sys file.
    -Windows remove the "Hibernate" option on the power management tab and delete the hiberfil.sys file.

    You can control the amount of space your system restore can use...

    1. Click Start, right click my computer and then click Properties.
    2. click on the System Restore tab.
    3. highlight one of your readers (or C: If you only) and click on the button "settings".
    4 change the percentage of disk space you want to allow... I suggest moving the slider until you have about 1 GB (1024 MB or close to that...)
    5. click on OK. Then click OK again.

    You can control the amount of space used may or may not temporary Internet files...

    Empty the temporary Internet files and reduce the size, that it stores a size between 64 MB and 128 MB...

    -Open a copy of Microsoft Internet Explorer.
    -Select TOOLS - Internet Options.
    -On the general tab in the section 'Temporary Internet files', follow these steps:
    -Click on 'Delete the Cookies' (click OK)
    -Click on "Settings" and change the "amount of disk space to use: ' something between 64 MB and 128 MB. (There may be many more now.)
    -Click OK.
    -Click on 'Delete files', then select "Delete all offline content" (the box), and then click OK. (If you had a LOT, it can take 2 to 10 minutes or more).
    -Once it's done, click OK, close Internet Explorer, open Internet Explorer.

    You can use an application that scans your system for the log files and temporary files and use it to get rid of those who:

    CCleaner (free!)
    http://www.CCleaner.com/
    (just disk cleanup - do not play with the part of the registry for the moment)

    Other ways to free up space...

    SequoiaView
    http://www.win.Tue.nl/SequoiaView/

    JDiskReport
    http://www.jgoodies.com/freeware/JDiskReport/index.html

    Those who can help you discover visually where all space is used. Then, you can determine what to do.

    After that - you want to check any physical errors and fix everything for efficient access"

    CHKDSK
    How to scan your disks for errors* will take time and a reboot.

    Defragment
    How to defragment your hard drives* will take time

    Cleaning the components of update on your Windows XP computer

    While probably not 100% necessary-, it is probably a good idea at this time to ensure that you continue to get the updates you need. This will help you ensure that your system update is ready to do it for you.

    Download and run the MSRT tool manually:
    http://www.Microsoft.com/security/malwareremove/default.mspx
    (Ignore the details and download the tool to download and save to your desktop, run it.)

    Reset.

    Download/install the latest program Windows installation (for your operating system):
    (Windows XP 32-bit: WindowsXP-KB942288-v3 - x 86 .exe )
    (Download and save it to your desktop, run it.)

    Reset.

    and...

    Download the latest version of Windows Update (x 86) agent here:
    http://go.Microsoft.com/fwlink/?LinkId=91237
    ... and save it to the root of your C:\ drive. After you register on theroot of the C:\ drive, follow these steps:

    Close all Internet Explorer Windows and other applications.

    AutoScan--> RUN and type:
    %SystemDrive%\windowsupdateagent30-x86.exe /WUFORCE
    --> Click OK.

    (If asked, select 'Run'). --> Click on NEXT--> select 'I agree' and click NEXT--> where he completed the installation, click "Finish"...

    Reset.

    Now reset your Windows with this FixIt components update (you * NOT * use the aggressive version):
    How to reset the Windows Update components?

    Reset.

    Now that your system is generally free of malicious software (assuming you have an AntiVirus application), you've cleaned the "additional applications" that could be running and picking up your precious memory and the processor, you have authorized out of valuable and makes disk space as there are no problems with the drive itself and your Windows Update components are updates and should work fine - it is only only one other thing youpouvez wish to make:

    Get and install the hardware device last drivers for your system hardware/system manufacturers support and/or download web site.

  • Oracle 11g with too many years of data in tables

    I have a facility with transactional tables that has records for many years. Queries on these tables are slow and I need to solve this problem in order to improve the speed of my application.

    I think deleting all records of the past five years, but it's going to be a very complex task. I heard an order to mark some records in a table like inmmutables so applications will treat them in a different way and then I won't need to delete anything.

    Anyone heard of this solution? What are the commands and steps to do?

    Thank you

    With the archiving of data, or any deletion of data, you can get a performance improvement, or you can't get any improvement.

    I heard an order to mark some records in a table like inmmutables so applications will treat them in a different way and then I won't need to delete anything.

    Where have you heard of such a device? Are you sure that this is a feature of Oracle?

  • too many lines return to query?

    I am trying to write a query to extract data from two different tables. There are 444 records in the table p and 650 records in table T, but when I run my application I get over 10,000 + records? When I look at the results, it seems that it applies several dates per person when there is only 1 deadline? and showing multiple languageid when only 1 language?

    SELECT P.LASTNAME, P.FIRSTNAME, T.LANGUAGEID, T.TEST_TYPE, T.END_DATE, T.SCORE1, T.SCORE2
    OF PS_TEST_SCORES T, PS_PERSONNEL P
    WHERE T.SCORE1 > = '2'
    AND T.SCORE2 > = '2'
    AND T.END_DATE between to_date (1 January 2009 00:00:00 ', "hh24:mi:ss of mon-dd-yyyy")
    and to_date (28 January 2011 00:00:00 ', "hh24:mi:ss of mon-dd-yyyy")
    ORDER BY P.LASTNAME;

    example of result would be

    test_type German john Jones 24 - dec-09
    German john Jones January 22 09
    john Jones 1 February 10 German
    John Spanish Jones August 5, 10

    Once you the alias of a table in the FROM clause, you must use the alias everywhere.

    SELECT DISTINCT P.SSN,P.LASTNAME, P.FIRSTNAME, T.LANGUAGEID, T.TEST_TYPE, T.END_DATE, T.SCORE1, T.SCORE2
      FROM PS_TEST_SCORES T,
          PS_PERSONNEL P
     WHERE T.SSN=P.SSN
       AND T.SCORE1 >='2'
       AND T.SCORE2 >='2'
       AND T.END_DATE between to_date( '01-jan-2009 00:00:00', 'dd-mon-yyyy hh24:mi:ss' )
                          and to_date( '28-jan-2011 00:00:00', 'dd-mon-yyyy hh24:mi:ss' )
     ORDER BY P.LASTNAME; 
    

    As you add a join condition, you are sure you really need the SEPARATE? Many new developers throw the SEPARATE on their queries into thinking that it is necessary because they missed a join condition. Unless you know that he's supposed be returned without the SEPARATE, leaving the SEPARATE in just the duplicate lines made Oracle work more hard.

    Justin

  • Too many lines 'recipient' when I reply to a message

    Since I updated to 31.0 Thunderbird version, whenever I hit him "reply" to an e-mail message rather than just get the two lines from and to, I get two additional blank lines before the "Subject" line I have to shrink the header to get rid of these extra lines. Not a major problem, but starts to annoy me.

    This did, in fact, solve my problem. I want to just emphasize that it takes effect as soon as you exit Thunderbird and then re - start.

    Thank you very much!

  • ReadyNAS 104 times out when trying to access directories with too many files.

    I am facing a problem where the contents of the directories which exceed a certain number of files (I'm not sure of the exact limit) may not display. I tired to view through the Finder on OSX files, through the web and even on the iOS app browser interface. The directories contain a large number of image (jpeg and png, for the most part) files. Directories with fewer files seem to open and display correctly, even when they have similar content (image, in this case files).

    I'm running a configuration using X-RAID with 3TO discs in each of four bays.

    This question is severely limiting the usefulness of my SIN, so I'd appreciate a quick answer on how to solve this problem.

    Thanks in advance.

    Changing the backend setting solves the problem.

    TheNoel says:

    "The difference is night and day. The largest directory containing 12 000 files loads quickly and is easy to navigate via SMB.

  • LiveCycle dynamic form adds too many lines and does not save properly

    Hello

    I'm fairly new to LiveCycle Designer.  I designed a few forms that behave in the same way, and I'm curious to know if someone would mind helping me find my mistake.

    I have a table that I need to be able to add and subtract lines.  If I add a line and fill in the information, it seems good.  If I save the form and re-open information disappeared and there are several added lines which are empty.  How can I fix?

    Document link: file - sharing Acrobat.com

    Thank you very much

    Loren

    Hey Loren,

    It's very strange, and I would say a bug in the binding process.  It seems that from Table2 Row1 elements can be picked up as part of the binding of the nested table, table 3, which has a line called Row1.

    I changed the Row1 under Table3 to SubRow1 and it seems to work fine.

    I don't know how you want the buttons Add/Remove to work, but "this.parent.index" you will get the index of Cell1 (which will always be 1), you can "this.parent.parent.index".

    Concerning

    Bruce

  • error "too many concurrent connections" with Gmail

    I started all of a sudden the error "too many concurrent connections" with Gmail with one of my gmail accounss. I googled and it seems like an old problem and I tried all the recommended solutions, but none worked. I have two gmail accounts and the other continues to function properly. Suggestions!

    Reduce the number of labels has solved this problem. Seems specific to TB and GMail (google says you can have hundreds of emails - I have about 60). There are mentions of which can be found via google - but no definitive statement on the problem, with workarounds, etc.. Now I will be anxious the next time I have to add a label, not knowing if it will work or cause this problem.

Maybe you are looking for

  • With SM30X-102 power management

    Hello I want to use the utility of Toshiba power with a non admin on laptop user account management. If I try, I get the message that I have to be an administrator. If I make a selection as long as an administrator, the values are not used for the no

  • How can I burn a DVD using the latest iMovie?

    I'm used to be able to export my iMovie as files DV videos.  I want to retain the original quality without compression.   This is no longer the case with the new iMovie app.  The only choice now is to 'Share' and the same year, when sharing, I always

  • Cannot access router EA3500 to change settings

    I would like to make a few changes to the configuration of my router, but can't access the configuration screens. I tried Smart Wifi and myrouter.local.  After entering my password, it hangs on "Waiting."... "and I never have to the configuration scr

  • Start stuck on waves, PC companion is not useful

    OK so I was using my phone and all of a sudden it shut down apps for no reason, so I thought it would be wise to reboot the phone. Big mistake. Now it is stuck on the wave logo when you start the phone and it gets really hot. I installed PC Companion

  • Transfer directly to the mailbox of the user in the unit

    This was probably requested in the past... I have 4.1 CCM (3) and unity 4.0.4 You know an easy way for the standard transfer a call to a voicemail access number (without the ring extension users). I tried to do it using a Manager to call the unit, bu