Type special group some lines

Hey guys,.

the time is the Dungeon running and there are still a few problems with my apex report, so I decied to ask fruther.

I combine all my lines as in example 2 above. I know I could put the information corresponding to all, in the columns 'number', 'title' and 'project', for a line. I tried to use these solutions, but some of my entries in the last column "history" are a bit longer than usual of the. So my text cut to 32 k characters, because all the cells of a report are limited to 32 KB.

Maybe it's important to know that the values of 'number', 'title' and 'project' could repeat sometimes.
Now, I don't put all the information in my whole machted in a row. Each entry gets its own line.
But you can see that the values for 'number', 'title' and 'project' always repeat and it is not should like this.

Is it possible to group my lines, as in the 2.example?




It looks like at the moment: (1. example)

Number of... title... history of project...
1... has... b.line1
__________________________________
1... has... b.line2
__________________________________
1... a... ab... ine3




and so it should look like: (example 2)

Number of... title... history of project...
1... has... b.line1
__________________________________
........................................ . Line2
__________________________________
..........................................line3
__________________________________
2................b..........bb.........xxxx
__________________________________
..........................................bbbb
__________________________________

(the points must be white space)

and so on...



Best regards
wderr

Hello wderr,

Try this - it has no limitation on the number of columns to break down on:

SELECT   DECODE(ROW_NUMBER() OVER (PARTITION BY num ORDER BY num), 1, num, '') num,
         DECODE(ROW_NUMBER() OVER (PARTITION BY num, title ORDER BY num, title), 1, title, '') title,
         DECODE(ROW_NUMBER() OVER (PARTITION BY num, title, project ORDER BY num, title, project), 1, project, '') project,
         history
  FROM   your_table;

See the model? Just keep adding some "decode" columns for additional groups.

Hope this helps,
John

Tags: Database

