Generate combinations of record group

Hello

I have a data set that is basically attribute (x) and pairs of values (y). The separate list of attributes defines a group. I would like to generate all the combinations of a group for data values.
create table a (x varchar2(50), y varchar2(50));
Some examples of data to illustrate.
insert into a values ('AAA', '111');
insert into a values ('BBB', '222');
insert into a values ('BBB', '333');
insert into a values ('CCC', '444');
insert into a values ('CCC', '555');
insert into a values ('CCC', '666');
The output that I would get would be the following.
GROUP    X    Y
-----    ---  ---
1        AAA  111
1        BBB  222
1        CCC  444
2        AAA  111
2        BBB  222
2        CCC  555
3        AAA  111
3        BBB  222
3        CCC  666
4        AAA  111
4        BBB  333
4        CCC  444
5        AAA  111
5        BBB  333
5        CCC  555
6        AAA  111
6        BBB  333
6        CCC  666
Thank you!

Hello

Here's one way:

WITH     all_x     AS
(
     SELECT       x
     ,       ROW_NUMBER () OVER (ORDER BY x)     AS r_num
     FROM       a
     GROUP BY  x
)
,     got_combination     AS
(
     SELECT     SYS_CONNECT_BY_PATH (a.y, '~')     AS combination     -- Assuming y never contains ~
     ,     ROWNUM              AS grp
     FROM     all_x  x1
     JOIN            a  ON     a.x     = x1.x
     WHERE   CONNECT_BY_ISLEAF     = 1
     START WITH     x1.r_num     = 1
     CONNECT BY     x1.r_num     = 1 + PRIOR x1.r_num
)
SELECT       c.grp
,       x2.x
,       REGEXP_SUBSTR ( combination
                 , '[^~]+'
               , 1
               , x2.r_num
               )     AS y
FROM        got_combination  c
CROSS JOIN  all_x          x2
ORDER BY  c.grp
,            x2.x
;

Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.
Don't forget to tell what version of Oracle you are using. The query above requires Oracle 10.1 or higher.

This requires, there is some character (I used "~") that never happens in there. If there is no such character, you can use a string of multiple character, but it complicates the REGEXP_SUBSTR in the main query.
It also means that there is not NULL. If there can be null, the same basic approach will work, but it's a little more complicated.

This is NOT to assume that there are 3 distinct values of x. It will work with any number of values of x and any number of lines to each value.

Grp numbers in no particular order. In other words, if you rerun the query, with exactly the same data, which was grp = 1 may be grp = 2, or it might be grp = 2, or any number between 1 and 6. There will always be 6 groups (account required to these data) and groups are always numbered from 1 to 6 and all the 3 lines that have the same number of grp in the above results will continue to have the same number of fiberglass, but it is unclear what the number will be.
If you want the grp numbers assigned in a certain order, use the DENSE_RANK function analytical in the main query, rather than using the ROWNUM in got_combination. (Do not use analytical functions in the same auxiliary request with CONNECT BY; it can cause the CONNECT BY acting strangely).

Published by: Frank Kulash, 10 may 2012 09:23

Tags: Database

