Hierarchical data where the records on a given level point to next level

WITH
    Data(Entity, Next_Entity, Datum)
AS
    (
     SELECT 'A', 'B', 'Edward'    FROM Dual UNION ALL
     SELECT 'B', 'C', 'Lorina'    FROM Dual UNION ALL
     SELECT 'C', 'D', 'James'    FROM Dual UNION ALL
     SELECT 'C', 'D', 'Alice'    FROM Dual UNION ALL
     SELECT 'D', 'E', 'Edith'    FROM Dual UNION ALL
     SELECT 'D', 'E', 'Rhoda'    FROM Dual UNION ALL
     SELECT 'A', 'F', 'Albert'    FROM Dual UNION ALL
     SELECT 'F', 'G', 'Violet'    FROM Dual UNION ALL
     SELECT 'F', 'G', 'Frederick'    FROM Dual UNION ALL
     SELECT 'G', 'H', 'Lionel'    FROM Dual
    )
SELECT
    Entity,
    Next_Entity,
    Datum
FROM
    Data
START WITH
    Entity = 'A'
CONNECT BY
    Entity = PRIOR Next_Entity;

Results in:

E N DATUM

- - ---------

An Edward B

B C Lorina

C D James

D E Edith

D E Rhoda

C D Alice

D E Edith

D E Rhoda

An Albert F

F G Violet

G H Lionel

F G Frederick

G H Lionel

What I want is:

E N DATUM

- - ---------

An Edward B

B C Lorina

C D James

C D Alice

D E Edith

D E Rhoda

An Albert F

F G Violet

F G Frederick

G H Lionel

Each record points to one or more children.

For any level, children, stressed are the same.

I only go to any given child, once.

Hello

CONNECTION BY ordering the release, so that the children come immediately after their parents.

If you SEPARATE the outcomes, so we know not what order the results are in.  You can get the resutls you purely by chance, especially in a small set of data, but it is still just a coincidence.

I think you need something like this:

WITH distinct_data AS

(

SELECT DISTINCT entity

next_entity

FROM the data

)

tree AS

(

SELECT entity

next_entity

ROWNUM AS r_num

OF distinct_data

START WITH entity = "A".

Entity = next_entity PRIOR CONNECTION

)

SELECT t.entity

t.next_entity

d.datum

TREE t

JOINING data d = d.next_entity t.next_entity

ORDER BY r_num

;

Here, the SEPARATE operation is done before CONNECT you, so you don't have to worry about destroying the order of the CONNECT BY query.

Tags: Database