Similar Questions

  • Why are some lines printed in blue in ProgramData? Have I not a bug/trojan/virus?

    I was looking for recent programs that I added not quite sure of the spelling of the name and intended to go to Program files, but hit ProgramData and I see that some lines are in blue type and others in black?  Am I in trouble? what it means?

    Blue type for a file name indicates the file is compressed.  For more information, seeHow to compress and uncompress a folder or file with the NTFS Compression in Vista and Windows 7 .

    Boulder computer Maven
    Most Microsoft Valuable Professional

  • Grouping of lines - SQL Developer

    I was wondering if someone can help me here - Im trying to group the lines in a "package" to get fewer lines of data and group together the dates where they follow (and they have the same class of service and client ID). Im not the most irritable person so any help is appreciated.

    Here's my CREATE & INSERT

    CREATE TABLE ACF_SERVICES_DIM (Client_id varchar2 (20),)
    Date of Agreement_Start_date,
    Date of Agreement_End_Date,
    Service_Category Varchar2 (200),
    Agreement_id varchar2 (20));

    Insert into Acf_Services_Dim (Client_Id, Agreement_Start_Date, Agreement_End_Date, Service_Category, Agreement_Id)
    VALUES ('2607 ', 'J2849', 'Red', TO_DATE (' 01/10/2013 ',' dd/mm/yyyy'), NULL);

    Insert into Acf_Services_Dim (Client_Id, Agreement_Start_Date, Agreement_End_Date, Service_Category, Agreement_Id)
    VALUES ('2607 ', 'J2279', 'Red', TO_DATE (' 30/09/2013 ',' dd/mm/yyyy'), TO_DATE (' 01/03/2002 ',' dd/mm/yyyy'));

    Insert into Acf_Services_Dim (Client_Id, Agreement_Start_Date, Agreement_End_Date, Service_Category, Agreement_Id)
    VALUES ('2607 ', 'J2284', 'Red', TO_DATE (' 30/09/2013 ',' dd/mm/yyyy'), TO_DATE (' 01/03/2002 ',' dd/mm/yyyy'));

    Commit;

    The last two are of the same exact service type / id / dates etc so id expect to see a result... I think however it it link to 1 also, such as tracking the dates on and again, everything else is the same.

    If there is a 4th line-

    VALUES ('2607 ', 'J2299', 'Blue', TO_DATE (' 30/09/2013 ',' dd/mm/yyyy'), TO_DATE (' 01/03/2002 ',' dd/mm/yyyy'));

    Commit;

    I only expect to show also in a separate package because it does not match the 1st 3 because it is a different class of service, even if the dates are the same... I hope that helps?

    The request im trying to use is the following... HOWEVER it keeps giving me a not authorized windows error function

    WITH got_package_id AS

    (

    SELECT agreement_id

    MIN (CONNECT_BY_ROOT agreement_id) AS package_id

    Of acf_services_dim

    CONNECT BY NOCYCLE client_id = client_id PRIOR

    AND service_category = PRIOR service_category

    AND agreement_id <>agreement_id PRIOR

    AND (agreement_start_date = agreement_end_date FRONT + 1).

    OR agreement_end_date = PRIOR agreement_start_date - 1

    OR (agreement_start_date = PRIOR agreement_start_date

    AND agreement_end_date = PRIOR agreement_end_date

    )

    )

    GROUP BY agreement_id

    )

    SELECT s.Client_Id

    MIN (s.Agreement_Start_Date) AS package_start_date

    , NULLIF (NVL (MAX (s.Agreement_End_Date))

    DATE "9999-01-01'

    )

    DATE "9999-01-01'

    ) AS package_end_date

    s.Service_Category

    p.package_Id

    ROW_NUMBER () OVER (PARTITION BY s.client_id

    s.service_category

    ORDER BY p.package_id

    ) AS package_num - if wanted

    Of s acf_services_dim

    JOIN got_package_id p ON p.agreement_id = s.agreement_id

    GROUP BY s.client_id

    s.service_category

    p.package_id

    ;

    Don't know why, but im getting the following error when running in SQL developer... no idea why?

    Error in the command column line: 32:56

    Error report:

    SQL error: ORA-30483: window functions are not allowed here

    30483 00000 - "window functions are not allowed here."

    * Cause: Window functions are allowed only in the SELECT a query list.

    And, depending on the window cannot be an argument in another window or group

    function.

    * Action:

    Make a copy of your test case in a spreadsheet SQL Developer 4.0.3 connected to Oracle Xe (11.2.0.2) with jdk1.7.0_67 on Windows 7, everything works as expected:

    CLIENT_ID PACKAGE_START_DATE PACKAGE_END_DATE SERVICE_CATEGORY

    -------------------- ---------------------------------- ------------------------------- -------------------------------

    2607 1 March 02 13 - SEP - 30 Blue

    2607 1 March 02 13 - SEP - 30 Red

    No ORA-30483 at all.  What versions of SQL, Oracle DB, Java developer and so on are you using?

  • Trying to get ending entry into force for the groups of lines

    Hello world

    I searched the forums, but I can't find a post that is a problem quite like that.

    I have some data that looks like this:
            ID_NUM     EFFECTIVE ALLOC_PERCENT   ACCT
    ---------- --------- -------------   ----
           101 01-JUL-11            21   A1
           101 01-JUL-11            72   A2
           101 01-JUL-11             7   A3
    
           101 01-JUL-12            20   B1
           101 01-JUL-12            80   B2
    
           101 01-JAN-13            20   A1
           101 01-JAN-13            20   A2
           101 01-JAN-13            50   A3
           101 01-JAN-13            10   B1
    
           101 01-JUN-13            50   A1
           101 01-JUN-13            50   A2
    (note: I inserted manually empty lines for clarity)

    Here's the logic: the lines represent an assignment of percentage on the account for the identification number specified for this entry into force. A new date to cancel the previous, and if any line in the conceptual group is replaced, so they are all.

    I'll try to find the date when the effective period of each group ended and which includes in the game so that I can calculate then the number of days in a given line has been effective; something like that;
      ID_NUM     EFFECTIVE END_DATE   ALLOC_PERCENT ACCT
    ---------- --------- ---------- ------------- ----
           101 01-JUL-11 01-JUL-12             21 A1
           101 01-JUL-11 01-JUL-12             72 A2
           101 01-JUL-11 01-JUL-12              7 A3
    
           101 01-JUL-12 01-JAN-13             20 B1
           101 01-JUL-12 01-JAN-13             80 B2
    
           101 01-JAN-13 01-JUN-13             20 A1
           101 01-JAN-13 01-JUN-13             20 A2
           101 01-JAN-13 01-JUN-13             50 A3
           101 01-JAN-13 01-JUN-13             10 B1
    
           101 01-JUN-13 <null>                50 A1
           101 01-JUN-13 <null>                50 A2
    The end_date of the group is the EFFECTIVE_DATE of the next group (ordered by ID_NUM, EFFECTIVE_DATE).

    End_date of two rows is zero because there is no group of lines with an effective date the later - in my process, I'll NVL which sysdate so that my calculations of days will be valid.

    I tried some analytical queries with LEAD, but I couldn't figure out how to get the next date of the efficient group. I could get the entry into force of the next row, but not the next group. I couldn't specify how many lead lines to look forward, because there is not a number of rows in each group.

    How to fill the end_date column?

    Here's the code to create the above.
    create table t
    (id_num number,
     effective_date date,
     alloc_percent number,
     acct_code varchar2(4)
     );
    
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2011',21.0,'A1');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2011',72.0,'A2'); 
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2011',7.0,'A3');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2012',20.0,'B1');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2012',80.0,'B2');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jan-2013',20.0,'A1');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jan-2013',20.0,'A2');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jan-2013',50.0,'A3');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jan-2013',10.0,'B1');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jun-2013',50.0,'A1');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jun-2013',50.0,'A2');
    
    commit;
    
    select * from t;
    Oracle version information:
    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    "CORE 11.2.0.3.0 Production."
    AMT for Solaris: 11.2.0.3.0 - Production Version
    NLSRTL Version 11.2.0.3.0 - Production


    Thank you very much

    Hello

    Here is one more way to do using lead work.

    WITH ds as (id_num, effective_Date, lead (effective_date) select on end_date (id_num order, effective_Date))

    t

    Id_num group, effective_date)

    Select t.*, ds.end_date

    DS, t

    where t.effective_Date = ds.effective_Date;

  • How to develop and reduce lines or groups of lines in figures?

    How to develop and reduce lines or groups of lines in figures?

    Thank you

    Casey

    Select the rows (or columns):

    Then, place the cursor on one of the row headings (the numbers on the left):

    so that you see the carat facing downwards, then click here to bring up the context menu for the lines:

    then select "hide selected rows.

  • DeskJet D4360: why my printer prints some lines in italics?

    I recently put in a new printer cartridge and now the printer prints some lines randomly on the page in italics.  Why?  How can I fix it?

    Hi Ba-rk , thanks for getting back to me!

    I hope you had a great weekend!

    If you make a copy of something from the glass as opposed to aprint without italics, the copy comes out with italics?

    I suggest to remove the cartridges and perform a power reset.  Unplug the power cord from the printer and the power outlet, then wait 60 seconds. After 60 seconds, plug back in the printer. Make sure that you connect the printer directly to a wall outlet. Make sure to bypass any surge protector or power bar.

    I recommend also to download and run the HP print and Scan doctor.

    Please hold me!

  • Windows 7 on a computer hp laptop, start menu never ceases to appear and disappear if often I can't type on the command line.

    Windows 7 on a computer hp laptop, start menu never ceases to appear and disappear if often I can't type on the command line. I can open Google Chrome and click here to read the games. If I need to type anything it either in the menu popping up any program does not allow me to do. I have it in safe mode to try to run a full scan check but not able to do. Any suggestions?

    Help, please

    You have another keyboard, say a connected USB, try? If this occurs only when you try to type, I was wondering if the keyboard is faulty and its operation to sort of the windows key?

    If this is likely, you can try https://support.microsoft.com/en-us/kb/216893 if you click on the toggle bits.

    If not that, perhaps of possible malware? Can you go as far as to update your antivirus software and then run a full scan to see if it finds problems? When you say "able to do" whats happening?

  • Dell XPS 13 type special characters with keyboard

    I'm unable to type special characters with my Dell XPS 13 with Windows 8 pre-loaded. For example when you type ' ^ ' followed by 'e', you should get 'e '.

    My previous 13 XPS with Windows 7 preinstalled worked well. I loaded all the latest drivers, but the functionality is still missing. Is there a setting that needs to be turned on? Or are still missing drivers for Windows 8?

    Help will be appreciated

    SHE FOUND! Press "Fn + Ctrl + LShift" simultaneously to activate and deactivate the entry of special characters

  • LaserJet M477: LaserJet M477 prints some lines in italics, and vertical lines must be straight are wavy

    Hello

    I just bought my LaserJet M477 a week ago, and I've noticed a few problems print quality:

    • When I print text documents, some lines incorrect impression of italic characters, while the text is not italicized in the source document.  The problem is not random - I can print the same page twice, and it is implemented in italics in the same places.
    • When I print graphics, long straight lines parallel to the direction of the paper path have regular aberrations, light showers in them.  The problem seems to occur at intervals down the page (as if there could be an irregularity in a circular or cylindrical part inside).  I am even noticing the problem when I print the test page "setting of alignment".  In comparison, all the lines that are perpendicular to the paper path are sharp and straight.

    Another post on this site suggested a "reset power" to solve a similar problem with the italics, but this does not solve the problem for me.

    I've also updated the firmware and drivers and installed/reinstalled the printer, each nothing helps.

    The question of italics seems like it might be a software problem, but I fear that the problem of vertical wavy lines might be a mechanical problem.

    Could someone suggest solutions?

    Thank you

    Kevin

    Droms,

    I chatted with HP online tech support yesterday, share everything we have discussed here and they concluded that there is a hardware problem with the printer.  They recommended I have share the printer to my point of sale to another unit.  Fortunately, I'm still within 14 days of the back window.  HP has also instructed to give me my case ID to the retailer, probably as license to HP for them to accept the return unit and perhaps to help diagnose the unit once the logistics team sent back to HP.

    BTW, HP examined our whole conversation here thread, and the thought of a problem with the Starter toner cartridges never came.

    You can continue a similar conversation with the HP technical support.  I'd hate to see that you stuck with a defective printer.

    Thanks for your comments, and I hope that you are able to get an acceptable resolution.

    Kevin

  • some lines are not resized right when resizing

    Hello people,

    I recently did a drawing in Illustrator CS5 to a certain vehicle. This size of the drawing is 2600 x 2583,5 px in a resolution of 72 dpi for use on the web.

    Now, I want to use this picture on a website, but this effect to be resized to 160 x 146 px. When I reduce the drawing to the size you want there are some lines that are not scaled down correctly compared to other lines. These lines are 1 pt stroke and whatever I do, the blow of these lines in particular cannot be resized to a value less than 1 pt.

    I activated "stroke scale & effect" in preferences, unlocked all objects and most of the strokes is scaled down fine apart from a few who will not be on the scale of less than 1 pt.

    Does anyone have any idea wat could be the cause of this?

    Greetings,

    Erik

    Transform the drop down palette menu > snap to the grid of pixels > Off

    They have added this in CS5, everybody throws finally in this.

  • Deleting some lines

    Very new to illustrator and I am looking for assistance in the removal of some lines (or a better way to do what I'm looking for). The image below has been stretched with the tool pen with three separate lines (the other form of bag and the two rings. However, I can't seem to find a way to get rid of the external ling when he meets the two rings (in other words, I want to delete the straight line when he corsses on the rings). Thanks for the time.

    Untitled-2.jpg

    yranac,

    If you have the latest version (s), you can use the live paint.

    In all versions, you can (a bit like the suggestion in post #3):

    (4) select the inner form and the object > path > divide objects below;

    (5) changing the path to the right.

    To join the open path to the left and closed to the right path, you can:

    (6) cut the closed path where it must be attached with the scissors (2 points) tool and remove the short path between them.

    (7) direct selection (click or drag on) pairs of anchors to assemble an open path.

  • How to spanne line / single called for a similar group of lines

    Hello

    I have a detail existing like that report, there is a conditional formatting on the cost, GP and safe etc..

    Type of mandate

    Type of assets

    Cost of the asset

    Term

    Grace period

    Deposit

    Future

    Vehicle

    1 173 952

    48

    0

    0% of the cost

    Future

    Vehicle

    4 173 952

    60

    0

    0% of the cost

    Future

    Vehicle

    1 500 000

    60

    0

    0% of the cost

    Future

    Material

    10,500,952

    48

    2

    10% of the cost

    Current

    Vehicle

    269 352

    36

    0

    0% of the cost

    Current

    Machines

    60,269,352

    48

    0

    0% of the cost

    Current

    Material

    200 000

    36

    0

    0% of the cost

    Current

    Material

    450 000

    36

    0

    0% of the cost

    Current

    Material

    250 000

    36

    0

    0% of the cost

    And we need to change the report at the start of this way without removing any existing conditional formatting.

    Type of mandate

    Type of assets

    Cost of the asset

    Term

    Grace period

    Deposit

    Current

    Vehicle

    269 352

    36

    0

    0% of the cost

    Machines

    60,269,352

    48

    0

    0% of the cost

    Material

    200 000

    36

    0

    0% of the cost

    Material

    450 000

    36

    0

    0% of the cost

    Material

    250 000

    36

    0

    0% of the cost

    Future

    Vehicle

    1 173 952

    48

    0

    0% of the cost

    Vehicle

    4 173 952

    60

    0

    0% of the cost

    Vehicle

    1 500 000

    60

    0

    0% of the cost

    Material

    10,500,952

    48

    2

    10% of the cost

    I tried many lines lasted , but without success, sometimes text out of the table or line covering the expected grouping. It is out of control for me

    Please help me, provide any sample/demo.

    Thank you

    I just tried according to your xml provided in post above, here is the model of form field and overview for your help.

    It's like you want.

    Type of mandate

    Type of assets

    Term

    Cost of the asset

    Grace period

    Deposit

    G V IF TERM_TYPE RS

    G V IF ASSET_TYPE RS

    G V IFTERMRS

    F ASSET_COST

    GRACE_PERIOD

    DEPOSIT E E E E

    Form fields

    G

    V

    IF

    TERM_TYPE

    RS

    G

    V

    IF

    ASSET_TYPE

    RS

    G

    V

    IF

    TERM

    RS

    F

    ASSET_COST

    GRACE_PERIOD

    DEPOSIT

    E

    E

    E

    E

    Overview

    Type of mandate

    Type of assets

    Term

    Cost of the asset

    Grace period

    Deposit

    Current

    Material

    36

    200 000

    0

    0% of the cost

    450 000

    0

    0% of the cost

    250 000

    0

    0% of the cost

    Machines

    48

    60,269,352

    0

    0% of the cost

    Vehicle

    36

    269 352

    0

    0% of the cost

    Future

    Material

    48

    10,500,952

    2

    10% of the cost

    Vehicle

    48

    1 173 952

    0

    0% of the cost

    60

    4 173 952

    0

    0% of the cost

    1 500 000

    0

    0% of the cost

    Note: as you mentioned earlier, it is a conditional formatting and logic on the existing model, these must be change as field are group / nested group, you may need to set field with current - group)

  • How to use the clause type conditionally create new lines

    This question is just for learning - no object other than to start real world to create versions of some queries known to learn how to measure the performance of the MODEL clause clause of the MODEL versions.

    The question is: How can you write a STANDARD clause that pivots (updates) ONLY the lines that actually need to rotate and do NOT change the lines that have no value and cannot be rotated.

    I found a good site that has about two dozen example articles on different pieces. This first link is the beginning of the series.

    SQL features tutorials - Clause TYPE

    http://www.sqlsnippets.com/en/topic-11663.html

    This link is to a clause of FAQ of BluShadow MODEL version "how to convert rows to columns."

    Line - MODEL method string

    http://www.sqlsnippets.com/en/topic-11987.html

    The solution to this link uses this line of source:

    POSITION KEY VAL

    --- ---------- ----------

    R08 0 v1, v2, v3,.

    and this result set:

    POSITION KEY VAL

    --- ---------- ----------

    R08 1 v1

    R08 2 v2

    R08 3 v3

    The reason why it produces that result set is this clause of the statement of MODEL

    RETURN THE UPDATED LINES

    If you comment on this article, you will see that the original lines are all in position 0. This means that the solution reproduced EACH SOURCE LINE even if there is only one item in the list of values.

    Thus, even a line source with a single value (for example, the r01 'a') will be updated and updated this line is returned.

    For a large number of data sources with only a few lines that actually need to rotate it would be a great performance of infringement.

    This is the sample data source

    with t as (button 1, 'a' value 'abc' col2, col3 'def' of the double
    Select Union all 2, 'b', 'ghi', 'jkl' from dual
    Union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
    Union all select 4, 'f', 'stu', 'vwx' from dual
    )
    Select the key, value, col2, col3
    t

    KEY, VALUE, COL2, COL3
    1, a, abc, def
    2, b, GHI, jkl
    3, "c, d, e, mno, pqr.
    4, f, stu, vwx

    Lines 1, 2 and 4 only have a value of (a, b, c respectively.

    Only line 3 must rotate. It contains "c, d, e" and which must become 3 lines in the result set

    Value of the key, col2 col3
    1 an abc def
    2B ghi jkl
    3 c mno, pqr
    3 d mno, pqr
    3 e mno, pqr
    4 f stu vwx

    The nut of the problem is that if the clause 'RETURN UPDATED ROWS' is used, then the lines 1, 2 and 4 must be updated in order to be returned in the result set. And if this clause is NOT used, then line 3 must be updated by 'c', d, e 'c' and two new product lines: one line for a ' and one for 'e '.

    How can you do this with the TYPE clause without the help of the clause "Return LINES UPDATE"? I don't have a solution to sample showing what I tried because I can't understand what it takes to even try.

    I have a solution that uses "RETURN UPDATED ROWS" but I want to compare this performance to the exercise, when this clause is NOT used.

    We ask BluShadow to add the solution of MODEL clause to this FAQ with other similar solutions.

    Like this?

    SQL > with t as
    () 2
    3 select the 1 key, 'a' val, 'abc' col2, col3 'def' of the double


    Select 4 Union all 2, 'b', 'ghi', 'jkl' from dual
    5 union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
    Select 6 Union all the 4 'f', 'stu', 'vwx' from dual
    7)
    8. Select the key
    9, key_1
    10, val
    11, regexp_substr (val, ' [^,] +', 1, key_1) val_new
    12, col2
    13, col3
    14 t
    model 15
    16 partition by (key)
    dimension (1 key_1) 17
    18 measures (val, col2, col3, (length (val) - length (replace (val, ",")) + 1) as len)
    19 rules
    (20)
    21 val [for 1 to increment of len key_1 [1] 1] = val [1]
    22, col2 [for 1 to increment of len key_1 [1] 1] = col2 [1]
    23, col3 [for 1 to increment of len key_1 [1] 1] = col3 [1]
    24)
    25 order
    26 by key
    27, key_1;

    KEY KEY_1 VAL VAL_N NECK NECK
    ---------- ---------- ----- ----- --- ---
    1 1 has an abc def
    2 b 1 b ghi jkl
    3 1 c, d, e c mno pqr
    3 2 c, d, e d mno pqr
    3 3 c, d, e e mno pqr
    4 1 f f stu vwx

    6 selected lines.

  • Grouping of lines from common lines in detail header

    Hello

    I have two tables TAB_MST and TAB_DTL with the information as below:

    {code}

    CREATE TABLE TAB_MST
    (
    NUMBER OF MSTCOL
    )
    /

    ALTER TABLE TAB_MST ADD CONSTRAINT TAB_MST_PK PRIMARY KEY (MSTCOL)
    /

    INSERT INTO TAB_MST (MSTCOL) VALUES (1);
    INSERT INTO TAB_MST (MSTCOL) VALUES (2);
    INSERT INTO TAB_MST (MSTCOL) VALUES (3);
    INSERT INTO TAB_MST (MSTCOL) VALUES (4);

    CREATE TABLE TAB_DTL
    (
    NUMBER OF MSTCOL
    NUMBER OF DTLCOL
    )
    /

    ALTER TABLE TAB_DTL ADD CONSTRAINT TAB_DTL_PK PRIMARY KEY (MSTCOL, DTLCOL)
    /

    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (1, 1);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (1, 2);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (1, 3);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (1, 4);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (1, 5);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (2, 4);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (2, 7);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (2, 8);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (2, 9);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (3, 8);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (3, 9);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (3, 10);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (3, 11);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (4, 12);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (4, 13);
    INSERT INTO TAB_DTL (MSTCOL, DTLCOL) VALUES (4, 14);

    COMMIT;

    {code}

    I want to group the rows in the Master table (TAB_MST) to different groups based on the data in the secondary table (TAB_DTL) with output like below

    MSTCOL GROUPID
    1               1
    2               1
    3               1
    4               2

    Rule for grouping are as follows:

    (1) if there is a common value of DTLCOL for two different values of MSTCOL, then two MSTCOL values should be grouped under the same group, for example for the above case of sample
    DTLCOL (value = 4) is common for MSTCOL = 1 and MSTCOL = 2, so MSTCOL 1 and MSTCOL 2 belong to the same group (GROUPID = 1).
    DTLCOL (value = 8, 9) is common for MSTCOL = 2, MSTCOL = 3, so 3 MSTCOL must belong to the same group as MSTCOL 2 (GROUPID = 1)
    There is no common value of DTLCOL for MSTCOL = 4, so it is in a separate group.

    Here is the PL/SQL block to highlight this grouping behavior. Two temporary tables are created to achieve this:

    {code}

    CREATE TABLE TAB_MST_GROUP
    (
    NUMBER OF MSTCOL
    GROUPID NUMBER
    )
    /

    CREATE TABLE TAB_TMP_GROUP
    (
    GROUPID NUMBER
    )
    /


    DECLARE
    CURSOR c1
    IS
    SELECT * FROM tab_mst;

    prevmstcol NUMBER;
    prevgroupid NUMBER: = 1;
    vtmpgroupid NUMBER;
    BEGIN
    DELETE tab_mst_group;

    FOR r1 IN c1
    LOOP
    IF prevmstcol IS NULL
    THEN
    INSERT INTO tab_mst_group
    VALUES (r1.mstcol, prevgroupid);

    prevmstcol: = r1.mstcol;
    ON THE OTHER
    INSERT INTO tab_tmp_group
    SEPARATE SELECT GroupID
    OF tab_mst_group a, tab_dtl b, tab_dtl c
    WHERE a.mstcol = b.mstcol
    AND c.dtlcol = b.dtlcol
    AND c.mstcol = r1.mstcol;

    IF SQL % ROWCOUNT = 0
    THEN
    prevgroupid: = prevgroupid + 1;

    INSERT INTO tab_mst_group
    VALUES (r1.mstcol, prevgroupid);
    ON THE OTHER
    SELECT MIN (groupid) IN the vtmpgroupid OF tab_tmp_group;

    UPDATE tab_mst_group
    SET groupid = vtmpgroupid
    WHERE groupid IN (SELECT tab_tmp_group FROM groupid);

    INSERT INTO tab_mst_group
    VALUES (r1.mstcol, vtmpgroupid);

    SELECT MAX (groupid) IN tab_mst_group prevgroupid;

    DELETE tab_tmp_group;
    END IF;
    END IF;
    END LOOP;
    END;

    {code}


    Question:

    a. can achieve us in SQL instead of PL/SQL?
    b. fresh general reading of TAB_DTL grows exponentially if the number of cases in TAB_MST develops. How can we reduce the number of TAB_DTL reading as the real lines of TAB_DTL is very high.


    Thank you
    sukhijank

    Hi, Sukhijank,

    Thanks for the additional information.  Has not only learned these details since posting your first message, did you?  If you post information like that in your first post, and then people can use it to give you a better response to the first answer.

    The idea I had for a recursive solution of WITH clause will not work after all.

    I think that the best solution will be in PL/SQL, using a table like tab_mst_group that you posted, but with an extra column:

    CREATE TABLE TAB_MST_GROUP
    (
      mstcol NUMBER PRIMARY KEY,
      groupid   NUMBER,
      levelnum NUMBER
    );
    CREATE INDEX tab_mst_group_groupid_levelnum
    ON     tab_mst_group (levelnum, groupid);
    

    If llevelnum = 0, which means that the allocation of groupid is not certain; If levelnum > 0, then groupid is correct.

    Here is a procedure you can use to fill in the table:

    CREATE OR REPLACE PROCEDURE tab_mst_group_populate
    AS
        new_groupid  tab_mst_group.groupid%TYPE
         := 0;
        new_levelnum tab_mst_group.levelnum%TYPE;
        num_added  PLS_INTEGER;
        truncate_stmt VARCHAR2 (50) := 'TRUNCATE TABLE tab_mst_group';
    BEGIN
        --  *****  Remove old entries from the table  *****
        -- dbms_output.put_line (truncate_stmt || ' = truncate_stmt in tab_mst_group_populate'); -- Debugging
        EXECUTE IMMEDIATE  truncate_stmt;
    
        --  *****  Populate table with all mstcols, and 1-member groups  *****
        INSERT INTO  tab_mst_group (mstcol, groupid, levelnum)
        SELECT    m.mstcol
        ,       m.mstcol  AS groupid
        ,       MIN ( CASE
                         WHEN  o.mstcol IS NULL
         THEN  1
         ELSE  0
                     END
        )  AS lvlnum
        FROM     tab_mst    m
        LEFT JOIN tab_dtl    d ON  d.mstcol = m.mstcol
        LEFT JOIN tab_dtl    o ON  o.dtlcol = d.dtlcol
                AND o.mstcol   != d.mstcol
        GROUP BY    m.mstcol;
    
        --  ***** Get groupid for lowest mstcol that still needs one  *****
        WHILE  new_groupid IS NOT NULL
        LOOP
            SELECT  MIN (groupid)
    INTO new_groupid
    FROM tab_mst_group
    WHERE levelnum = 0;
    IF  new_groupid   IS NOT NULL
    THEN
         --  ***  Confirm groupid for this one mstcol  ***
         UPDATE  tab_mst_group
         SET     levelnum = 1
         WHERE   levelnum = 0
         AND     groupid = new_groupid;
         new_levelnum := 2;
         num_added := 1;
         --  ***  Add neighboring mstcols to this group  ***
    
         WHILE  num_added > 0
         LOOP
             UPDATE  tab_mst_group
      SET groupid   = new_groupid
      , levelnum  = new_levelnum
      WHERE levelnum  = 0
      AND groupid   IN (
                       SELECT  d2.mstcol
                FROM  tab_mst_group g1
          JOIN  tab_dtl       d1  ON  d1.mstcol  = g1.mstcol
          JOIN  tab_dtl       d2  ON  d2.dtlcol  = d1.dtlcol
                        AND d2.mstcol != d1.mstcol
          JOIN  tab_mst_group g2  ON  g2.mstcol  = d2.mstcol
          WHERE  g1.levelnum  = new_levelnum - 1
          AND  g1.groupid   = new_groupid
          AND  g2.levelnum  = 0
             );
      num_added := SQL%ROWCOUNT;
      dbms_output.put_line (num_added || ' = num_added');
             new_levelnum := new_levelnum + 1;
         END LOOP;
    END IF;
        END LOOP;
    
    END tab_mst_group_populate;
    /
    SHOW ERRORS
    

    The basic strategy is that we start assuming that each mstcol will have its own groupid.  The CASE expression in the INSERT statement sets levelnum = 1 for the mstcols that do not exist in the tab_dtl table, or are not related to other mstcols in tab_dtl.  The loop after that looks like for tab_mst_group lines are always 0, which means that the grpupid must still be confirmed or changed.  He begins by finding the lowest mstcol which still has levelnum = 0 and makes a new group.  The inner loop looking for related mstcols and the brand as being in the same group.

    You could combine tab_mst and tab_mst_group; I see no need to have a separate table (but maybe do you).  If combine you them, then you would not truncate the table in the procedure.

  • When I type in Acrobat, empty lines to cover my text

    To add text to a pdf document using Adobe Acrobat X Pro, I followed the following steps:

    -Click on tools at the top right of Acrobat, under the X.

    -By virtue of changes to the text and objects, select modify the text Document.

    -Place the cursor where I want the text to appear and typed.

    I placed the cursor on a blank line in my pdf. Rather than type above the line, my text covered the line. Now, I would like to know if there is a way to underline my text so it seems that it is above the line or cause my text not to cover the line below.

    It seems that you replace the characters in the line with the text and the original line was just text. Acrobat text editing features are heavy and difficult to use in a simple way. You are probably better off using the typewriter tool or adding a text field. Another option would be to add some text above the text by holding the CTRL key (or the equivalent on a MAC) when you place the cursor. Creates a new text rather than amend the current box.