Similar Questions

  • A function can be called record group - Oracle Form 6i.

    Hi all

    I want to create query based LOV in Oracle Form 6i.

    The query I have use of the record group is as follows:

    SELECT DISTINCT

    Nr.rec_locator AS rec_locator,

    car.car_dte AS car_date,

    Get_car_info(:CON.) REF_NO) AS car_number

    Car_list_entries CAR

    contact_details cdt,

    name_records nr

    WHERE car.car_id = cdt.car_id

    AND cdt.nr_id = nr.id

    AND cdt.con_ref_no =: CON. REF_NO

    / * Get_car_info (x NUMBER) is a function of form * /.

    This generates an error:

    It is said

    FRM-12001 (impossible to create the Group Record (check your query)


    Kindly guide how can I use the function of form to achieve the desired result.

    Thank you very much

    Anoop.

    Hi Anoop,

    I can assure you that the issue is not because of the called function of the record group.

    I used the query showing the value of the function; but one thing you should keep in mind is:

    If you create a new item not related in a based lov to sql expression that

    return a character data type, and if the element related to the used in the function

    is generated with a size of 0, then the item not related is generated

    with a size of 4000 and a compilation of the form failed with error FRM-30187

    the solution to this problem is: lov property > column specification > columns one will be having a greater length and 2000 it set its 2000 which is the maximum value. Then it won't work.

  • FRM-30187: size of the column of type CHAR in the record group must be between 1 and 2000.

    Hi, forms 6i, db 10g

    I created a lov based on this query

    select * from items_qty_vu -- database view
    

    and the view code is

    CREATE OR REPLACE FORCE VIEW items_qty_vu (serial, item_id, expiry_date, qty)
    AS
       WITH item_units_plus AS
            (SELECT item_id, unit_id, factor,
                    LEAD (factor, 1, 1e99) OVER (PARTITION BY item_id ORDER BY factor)
                                                                   AS next_factor,
                    ROW_NUMBER () OVER (PARTITION BY item_id ORDER BY factor DESC)
                                                                           AS rnk
               FROM item_units)
       SELECT     ID.serial, ID.item_id, ID.expiry_date,
                  SUBSTR
                     (SYS_CONNECT_BY_PATH (   TRUNC (  MOD ((  ID.qty
                                                             - ID.qty_allocated
                                                            ),
                                                            iup.next_factor
                                                           )
                                                     / iup.factor
                                                    )
                                           || ' '
                                           || u.unit_name,
                                           ', '
                                          ),
                      3
                     ) AS qty
             FROM item_detail ID JOIN items i ON i.item_id = ID.item_id
                  JOIN item_units_plus iup ON iup.item_id = ID.item_id
                  JOIN units u ON u.unit_code = iup.unit_id
            WHERE CONNECT_BY_ISLEAF = 1
       START WITH iup.rnk = 1
       CONNECT BY iup.rnk = PRIOR iup.rnk + 1 AND ID.serial = PRIOR ID.serial
         ORDER BY ID.serial;
    
    

    When I compile the form, I face the error FRM-30187,

    If I replace my query "select * from items_qty_view" with "select item_id, serial, expiry_date of items_qty_vu", it compiles successfully.

    As salamualikum, Salem,.

    You must follow my instructions carefully.

    1. Select the record group.

    2. go in the record group property

    3. Select and open the column specifications

    4. highlight the column and check the decrease of the length, the bellows of the size that you cross more than 2000 then 2000.

    Compilation of now and you're done.

    Wow. you did.

    Hamid

  • Is there a limitation of length of sql in a record group?

    Record group contains 4 by union funcion sql statement. When this sql statement longer than 4000 characters then the record group do not allow me to add an additional column to another.

    My question is, is there a limitation of length of sql that record the group support?

    Developer 10g suit.

    Thanks in advance.

    As you have discovered that there is a limit in the form designer, on what size the SQL statement may be in the property Query Group Record in your record group.  Unfortunately, the forms for the Query Group property help topic Record does not that there is a limit or the limit.

    If your request does not fit into the Group Record Query property, you can try to use the integrated Create_Group_From_Query() to fill in your group.  Another option would be to create views in your database, and then select the view in the Query property group Record.

    If you opt to try the method of Create_Group_From_Query(), just set your Group Record in the navigation of the object by using a SELECT statement (your column names) twice and then programmatically remove the Group and re-create it with the high - Create_Group_From_Query ().  See the help topic for the function integrated for a code example.

    Craig...

  • Dynamic record group works not when using apostrophes

    Hello world

    I developed a form most of the time, everything works as expected. However, there is a search feature that gives me problems. The problem is that when the user enters the search criteria for last_name with an apostrophe (O'brian) lov research get filled because the dynamic disk group is not created when the string contains an apostrophe (i.e. O'brian). I have a dynamic disk group that takes the user's search criteria and fills a LOV on the screen with the corresponding records to their criteria.

    Here is the code that is behind my search button where the dynamic RG is created. It works very well for any research that does not contain an apostrophe. BTW, the Oracle Forms version is 10g.

    DECLARE

    p_where_debtor varchar2 (2000);
    p_where_liab varchar2 (2000);
    RG_ID RecordGroup;
    v_query varchar2 (2000): = null;
    rg_name varchar2 (2000): = "RG_LIAB_LST";
    ERRCODE NUMBER;
    BEGIN

    IF: SEARCH.cd_nb is null and
    : SEARCH.cd_seq is null and
    : SEARCH.f_name is null and
    : SEARCH.l_name is null and
    : SEARCH.mi_name is null
    then
    display_message (' search criteria must be entered ");
    raise form_trigger_failure;
    END IF;

    v_query: = ' SELECT name, middle_name, c_no, c_seq
    FROM TABLE_VW2 WHERE 1 = 1';
    / * Search criteria entered by the user * /.

    IF: SEARCH.l_name_srch IS NOT NULL THEN
    v_query: = v_query | "AND UPPER (last_name) AS"' | Upper(:Search.L_Name) | » %''';
    END IF;

    IF: SEARCH.f_name_srch IS NOT NULL THEN
    v_query: = v_query | "AND UPPER (first_name) AS"' | Upper(:Search.F_NAME) | » %''';
    END IF;

    IF: SEARCH.mi_srch IS NOT NULL THEN
    v_query: = v_query | "AND UPPER (middle_name) AS"' | Upper(:Search.mi_name) | » %''';
    END IF;

    IF: SEARCH.cdcs_nbr_srch IS NOT NULL THEN
    v_query: = v_query | "AND UPPER (c_no) AS"' | Upper(:Search.cd_nb) | » %''';
    END IF;

    IF: SEARCH.cdcs_seq_srch IS NOT NULL THEN
    v_query: = v_query | "AND UPPER (c_seq) AS"' | Upper(:Search.cd_seq) | » %''';
    END IF;

    / * Make sure that the record group exists * /.

    RG_ID: = Find_Group (rg_name);

    / * If there are then create record group * /.

    IF id_null (rg_id) THEN
    RG_ID: = create_group_from_query (rg_name, v_query);
    END IF;

    IF this is id_null (rg_id) THEN
    delete_group (rg_id);

    RG_ID: = create_group_from_query (rg_name, v_query);
    END IF;

    Errcode: = Populate_Group (rg_id);

    Any help would be greatly appreciated.

    Thank you

    Adrian

    For each item where an apostroph may occur, make a

    REPLACE(:BLOCK.ITEM, '''', '''''');
    
  • Request of the record group.

    Hello
    I have a group record Forms 4.5 created with CREATE_GROUP_FROM_QUERY. How to use this record group as a source of records for a block?

    Thanks in advance.

    "query record group ' means that you fill out the Group Record with a query values not static.

    François

  • dynamically populate a record group on fly uisng LOV

    Hello

    I want to create dynamically populate a group of disks on the fly uisng LOV.


    1. here's how resemble the subject of record RG_BANKNAME group

    Subject: Folder group

    Name: RG_BANKNAME

    Record group Query: SELECT NAME, SHORT_NAME OF C_BANKS


    2. I create the button and when the user clicks on it will appear the LOV.



    DECLARE
    RG_ID RecordGroup;
    ERRCODE NUMBER;
    BOOLEAN status;
    BEGIN
    RG_ID: = Find_Group ('RG_BANKNAME');

    IF Id_Null (rg_id) THEN
    Message ("no such group: ', acknowledgement of RECEIPT");
    RAISE Form_Trigger_Failure;
    ON THE OTHER
    Errcode: = POPULATE_GROUP (rg_id);

    SET_LOV_PROPERTY ('LV_NAME', TITLE, 'My own LOV');
    SET_LOV_PROPERTY (groupname, 'LV_NAME', rg_id);

    SET_LOV_COLUMN_PROPERTY ('LV_NAME', 1, 'NAME', title);
    SET_LOV_COLUMN_PROPERTY ('LV_NAME', 1, width, 150);
    SET_LOV_COLUMN_PROPERTY ('LV_NAME', 2, title, 'SHORT NAME');
    SET_LOV_COLUMN_PROPERTY ('LV_NAME', 2, width, 100);

    status: = Show_LOV ('LV_NAME', 10, 20);

    In the CONTRARY CASE the status THEN
    Message ("you have not selected a value.");
    Bell;
    END IF;
    END IF;
    END;


    My question is should I create name object LOV 'LV_NAME "? given that I do not have it
    create on my design time, because I thought that it can be done dynamically on the fly.

    The problem is consistent that the Lov Id is not valid.

    Thank you


    David

    Published by: user445990 on May 24, 2011 21:19

    OK, so the LOV MUST exist at the time of the design, because you cannot create it dynamically.

    François

  • How to use record group to insert data into the hierarchy tree?

    Hello

    I had a hierarchical tree in my block and I want to use the record group to display
    in the hierarchy tree, call david_tree. He did work for the code I try below
    and I think it might be that the create_group_form_query was wrong? or miss an order?


    DECLARE
    htree;
    rg_data RECORDGROUP;
    v_ignore NUMBER;
    BEGIN
    htree: = Find_Item ('tree_block.david_tree');

    rg_data: = CREATE_GROUP_FROM_QUERY ('rg_bank',
    "select name, short_name".
    || "from css_banks");

    -Fill the record with data.

    v_ignore: = POPULATE_GROUP (rg_data);

    -Transfer the data from the record group to the hierarchical
    -tree and bring it to display.

    FTREE. SET_TREE_PROPERTY (htree, FTREE. (RECORD_GROUP, rg_data);

    END;


    Thank you


    David

    David,
    You get an error with your code? Looks like you took your example code help Forms. I don't really see a problem with the code, but the forms example gives an example of how create the record group used by the HTree so the Receiver General may be the cause of the problem. When I used the HTree, I used the FTREE. Procedure ADD_TREE_DATA to fill the tree. When I started working with HTree I created a wrapper package to simplify the process. You can watch how I work with the HTree in a demo that I published called: forms and how to: create a shape of the HIERARCHICAL tree.

    Hope this helps,
    Craig B-)

    If someone useful or appropriate, please mark accordingly.

  • change the record group for a lov

    Dear Sirs,
    I have a list of value (LOV) and I have 2 record group, and I want to associate each of these group record depends on the conidition
    for example

    If condition 1
    associate the record group 1 LOV
    on the other
    associate the record group 2 LOV
    end if;

    Please help me
    Thanks in advance

    Check the built-in SET_LOV_PROPERTY, you can use this then assign a recordgroup to a lov.

  • Fill area of the screen with the first value in the record group

    Hi guys, what the title essentially says. I have a display element that is populated by the by selecting the appropriate option in a LOV. Is there a method that I can put in when a new instance of the form or something else to fill the screen with the first item in the record group used to fill the lov to ensure when the load form display area is not empty. I know I have to hard just in code, but I would have the value come from the record group.


    Thank you

    Published by: user13390506 on August 25, 2010 05:39

    This works very well for me:

    Created a record group (RG1) with the following order of selection:

    select table_name, table_name from user_tables order by 1
    

    Created a button on the Web that are running the following:

    PROCEDURE pop IS
       rg_id RecordGroup;
       gc_id GroupColumn;
       col_val VARCHAR2(1000);
       n number ;
    BEGIN
    
       rg_id := Find_Group( 'rg1' ); 
    
       IF Id_Null(rg_id) THEN
       Message('Record Group rg1 does not exist.');
       RAISE form_trigger_failure;
       END IF; 
    
       n := Populate_Group( rg_id) ;
       gc_id := Find_Column( 'RG1.TABLE_NAME' ); 
    
       IF Not Id_Null(gc_id) THEN
         col_val := GET_GROUP_CHAR_CELL( gc_id, 1 );
         message(col_val);
       End if ;
    
    End;
    

    I guess the record_name.column_name at the top of case...

    François

  • How to share the record group between 2 forms

    Hi all

    Some might guide me how to send one record group to another form and how it is received

    programmaticaly

    any help or advice, that I enjoyed

    Thank you

    Hello
    Little late but was not on the development computer.
    In fact the data you are trying to recover also ensure the data type. I mean if you retrieve DIGITAL data record group for the first column you use fld_1 , you must have to use the built-in GET_GROUP_NUMBER_CELL . Like this..

    DECLARE
      rg_id recordgroup;
    BEGIN
      rg_id := FIND_GROUP('my_rg');
      IF NOT id_null(rg_id) THEN
       :ctrl.text_item8 := GET_GROUP_NUMBER_CELL('my_rg.fld_1', 1);
      END IF;
    END;
    

    If If the field you get the record group's CHARACTER then you must use the built-in function GET_GROUP_CHAR_CELL like that...

    DECLARE
      rg_id recordgroup;
    BEGIN
      rg_id := FIND_GROUP('my_rg');
      IF NOT id_null(rg_id) THEN
        :ctrl.text_item8 := GET_GROUP_CHAR_CELL('my_rg.fld_1', 1);
      END IF;
    END;
    

    And if the salvage value of DATE data type, then GET_GROUP_DATE_CELL like this...

    DECLARE
      rg_id recordgroup;
    BEGIN
      rg_id := FIND_GROUP('my_rg');
      IF NOT id_null(rg_id) THEN
        :ctrl.text_item8 := GET_GROUP_DATE_CELL('my_rg.fld_1', 1);
      END IF;
    END;
    

    So, in you case I think the department_id data type is numeric in the database, and you use GET_GROUP_CHAR_CELL which will not work. Use the first one I showed you for numeric values.

    And also use the trigger a TIME NEW FORM INSTANCE used to retrieve the value. I want to use the first example in this trigger. Then you can see the value of the result of the shared record group.

    -Clément

  • Record group using slider

    Hello world!

    I wonder if it is possible to use an oracle forms RECORD GROUP as a SLIDER? or do I have to create the same cursor query in my procedure?

    Thank you
    Guillaume

    You might loop through the data in the recordgroup using the builtin group, such as GET_GROUP_ROW_COUNT and GET_GROUP_CHAR_CELL, but it is not very effective. If it's just to get the same query, you can create a database view to "encapsulate" the logic in the database, and then use the view in the recordgroup and your cursor.

  • With the help of record group in the report server 11.1.1.2 is possible?

    Hello.

    I m triying to call report forms using the command RUN_REPORT_OBJECT, whith a record group (DATA_PARAMETER).

    allways show the error ' FRM-41214: cannot run reports.

    Possible to use this type of parameters int´s?.

    Thnaks and sorry for my English.

    DATA_PARAMETER does not work in Forms 10 G due to the change in the form of c/s to web architecture, so I don't think it will work again in form 11 G.

  • Creating dynamically record group.

    Hello

    I have multi line block. My req is I create record group dynamically based on some fields of line level. This item then my card code - key.

    DECLARE
    group_id RecordGroup;
    v_lms_lov lov.
    BEGIN

    group_id: = Create_Group_From_Query ("RG_LMSID",
    ' SELECT lms_id
    OF sify_lms_header
    WHERE from_location =: lines.from_location
    AND to_location =: lines.to_location; »

    v_lms_lov: = find_lov ('LOV_LMSID');

    set_lov_property (v_lms_lov, group_name, 'RG_LMSID');

    Set_Item_Property('LINES.) LMS_ID', LOV_NAME, 'LOV_LMSID');

    END;

    It is said, no record in lov. Anything I've missed.
    Or any other way to do this.
    Pl help.

    Thank you
    Kouadio

    Kouadio,

    Why you need dynamic disk group for this?, you can give the control names in the query of the record group. Then the query of the record group will be

    SELECT LMS_ID FROM SIFY_LMS_HEADER WHERE FROM_LOCATION = :LINES.FROM_LOCATION AND TO_LOCATION = :LINES.TO_LOCATION
    

    If you still want to use dynamic disk group creation, then try

    DECLARE
         RG_Group_ID RECORDGROUP;
    BEGIN
         RG_Group_ID := FIND_GROUP('RG_LMSID');
      IF NOT Id_Null(RG_Group_ID) THEN
              DELETE_GROUP(RG_Group_ID);
      END IF;
         RG_Group_ID := CREATE_GROUP_FROM_QUERY('RG_LMSID', 'SELECT LMS_ID FROM SIFY_LMS_HEADER WHERE FROM_LOCATION = ''' || :LINES.FROM_LOCATION || ''' AND TO_LOCATION = ''' || :LINES.TO_LOCATION || '''');
         SET_LOV_PROPERTY('LOV_LMSID',     GROUP_NAME, 'RG_LMSID');
         SET_ITEM_PROPERTY('LINES.LMS_ID', LOV_NAME,   'LOV_LMSID');
    END;
    

    Kind regards

    Manu.

    If my response or response from another person was helpful, please mark accordingly

  • The point list - record group Query - bad alignment order

    Dear all,

    When I try to concatenate two columns using the query of the record group and display in the list item, the alignment is not in good condition.

    For example; Here are the columns and data used in the process:

    SHORT_DESC CODE_VALUE DESCRIPTION
    ---------------------------------------------------------------------------------------------------------------------------------------------------
    ROLL1 customer - No accidental Production, by booking with another carrier, bad projection.
    Roll2 client project - accidental l/c, B/L, customs, samples, AMS, LAR.
    ABC - lack of vacuum ROLL3 lack of empty units.
    ABC CDE ROLL4 - Roll on decision of the AGR RRR.
    ROLL5 ABC XXX - Accidental IMO or denied OOG, operational problems, Cut & Run.
    ROLL6 ABC YYY - booking fictitious material buffer, dummy booking.

    This is the query of the record group used in forms:
    ----------------------------------------------------------------
    PROCEDURE p_when_new_form_instance
    IS
    GROUP_ID recordgroup;
    list_id question: = FIND_ITEM ('BLK_CONTROL.) LI_ROLL_REASON');
    rg_name VARCHAR2 (20): = "LI_ROLL_REASONS";
    status NUMBER;
    l_query VARCHAR2 (4000);
    BEGIN
    l_query: =.
    ' SELECT rpad (short_desc, 50, "") | "| ''|| description of the description, code_value code_value OF codes WHERE code_value IN ("ROLL1", "roll2", "ROLL3", "ROLL4", "ROLL5", "ROLL6")';
    GROUP_ID: = CREATE_GROUP_FROM_QUERY (rg_name, l_query);
    status: = POPULATE_GROUP (GROUP_ID);
    POPULATE_LIST (list_id, GROUP_ID);
    EXCEPTION
    WHILE OTHERS
    THEN
    pl_common.when_others;
    END;
    -----------------------------------

    In addition, I have my property list item as the default "" MS SANS SERIF"fonts and when I run in Forms Builder get the alignment as below.

    Result:
    ====
    DESCRIPTION CODE_VALUE
    Customer - Non-accidental. Production, by booking with another carrier, bad projection.     ROLL1
    Customer - Accidental | L/c, B/L project, customs, samples, AMS, LAR.     ROLL2
    ABC - lack of vacuum | Lack of empty units.     ROLL3
    ABC ORDER - to the reversal. Decision of the AGR RRR.     ROLL4
    ABC XXX - Accidental | IMO / denied OOG, operational problems, Cut & Run.     ROLL5
    ABC YYY - booking fictitious | Reservation of equipment, fake buffer.      ROLL6

    More high of the order is not the desired result because all the | (vertical bar) should display in the correct order as below.
    Expected result:
    ==========
    DESCRIPTION CODE_VALUE
    Customer - Non-accidental. Production, by booking with another carrier, bad projection.     ROLL1
    Customer - Accidental | L/c, B/L project, customs, samples, AMS, LAR.     ROLL2
    ABC - lack of vacuum | Lack of empty units.     ROLL3
    ABC ORDER - to the reversal. Decision of the AGR RRR.     ROLL4
    ABC XXX - Accidental | IMO / denied OOG, operational problems, Cut & Run.     ROLL5
    ABC YYY - booking fictitious | Reservation of equipment, fake buffer.      ROLL6


    I tried and RPAD LPAD the alignment problem is still there; I know that the issue is due to the fixed length of the police.
    But is there a solution to replace it it will be a great help.



    So please help!


    Thank you...

    Kind regards
    Sunil.G

    If you can not use non proportional fonts, then forget about having any special alignment, because with proportional fonts, room occupied by each letter is different.

    François

Maybe you are looking for