Similar Questions

  • Keep the data on the record points and serve the rest

    Hello world!

    I think somehow either CompressWorkspace [tree] or PurgeTable what we want to do, but somehow I don't see exactly how...

    Here's our situation: the admin of our customer demand can create backup points. He made what is called "data freezing" happens a few times a year (3-4).

    The database is created using WO_OVERWRITE to keep a track full edit. However, for older data we now to just keep recording data and delete what that it is between the two. Only for the most recent backup points, we always want to keep the complete history. Is there a way to do this?

    To clarify things, with some text-Art, this might look like this for 5 Savepoints SP1... SP5:

    [SP1]-[SP2]-[SP3] hhh [SP4] [SP5] of hhh hhh [LATER]

    where - means "no historical data here" and "hhh" means "here for historical data.

    My first guess was the CompressWorkspace procedure, but if I give two points for first registration is deleted. What we want to do is give two points of record, have deleted all the data of the history between the two and keep both the backup points. In the example above, we would like to compress between SP1 and SP2 the SP2 and SP3.

    Note: the database will be migrated soon to 11 GR 2, so all the features of the OWM until this version can be used for a solution.

    Any help is appreciated!

    Kind regards

    Andreas

    Hi Andreas,

    You don't want to use CompressWorkspace.  Specify the backup even point to firstSP and secondSP and the parameter compress_view_wo_overwrite set to true.  Thus, for example:

    SQL > dbms_wm.compressworkspace exec ('LIVE', true, "SP1", "SP1");

    This should be done for each backup point where you want to delete the history.  The procedure would remove all lines for each primary key value, with the exception of the most recent in the backup point.  It cannot be done on a variety of checkpoints at the same time, as that would remove the previous save points, as you pointed out.

    Kind regards

    Ben

  • How to insert date in the record being updated (MySql, PHP)

    I want to be able to update an existing record and automatically include the date that the change was made when I submit the data to the MySql database.

    I saw this thread on how to date on a new record using NOW()

    http://forums.Adobe.com/thread/855152?decorator=print & displayFullThread = true #855152

    After reading it, I have successfully changed my page insert.php.

    Here is the code of my insert.php page that works well:

    If ((isset($_POST["MM_insert"])) & & ($_POST ["MM_insert"] == "form1")) {}
    $insertSQL = sprintf ("INSERT INTO standardsclient_tbl (client_name, pantone_ref1, pantone_ref1_image, font_ref1, font_ref1_image, 'date') VALUES (%s, %s, %s, %s, %s, NOW())", ")
    GetSQLValueString ($_POST ['client_name'], "text").
    GetSQLValueString ($_POST ['pantone_ref1'], "text").
    GetSQLValueString ($_POST ['pantone_ref1_image'], "text").
    GetSQLValueString ($_POST ['font_ref1'], "text").
    GetSQLValueString ($_POST ['font_ref1_image'], "text").
    GetSQLValueString ($_POST ['date'], 'date'));

    It's the update.php page, I changed 'date' = %s to 'date' = NOW () , but this has made that prevents me from updating the record all the.

    If ((isset($_POST["MM_update"])) & & ($_POST ["MM_update"] == "form1")) {}
    $updateSQL = sprintf ("UPDATE standardsclient_tbl SET client_name = %s pantone_ref1 = %s pantone_ref1_image = %s, font_ref1 = %s, font_ref1_image = %s, 'date' = NOW () WHERE the client_ID = %s",
    GetSQLValueString ($_POST ['client_name'], "text").
    GetSQLValueString ($_POST ['pantone_ref1'], "text").
    GetSQLValueString ($_POST ['pantone_ref1_image'], "text").
    GetSQLValueString ($_POST ['font_ref1'], "text").
    GetSQLValueString ($_POST ['font_ref1_image'], "text").
    GetSQLValueString ($_POST ['date'], 'day'),
    GetSQLValueString ($_POST ['client_ID'], "int"));

    You can see where I have gone wrong?

    Thank you

    In the update query, you have 6 %s but GetSQLValueString 7. That's your problem.

  • Convert data in hierarchal of hierarchical data for the creation of the tree

    Hi guys,.

    I tried to figure this out for about two days together now and I'm still stuck and I see no possible solution that does not involve a new creation of the table.
    I want to create a tree to navigate through projects and tasks, I use the demo "Task Manager" app, which I customized it a bit to fit my needs.

    Basically, I can't create the tree because the relationship between projects and tasks is not a hierarchical relationship, it's a relationship 1: n like this:

    __Projects__
    ID (PK)
    PROJECT NAME



    ___Tasks___
    ID (PK)
    Project (done FK reference Projects.ID)


    So what I have to do is to "force" this relationship 1: n with a hierarchical relationship by creating a query (view) that links the two tables into one and have 2 columns, I can use as ID and PARENT_ID for the creation of the tree.

    This is the data model:


    CREATE TABLE 'EBA_TASK_PROJECTS '.
    (NUMBER OF 'ID',
    'PROJECT_NAME' VARCHAR2 (255),
    "CREATED_ON" DATE NOT NULL ACTIVATE.
    'CREATED_BY' VARCHAR2 (255) NULL NOT ACTIVATE.
    DATE OF THE "UPDATED_ON"
    "UPDATED_BY' VARCHAR2 (255),
    'FLEX_01' VARCHAR2 (4000).
    'FLEX_02' VARCHAR2 (4000).
    'FLEX_03' VARCHAR2 (4000).
    'FLEX_04' VARCHAR2 (4000).
    'FLEX_05' VARCHAR2 (4000).
    NUMBER OF "PARENT_ID"
    VARCHAR2 (1) 'IS_ACTIVE ',.
    VARCHAR2 (4000) "DESCRIPTION."
    CONSTRAINT CHECK of 'EBA_TASK_PROJECTS_ACTIVE_CC' (in is_active ('Y', 'n')) ENABLE,.
    ENABLE 'EBA_TASK_PROJECTS_PK' CONSTRAINT PRIMARY KEY ('ID')
    ) ; ALTER TABLE 'EBA_TASK_PROJECTS' ADD 'EBA_TASK_PROJECTS_FK' OF CONSTRAINT FOREIGN KEY ('PARENT_ID')
    REFERENCES 'EBA_TASK_PROJECTS' ('ID') ON DELETE CASCADE ACTIVE;


    CREATE TABLE 'EBA_TASK_TASKS '.
    (SELECT 'ID' NUMBER NOT NULL,)
    ACTIVATE THE "PROJECT" NUMBER NOT NULL,
    ACTIVATE THE "TASK_PRIORITY" VARCHAR2 (400) NOT NULL,
    ACTIVATE THE "TASK_DIFFICULTY" VARCHAR2 (400) NOT NULL,
    ACTIVATE THE "TASKNAME" VARCHAR2 (4000) NOT NULL,
    VARCHAR2 (4000) "TASK_DETAILS."
    "CREATED_ON" DATE NOT NULL ACTIVATE.
    DATE 'DONE ',.
    ACTIVATE THE 'CREATED_BY' VARCHAR2 (400) NOT NULL,
    'STATUS' VARCHAR2 (4000).
    DATE OF THE "UPDATED_ON"
    "ON THE ROAD" DATE.
    NUMBER OF "TASK_PREDEFINED_ID."
    "UPDATED_BY' VARCHAR2 (255),
    ACTIVATE THE "USER_NAME" VARCHAR2 (255) NOT NULL,
    'FLEX_01' VARCHAR2 (4000).
    'FLEX_02' VARCHAR2 (4000).
    'FLEX_03' VARCHAR2 (4000).
    'FLEX_04' VARCHAR2 (4000).
    'FLEX_05' VARCHAR2 (4000).
    NUMBER OF "PERCENTAGE."
    ENABLE 'EBA_TASK_TASKS_PK' CONSTRAINT PRIMARY KEY ('ID')
    ) ; ALTER TABLE 'EBA_TASK_TASKS' ADD 'EBA_TASK_TASKS_PROJECTS_FK' OF CONSTRAINT FOREIGN KEY ('PROJECT')
    REFERENCES 'EBA_TASK_PROJECTS' ('ID') ON DELETE CASCADE ACTIVE;

    I use APEX4.0

    It's good enough that this guy, hope you can help me with this. I'm really stuck on this and I'm about to give up.

    Hello

    So what I have to do is to "force" this relationship 1: n with a hierarchical relationship by creating a query (view) that links the two tables into one and have 2 columns, I can use as ID and PARENT_ID for the creation of the tree.

    I'd say you need a UNION rather than a JOIN.
    Something like:

    WITH project_task_view AS (
     SELECT 'P'||to_char(id) as id
          , null as parent_id
          , project_name as node_name
     FROM eba_task_projects
     UNION ALL
     SELECT 'T'||to_char(id)
          , 'P'||to_char(project_id)
          , task_name
     FROM eba_task_tasks
    )
    SELECT id, parent_id, node_name, level
    FROM project_task_view
    START WITH parent_id IS NULL
    CONNECT BY PRIOR id = parent_id
    ;
    
  • Mapping of extraction of SAP data, where the JCO files need to be copied?

    Hi all

    I have the following environment.

    Customer OWB: Windows7
    OWB server: Linux x86_64
    SAP server: Windows Server 2003

    I need to create the OWB mapping to extract data from SAP to the target of the Oracle.

    Let me know what are the required files JCO and where should I copy?

    Do I need to copy them to the customer owb and the server or is it enough to copy them on the client computer only?

    Thank you and best regards,
    Pnreddy.

    Customer OWB only is not supported on 64-bit Windows, I wanted to just let you know since you mentioned Windows 7...

    For windows, you will need sapjco.jar, librfc32.dll and 3 files sapjcorfc.dll. You can get them from the SAP installation cd or download on http://service.sap.com/connectors for your SAP version. You will need to have a SAPnet account to do so.
    You can place the files sapjcorfc.dll and sapjco.jar in OWB_HOME\owb\lib\int and in OWB_HOME\owb\bin-librfc32.dll and also set the path to reference the directory.

    For linux, you will need librfcccm.so, libsapjcorfc.so and sapjco.jar. Also set the LD_LIBRARY_PATH to reference these file locations.

    If you extract metadata from SAP then you need only on the OWB client, but if you plan to run ABAP programs on the SAP system, you will need to set up on the side server.

  • Writing a query to display data WHERE the data in column do not begin with 'Rep '.

    Hello

    * (Assuming file_name is a column of table $file_log) *.

    Please tell me

    How to write a query where I want to display the data for which File_Name does not begin with name like Reports_

    Please tell me.

    Thank you

    Hello

    I hope that this might help

    SELECT * FROM FILE_LOG_TABLE WHERE FILE_NAME NOT LIKE 'Reports_%';
    

    see you soon

    VT

  • Select with the DATE WHERE the...

    Hi all!

    I need to select with where condition on cirtain cust_date date (date) specifying columns say date01 = 25 August 10 'and time range somewhere between time01 = 7:15:00 ' and time2 = 9:30:00 ' ('HH24:MI:SS).
    I have some test data and I saw still some trouble with my select particular regarinding of time slot.

    Can someone tell me what will be the easiest way to do this, especially for the begiinner;

    SELECT * FROM TABLE1 WHERE cust_date > to_date (August 25, 2010 7:15:00 ',' DD-MON-YY HH24:MI:SS')...

    I just do to_date after >?


    TX
    Trent

    Trento wrote:
    Hi all!

    I need to select with where condition on cirtain cust_date date (date) specifying columns say date01 = 25 August 10 'and time range somewhere between time01 = 7:15:00 ' and time2 = 9:30:00 ' ('HH24:MI:SS).
    I have some test data and I saw still some trouble with my select particular regarinding of time slot.

    Can someone tell me what will be the easiest way to do this, especially for the begiinner;

    SELECT * FROM TABLE1 WHERE cust_date > to_date (August 25, 2010 7:15:00 ',' DD-MON-YY HH24:MI:SS')...

    I just do to_date after >?

    TX
    Trent

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions183.htm#SQLRF06132

    Connected to Oracle Database 11g Enterprise Edition Release 11.1.0.7.0
    Connected as SYS
    
    SQL> desc SH.SALES
    Name          Type         Nullable Default Comments
    ------------- ------------ -------- ------- -------------------------------------------------------------------------------------------
    PROD_ID       NUMBER                        FK to the products dimension table
    CUST_ID       NUMBER                        FK to the customers dimension table
    TIME_ID       DATE                          FK to the times dimension table
    CHANNEL_ID    NUMBER                        FK to the channels dimension table
    PROMO_ID      NUMBER                        promotion identifier, without FK constraint (intentionally) to show outer join optimization
    QUANTITY_SOLD NUMBER(10,2)                  product quantity sold with the transaction
    AMOUNT_SOLD   NUMBER(10,2)                  invoiced amount to the customer                                                             
    
    SQL>
    SQL> SELECT *
      2  FROM SH.SALES S
      3  WHERE S.TIME_ID >= to_date('19970102','YYYYMMDD')
      4  AND ROWNUM < 4
      5  ;
    
       PROD_ID    CUST_ID TIME_ID     CHANNEL_ID   PROMO_ID QUANTITY_SOLD  AMOUNT_SOLD
    ---------- ---------- ----------- ---------- ---------- ------------- ------------
            37        368 01/01/1998           2        999          1.00        63.57
            37       4687 01/01/1998           2        999          1.00        63.57
            37       8302 01/01/1998           2        999          1.00        63.57
    SQL>  SELECT *
      2  FROM SH.SALES S
      3  WHERE S.TIME_ID >= to_date('19970102 10:12:00','YYYYMMDD HH24:MI:SS')
      4  AND S.TIME_ID < to_date('20000102 10:12:00','YYYYMMDD HH24:MI:SS')
      5  AND ROWNUM < 4
      6  ;
    
       PROD_ID    CUST_ID TIME_ID     CHANNEL_ID   PROMO_ID QUANTITY_SOLD  AMOUNT_SOLD
    ---------- ---------- ----------- ---------- ---------- ------------- ------------
            37        368 01/01/1998           2        999          1.00        63.57
            37       4687 01/01/1998           2        999          1.00        63.57
            37       8302 01/01/1998           2        999          1.00        63.57
    
    SQL> 
    
    SQL>
    SQL>  SELECT *
      2  FROM SH.SALES S
      3  WHERE S.TIME_ID >= to_date('January 15, 1989, 11:00:00','Month dd, YYYY, HH:MI:SS',
      4       'NLS_DATE_LANGUAGE = American')
      5  AND S.TIME_ID < to_date('January 15, 2000, 11:00:00','Month dd, YYYY, HH:MI:SS',
      6       'NLS_DATE_LANGUAGE = American')
      7  AND ROWNUM < 4
      8  ;
    
       PROD_ID    CUST_ID TIME_ID     CHANNEL_ID   PROMO_ID QUANTITY_SOLD  AMOUNT_SOLD
    ---------- ---------- ----------- ---------- ---------- ------------- ------------
            37        368 01/01/1998           2        999          1.00        63.57
            37       4687 01/01/1998           2        999          1.00        63.57
            37       8302 01/01/1998           2        999          1.00        63.57
    
    SQL>
    SQL> SELECT *
      2  FROM SH.SALES S
      3  WHERE S.TIME_ID >= to_date('14-Feb-1998 11:00:00','DD-Mon-YYYY HH24:MI:SS',
      4       'NLS_DATE_LANGUAGE = American')
      5  AND S.TIME_ID < to_date('17-Mar-2000 11:00:00','DD-Mon-YYYY HH24:MI:SS',
      6       'NLS_DATE_LANGUAGE = American')
      7  AND ROWNUM < 4
      8  ;
    
       PROD_ID    CUST_ID TIME_ID     CHANNEL_ID   PROMO_ID QUANTITY_SOLD  AMOUNT_SOLD
    ---------- ---------- ----------- ---------- ---------- ------------- ------------
            36       2168 15/02/1998           3        999          1.00        51.29
            36       7237 15/02/1998           3        999          1.00        51.29
            36       7678 15/02/1998           3        999          1.00        51.29
    
    SQL>  
    
  • Import the data from the record music in Windows Media Player

    I'm importing WAV files in the music folder.  The data associated with these files include time and size of the file, running that were determined by Windows and listed with each track.  Windows Media Player has the value import these files, it does.  However, in random cases, the execution time is not captured by Media Player, and so they are reported in the burn list and will not burn.  I get a message that if I play the track, the running time can be picked up, but it did not work.  The information is complete in the music folder.  Is it possible that I can manually transfer these data? (Note - since posting this question, I decided to experiment.  I removed the tracks in Media Player lacking of run times and their re-importation with the menu item drop library «Add to library...» "and they have been re-imported with run times. Eureka!)

    Hi sailorsteve,

    Are you referring to the length of the track?

    You can follow the steps (in the link to uninstall windows media player applies to windows 7) provided by Azam K, Microsoft product support, see the link below

    http://social.answers.Microsoft.com/forums/en-us/w7desktop/thread/5fc4ee85-60b4-498C-81A4-262bb8904bca

    Yes, you can add or edit media information, please take a look at the link below


    Add or edit media information
    Windows Media Player

    http://Windows.Microsoft.com/en-us/Windows-Vista/add-or-edit-media-information-in-Windows-Media-Player

    Please post if you have any questions

    Thank you, and in what concerns:

    Ajay K

    Microsoft Answers Support Engineer

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • How to extract string in JSON data where the value in a table

    Hello

    Structure of JSON string

    {'name': 'John', 'name': 'kumar', 'address': [{'Address1': 'value', 'place': 'value'}, {'address2': 'value', 'place': 'value'}]}

     


    How to extract the value of the address of the list.

    If you have control over the format of data, it is best to rename address1 and address2 to have the same name, for example "address". Then, it can be analyzed that way (I've also simplified other code a bit):

    JsonDataAccess jda;
    QVariant v = jda.loadFromBuffer(jsonString);
    QVariantMap m = v.toMap();
    QString name = m["name"].toString();
    QString surname = m["surname"].toString();
    QVariantList addresses = m["address"].toList();
    foreach (QVariant addr, addresses)
    {  QVariantMap addrMap = addr.toMap();
      QString addressValue = addrMap["address"].toString();
      QString place = addrMap["place"].toString();
    }
    
  • Hierarchical data in the component of the tree should not be visible

    JDeveloper version - 11.1.1.7.0

    Default in the ADF, the performance of a page with a tree component, existing hierarchies are displayed as trees.


    For my requirement the TRIE hierarchies will not be displayed and component of the tree must be empty when the page runs.

    Why not just use the executeEmptyRowSet(), as described here:

    http://www.jobinesh.com/2010/05/displaying-empty-table.html

  • Increamental Dates check the records in the table

    My professional background is in the history table,
    I would like to write a query that search job history dates are correct.
    concerning

    rownum ID startdate enddate jobtitle
    1 200 xxxx 01.01.1990 30.12.2000
    2 300 yyyyyy 01.01.2001 15.07.2006
    3 400 zzzzzz 16.07.2006 null



    start dates or (endates) will check the required query like 01.01.1990 < = 01.01.2001 < = 16.07.2006

    I use ORACLE 10 g Standard Ed.

    concerning

    Edited by: Siyavus on September 14, 2009 12:32

    Edited by: Siyavus on September 14, 2009 12:34

    something like

         , case when lead (startdate) over (order by startdate) > startdate
                  or lead (startdate) over (order by startdate) is null
           then 'OK'
           else 'NOK'
           end
    

    as in

    SQL> with test as
      2  (
      3  select 200 id, 'xxxx'   jobtitle, to_date ('01.01.1990', 'dd.mm.yyyy') startdate, to_date ('30.
    12.2000', 'dd.mm.yyyy') enddate from dual union all
      4  select 300 id, 'yyyyyy' jobtitle, to_date ('01.01.2001', 'dd.mm.yyyy') startdate, to_date ('15.
    07.2006', 'dd.mm.yyyy') enddate from dual union all
      5  select 400 id, 'zzzzzz' jobtitle, to_date ('16.07.2006', 'dd.mm.yyyy') startdate, null from dua
    l
      6  )
      7  select startdate
      8       , case when lead (startdate) over (order by startdate) > startdate
      9                or lead (startdate) over (order by startdate) is null
     10         then 'OK'
     11         else 'NOK'
     12         end
     13    from test
     14  /
    01-JAN-90 OK
    01-JAN-01 OK
    16-JUL-06 OK
    SQL> 
    
  • 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.

  • How to insert 10,000 records test data into the emp table

    Hi I am new to oracle can someone please help me write a program so that I can insert the test data into the emp table
    SELECT       LEVEL empno,
                 DBMS_RANDOM.string ('U', 20) emp_name,
                 TRUNC (DBMS_RANDOM.VALUE (10000, 100000), 2) sal,
                 DBMS_RANDOM.string ('U', 10) job,
                 TO_DATE ('1990-01-01', 'yyyy-mm-dd')
                 + TRUNC (DBMS_RANDOM.VALUE (1, 6000), 0)
                   hiredate,
                 CASE
                   WHEN LEVEL > 10 THEN TRUNC (DBMS_RANDOM.VALUE (1, 11), 0)
                   ELSE NULL
                 END
                   mgr,
                 TRUNC (DBMS_RANDOM.VALUE (1, 5), 0) deptno
    FROM         DUAL
    CONNECT BY   LEVEL <= 10000
    
  • Filtered hierarchical data - previous available ancestor?

    I'm trying to find a solution to a problem with hierarchical data and the concept of the closest available ancestor – my platform is gr 10, 2 and 11 GR 2.  I give myself a few hierarchical data (in its simplest form it is in the form ID, NAME, PARENT_ID, where of the PARENT_ID since ID links).

    For example:

    with qryData like)

    Select 1 as ID, 'Bert' as NAME, to_number (null) as PARENT_ID from dual union

    Select 2 as ID, 'Brand', 1 double Union

    Select 3 as ID, 'Brenda', 1 double Union

    Select option 4 as ID, 'Mike', 3 double Union

    Select 5 as ID, 'Steve', 4 double Union

    Select 6 as ID, 'John', 2 double Union

    Select 7 as ID, 'Jo', 6 double Union

    Select ID, "Jim", 2 double Union 8

    Select 9 as ID, 'Jane', the double 7

    )

    Select q.*, sys_connect_by_path (ID, ' /') ID_PATH

    of qryData q

    Start by parent_id is null

    Connect ID PARENT_ID = prior

    /

    ID NAME PARENT_ID ID_PATH

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

    1 Bert 1

    2. Mark 1/1/2

    6 Jean 2/1/2/6

    7 Jo 6/1/2/6/7

    Jane 9 7/1/2/6/7/9

    8 Jim 2/1/2/8

    3 Brenda-1/1/3

    4 mike 3/1/3/4

    5 Steve 4/1/3/4/5

    In reality, this data set can be several thousand rows with dozens of levels of nesting, the several nodes to start without parent but especially often filtered, so some arbitrary lines are missing.  When this happens, I need to find the closest available ancestor that appears in the list. "The closest available ancestor" is closest relationship to ancestor in your family tree which still exists in the filtered list found from parent, then upward contuniing to grandparent, great-grandparent... nth grandparent grand until an ancestor is found.


    For example:

    ID NAME PARENT_ID ID_PATH AVAIL_ANCESTOR_ID

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

    1 Bert 1

    Jean 6 2 1 1/2/6

    Jim 8 2 1 1/2/8

    Jane 9 7 6 1/2/6/7/9

    Brenda 3 1 1 1/3

    Steve 5 4 3 1/3/4/5

    For example.  Who is Steve closest ancestor in the filtered list?

    Steve's family tree is: / Bert/Brenda/Mike/Steve

    Mike (ID = 4) is not in the filtered list, so we move on Brenda, what is.  Brenda, ID = 3, so ANCESTOR_ID = 3

    I have access to the original table, so that can join the list filtered to the full table, I can also ask other columns (such as ROWID, and ROWNUM, LEVEL SYS_CONNECT_ROOT) to be included in the filtered set.  I tried various methods to achieve this, but all seem to be quite poor in performance (the columns ID and PARENT_ID indexed as appropriate) or does not quite give the correct result, such as...

    1. the analysis of the ID_PATH and the treewalking on this basis and to join the list...

    Select distinct CUSTOMER_ID, regexp_substr (ID_PATH, "[^ /] +', 1, level") as ANCESTOR_ID

    of qryData

    connect regexp_substr (ID_PATH, "[^ /] +', 1, level") is not null

    2 anti-assemblage to return to the full list in order to identify the missing elements, then for those treewalking.

    3 write a function that return treewalks.

    It of a difficult problem, so someone can think a solution that works well?  Ideally, I try to find a SQL based solution?

    Hello

    paulzip wrote:

    It is a clever solution!  The only problem I have is that I wouldn't be able to generate "good_id_path" as part of the filtered list, filtering is not done by me and is done once the id_path is generated.  I have to join the most complete list list filtered back to generate, unless there is a tweak to do?

    I see it; You are given connect_by_results (with id_path), and that's what you have to work with, in addition to the original table.

    Here's one way:

    SELECT d.id d.name, d.parent_id, d.id_path

    MIN (a.id) DUNGEON (DENSE_RANK LAST ORDER BY a.id_path) AS avail_ancestor_id

    OF connect_by_results d

    LEFT OUTER JOIN connect_by_results has the d.id_path AS a.id_path. '/%'

    GROUP BY d.id d.name, d.parent_id, d.id_path

    ORDER BY d.id_path

    ;

    The fastest way depends on a lot of things, some may not be known until the moment of execution.  The query above could be better if the number of rows in the result set is small, but you don't know anything else about them (for example, if all have a common ancestor).

  • Problem with negative filters of refinement and the source of data on the OID 2.3

    Hello

    I have a problem using the filters of negative refinement on a data source with Information discovered 2.3

    Here is the configuration of data source

    {
    "baseFunctions":]
    {
    "attributeKey": "COMPANY"
    "attributeValue": "PROMO."
    'class': 'com.endeca.portal.data.functions.NegativeRefinementFilter '.
    },
    {
    'class': 'com.endeca.portal.data.functions.RecordFilter ',.
    'recordFilter': 'OR (OID_RECORD_TYPE:RES, OID_RECORD_TYPE:DEF).
    }
    ],
    "datastoreName": "datastorename",
    'name': 'ABC ',.
    "port": "7770."
    "Server": "XYZ".
    }

    When I reached a dashboard page where all the portlets using this data source, the record filter is applied as expected. However, for negative refinement filter, so that it appears in the portlet of the breadcrumb, it has no effect on the data set. Guided navigation always displays the value as a dimension as possible and I can see in my table of results as the data was not deleted by the negative refinement filter. I tried to restart Tomcat, without effect.
    If I go to the guided navigation and define negatively this value on the dimension of the COMPANY, the data gets filtered and I get 2 negative improvements will appear in the navigation bar to the same value (!)

    Is there something escapes me to configure negative refining filter?

    Thank you

    Your configuration is correct.

    I see two possible problems, but we are really just shooting in the dark:

    (1) "rogue whitespace.
    -If your value is not actually "PROMO" "PROMO", then your filter would not exclude anything. This would also explain why you might then add a negative refinement for the "real value". To validate this, use a browser with some debugging functions (i.e., Chrome), have your applied by default negative refinement and then "apply manually" in Studio.

    And then open the browser debug mode (chrome, right click on the value you just added and click 'Inspect element'). If all goes well, the HTML code will show a little differently, and you can see the white space in the manually added refinement.

    (2) it would happen to be a managed attribute? I think that the managed attribute values can have display names and real names and real name should be used for filtering purposes. I doubt that's the problem, but it's the only other thing I could think of...

    Kind regards

    Patrick Rafferty
    Branchbird

Maybe you are looking for