Maybe you are looking for

  • Zoom window and minimizing the quirks

    I just discovered this message that solves a problem that concerns me for a long time More precisely: some applications of the mine should run maximized so I use SetPanelAttribute (hparent, ATTR_WINDOW_ZOOM, VAL_MAXIMIZE); to show directly the main t

  • my screen went sideways, how to fix this?

    everything on my screen turned sideways and I don ' know to restore.

  • Impossible to find fire wire connection on my Dell w/Windows XP

    I am trying to connect a digital on my desktop Windows XP Dell to edit camcorder videos. but I can't find a port of FireWire on my computer in order to connect the cable.  I have 6 USB ports, but I looked on my Dell configuration schema and no mentio

  • Can't send or receive messages in Windows Live Mail

    Hello. I recently bought an e-mail domain. The site that I bought since provided tutorials to add the Outlook and Windows Live Mail account. Unfortunately, I can't send / receive messages on either. I gave up Outlook and now focus on Windows Live. Th

  • DVD RW of Lenovo N200 do not play the DVD. But he plays perfect CD

    Hi forum; I've been using Lenovo N200 for 2 years. I installed Windows 7 top through a DVD. Mean to say is that I used DVDs on it. But now I am facing a problem, I can't play a DVD on it. Continue blinking light of rom. And in my computer in my G dri