connect by query, element need root for each line

Hello

I'm working on a hierarchical query using connection by front. Each node in the tree has two properties, a type and a sequence.

The table that contains the hierarchy has 4 fields:
element_type_from
element_sequence_from
element_type_to
element_sequence_to

Each child has a parent, a parent can have several childeren. For a map, the element_type_to and element_sequence_to fields are zero.

To generate a tree, you can run:
select element_type_to
,      element_sequence_to
from   element_hierarchy
start with element_type_from = [root_element_type]
       and element_sequence_from = [root_element_sequence]
connect by prior element_type_to = element_type_from
       and prior element_sequence_to = element_sequence_from
That works well... but... not only don't want child elements, I would like to return the sequence of element root for each child (in our table is a type of root element is always the same). There are several root elements and I want to create a list containing all the trees and each node in the tree must have its roots as well.

There is the possibility to use sys_connect_by_path. This returns the root, but also the full path to the current child. It also returns a varchar2, requiring to be substr-ed and to_number-ed to get the sequence... not nice.

warning, extremely ugly (but functional) code:
select element_type_to
,      element_sequence_to
,      to_number(substr(sys_connect_by_path(element_sequence_from ,','),2,instr(sys_connect_by_path(element_sequence_from ,',') ||',',',',2)-2)) root_sequence
from   element_hierarchy
start with element_type_from = [root_element_type]
       and element_sequence_from = ( select [root_element_sequence] from all_root_elements )
connect by prior element_type_to = element_type_from
       and prior element_sequence_to = element_sequence_from
There must be something simple I'm missing here! Can you help me?

Edit: Oops, the database version is 10.2.0.4.0

CONNECT_BY_ROOT maybe?

Tags: Database

Similar Questions

  • I need avg for each lines dept of sage, matched and unmatched wage table

    Hi gurus,
    I doubt in sql, the employee table and department table two tables are there.

    1. I need pay for avg to each dept wise.

    2. matched and unmatched in the rows of the table

    in a request format

    Thanks and greetings
    k.Raghavan

    945795 wrote:
    Hi gurus,
    I doubt in sql, the employee table and department table two tables are there.

    Personally, it looks more like a HOME and WORK, only a DOUBT! What are your efforts on your bottom of DOUBTS?

    1. I need pay for avg to each dept wise.

    select department_id, avg(salary)
      from hr.employees
     group by department_id;
    

    2. matched and unmatched in the rows of the table

    The number of matching rows:

    select employee_id, department_name
      from hr.employees natural join hr.departments;
    

    Unpaired lines:

    select department_id, department_name
      from hr.departments d
     where not exists (
                    select 'x'
                      from hr.employees e
                     where d.department_id = e.department_id
                  )
    
  • How to access a column value in a Select list in a tabular presentation for each line

    Hello

    Environment: Using Oracle APEX v4.2.1 on an Oracle 11 g 2 DB

    In a tabular presentation using the following example query, i.e.:

    select
    "EMPNO",
    "EMPNO" EMPNO_DISPLAY,
    "ENAME",
    "HIREDATE",
    "SAL",
    "DEPTNO",
    "MY_LOV"
    from"#OWNER#"."EMP"
    
    

    I need access to every line of my sub form of table, the EMPNO of this line value, within a list of selection (query based LOV) in the column "MY_LOV."

    So, basically, the MY_LOV column in my table presentation, would be a list of selection (query based LOV) where MY_EMPNO =: EMPNO (first column in the select statement above), for each line of the tabular presentation.

    With the help of a picture ( Tom's Blog ) and assuming 'Deptno' column here is actually my new column, i.e. "MY_LOV, I want to know how this list of selection based on lov query would be able to access each EMPNO down in the form of tables, i.e. 7839, 7698, 7782 etc.?

    overview.png

    Any help would be appreciated.

    Thank you.

    Tony.

    Hi Tony,.

    Take a look at the API APEX_ITEM for LOV

    http://docs.Oracle.com/CD/E37097_01/doc/doc.42/e35127/apex_item.htm#AEAPI208

    Kind regards

    Brad

  • Use: OLD and: NEWS in the triggers without oracle for each line

    I use Oracle 10 g.
    I want to insert a row in the table of the newspaper by each Witch of the query is executed on a table.
    And I want to insert on the line at a table of detailed log for each row changed in a query.
    I want to add modification date and time for each line in the two tables of the newspaper and I want it to be similar.

    So, I'm curious about using old and new variables without using for each row on the creation of the trigger. Is this possible?
    Or maybe I can score some variables static for this query (so sysdate will be the same and some of the Pavilion for the insertion of small newspapers)?
    Or maybe is there other ways to do it?

    LeopoldStoch wrote:
    But if I use sysdate in each trigger and it will update something as my sysdate 100000 lines will be different for different lines but I want it to be time and on the same date.

    Hi Leopold,

    Then today is your lucky day :-): sysdate is the same for all the DML. Even if it takes more than one second:

    SQL> create table rob
      2  ( id int
      3  , creation_date date
      4  )
      5  /
    
    Table created.
    
    SQL> create trigger t
      2  before insert on rob
      3  for each row
      4  begin
      5          :new.creation_date := sysdate;
      6  end;
      7  /
    
    Trigger created.
    
    SQL> set timing on
    SQL> insert into rob (id)
      2   select level
      3     from dual
      4  connect by level <= 10000
      5  /
    
    10000 rows created.
    
    Elapsed: 00:00:00.37
    SQL> set timing off
    SQL> select min(creation_date)
      2       , max(creation_date)
      3    from rob
      4  /
    
    MIN(CREATION_DATE)  MAX(CREATION_DATE)
    ------------------- -------------------
    07-05-2010 09:29:24 07-05-2010 09:29:24
    
    1 row selected.
    

    You can read more here: http://rwijk.blogspot.com/2008/07/sysdate.html

    Kind regards
    Rob.

  • LabVIEW allows to read an Excel file to a control and add a checkbox for each line

    As say the topic, I need to use labview to read an excel file and show it in a control, such as mclb; I should add a checkbox for each line then allow me to choose the line I want. What should I do? Thank you very much.

    guiming wrote:

    I can read an Excel file to a spreadsheet, but I have no idea how to do to add a checkbox for each line.

    Sometimes, all you need to do is Google. https://decibel.NI.com/content/docs/doc-25000

    http://www.labviewing.com/check-box-in-multicolumn-ListBox/

  • How do I either set channel name of a graph of cluster or get a 1 d waveform chart to start different time (t0) for each line of the waveform?

    I have a chart single 2D out a conditional of a loop indexing output such that over the rows of the table are not the same size. -Basically, they have different starting and ending points and sizes. -Not so concerned by the endpoints, because as soon as I get correctly starting points, everything shows fall in place.

    The challenge is that when I try to have the variable t0 (start time) for each line, the wave of construction vi form would always keep each line at the same starting point.

    I used the approach bundled with success (the cluster approach ensures that each waveform starts at different times according to the guidelines of my t0 defined for each line) but then I'm not able to get in the channel names I could make using the graphical approach (wave generation) waveform.

    In essence what I get here, I'm losing here.

    Because I don't want one of my mentors, Bob and Altenbach have fed up with me I have attached a vi this time

    Attached VI shows a combination of the two attempts (first with the waveform graph) and then with the graph of cluster

    1. with the first (graphical waveform), I get my channel names as you wish, but the alignment of the wave is not correct.

    2. with the second (graphical cluster), the alignment is good, but I can't do the names of channel in the chart, even if they are present in the cluster.

    I read some reviews that mentions that attributes can be displayed with waveform and data Dynamics (not clsuters) so I guess that's why.

    I saw another report indicating the start time for a waveform 1 d will always remain the same for the rest lines defined for the first line even if changed for the following lines in a loop.

    So I guess my question is: what is the way around questions like that?

    First of all, let me be the first to the congratulate and thank you for finally posting a code!  I'm not 100% certain I understand your question or your code, but I have an idea, perhaps, of what you want to do, so I wrote a little VI who made something simple that could be relevant.

    You mention waveforms of different lengths and beginning at different times.  You also want everyone to have a unique attribute (although I'm not sure what you want to do with the attribute).  So, I did the following:

    1. Generated an array of 100-sample random to represent one second of a waveform.
    2. Created 4 waveforms on this 100-sample basis.  The first waveform (channel 0) is just these 100 points.  The second, 1 channel, is the concatenation of string 0 with the base of 100 samples, or a waveform "double".  Channel 2 is 1 string concatenated with the base, and channel 3 is 2 string concatenated with the base.
    3. In order to trace the four channels that they rest 'on' the other, the waveform has the number of the channel added to it.  Channel 3 is 3 + (4 copies of the basis of 100 points), a waveform 400-point random centered around a shift of 3.
    4. All channels have dt value 0.01 (but I guess I could have varied, as well).
    5. To make the channels start at different times, I started channel N N seconds before channel 0 (by subtracting the index of the loop, I, T0).
    6. For each channel, I created an attribute called "Chan" equal to "Channel N" (where N = 0, 1, 2 or 3, as the case may be).

    This is the plot that results. Scale X is the absolute time value (no Date) using the 24-hour HH: mmS format.  You can see that the plots are 1, 2, 3 and 4 seconds of time, and are offset from each other by a second.  I used the trace attributes to change the name to the respective attribute.

    The code to do this is very simple - I almost don't need to show it, because I think it is completely described by the text above, but this is here:

    Now, it was not that much faster that some of your previous posts, when you refused to your postcode, "guess us" what you wanted (but not to not correctly guess), you tried to "push" us in the right direction (still refuses to post code), and no one seemed very happy?

    Bob Schor

  • In a hierarchical query, is it possible for a line having more than one immediate ancestor?

    Hello

    Question:

    In a hierarchical query, is it possible for a line having more than one immediate ancestor?


    Answer:



    Isn't it?  Surely this is Yes?


    Thank you

    Jason

    Line may have ancestors as much as you want. It goes the same for successors.

    SY.

  • How to print 1 page for each line of the numbers worksheet

    Hello... I am trying to print reports of year-end per person and number.

    Is it possible in number to print 1 page for each row of a spreadsheet of numbers?

    Or suggestions?

    Thank you.

    Hi cm,

    This looks like a work of fusion and mailing.

    The merge document would create in Pages, and the cells of merger on this document référenceriez cells in the table in the document numbers.

    See the documentation Pages (on the Help menu) for instructions on the conduct of merger and mailing.

    To do this in only numbers, you would need to put in place a 'table of declaration' on a separate sheet (in the same document as the table containing information) which would accept a customer number (or other key ID for each individual) then use it to determine the line of the main table to retrieve information about this pattern.

    A more precise answer requires a more specific desription of your table structure and the desired form of the instruction to take.

    Kind regards

    Barry

  • Adding column which gives the serial number for each line in the Bulletin Board

    I use the update version 2 Jdev 11 g.
    I'm the filling of all employees from the emp table ADF table.
    My requirement is to add a column more as the first column and header line which displays the serial number for each serial number of row.the is not available in the table emp in database .i want to generate it dynamically when the data are filled in to ADF table.i don't want not to use the method to get the SQL query rownum. I want to get custom code (in the Managed Bean) or set all of the properties in the subject entity or any other object.

    Published by: sj0609 on September 8, 2009 09:43

    Hello

    Give an id to the table (say 'currRow') varStatus property. Add a column to the table (for example with a text output), then set it to the value of the output text #{currRow.index}.

    Arun-

  • Remove the single record using the Recycle Bin for each line icon

    Hello

    Long ago, I saw in some blog ApEx showing how to remove records using "Trash" image on each line.
    I couldn't find that blog anywhere, but I managed to make an example.

    http://Apex.Oracle.com/pls/OTN/f?p=47888:5:0:no:

    Can you someone please guide me to good links on how to do the same.

    I appreciate for your time.

    Thank you
    Raj.

    Hello
    Here you are:

    http://Apex.Oracle.com/pls/Apex/f?p=19914:10:0:no:

    Best regards
    Fateh
    ------------------------------------------------------
    If you think that my answer was correct or helpful to you, then please check the response as helpful or appropriate.

  • Group repeated for each line column

    How a group column can appear in all the ranks? I have to develop a model of assets of the Group company, GL and Costcenter accounts. How can I make these group columns for each asset rather than appear once for each group?

    Thank you
    SN

    Hello

    in your case, the following should work:







    You see, the code depends on the structure of your of your xml, that's why vetsrini inquired.
    And please: publish a valid xml code in the future

    Concerning
    Rainer

  • Report Classic - Condition evaluated for each line

    APEX 4.2.2

    I see something strange in a classic report area. A report began to fail at runtime with a strange error of incorrect syntax. When I run the page in debug mode, I see the following

    Print column headers

    loop lines: line 30 (s)

    ... Run the statement: begin wwv_flow.g_boolean: = "is not null;

    end;

    ...... Result = false

    ... Run the statement: begin wwv_flow.g_boolean: = "is not null;

    end;

    ...... Result = false

    ... Run the statement: begin wwv_flow.g_boolean: = ' embedded string with a 'apostrophe' is not null;

    end;

    ...... Result = true

    It seems that the APEX engine evaluates a Boolean expression after rendering and each row in the report. And for some strange reason, it is using a piece of data from the result set of the query and is not due to bad syntax introduced by the single quotation mark in the string.

    I have never seen it before. Any idea what's going on?

    Thank you

    Hi Vikas

    Report template customized with the models of the conditional row/column?

    (Sorry for the brevity of the answer but I just get on a plane...)

  • Add the check box for each line in the classic report

    Hello

    I created the report classic with checkboxes in each row and added the On-Submit process, BUTTON CONDITIONAL, to determine the behavior of the boxes. The process of PL/SQL is suppose to delete the selected row from the database.

    I get the success message, but when I check the database, the line is still present in the database.

    PLSQL CODE:

    FOR i IN 1.. apex_application . g_f01 . County LOOP

    DELETE
    Of
    Registry
    WHERE
    reg_id
    = apex_application. g_f01 (i); END LOOP ;




    ORACLE APEX: 4.2

    Thank you

    ApexNewLearner wrote:

    I tried the above solution, but I get the error message.

    Don't see no error message (maybe someone else was modulate the application). As I found it, the problem was the property view as of the column being Simple Checkboxvalue box. This type of display should be used only by generated by the wizard tabular forms, not with a apex_item.checkbox2 column. When the display type is changed to Standard report column, the row is deleted if necessary.

  • How add us a button to check for each line in a report to oracle Apex?

    How we publish one every line ina report in oracle Apex? (with the help of select * from empdate)

    I need to add new row in the table (with the help of select * from empdate)

    I need to click on the box and I want to delete the row from the table!

    I need to click on the box and I want to change the whole table raow!

    See this blog entry for an example: adding a checkbox to your report & #8211; APEX_ITEM tutorial & #8211; APEX blog

    Thank you

    Tony Miller

    Software LuvMuffin

  • [AS] Why not work object reference for each line of text with Leopard/Snow Leopard style

    script extract, in CS5 (but have the same problem with the version of the script for CS3):

    say theDoc

    ...

    tell theStory

    ...
    the value question (object reference each text style Beach where the style police is in boldStyles)

    In Tiger, it would generate a list of ranges of text, such as "character text 64-character 110 text stream code 55110 document"thisdoc.indd"

    Under Leopard and Snow Leopard, I get an error: can not get the object reference

    I did not write the original screenplay and I can find a solution by looping through the styles in the list but this good word seems to be better, if I can make it work!

    Thoughts?

    Thank you!

    It works in CS4 on Mac OS 10.5.8 Intel:

    Tell application "Adobe InDesign CS4"

    say 1 document

    say page 1

    say the text block 1

    tell of the history of parent

    the value question to (object of each text style reference range) which police style is in 'mainstream '.

    end say

    end say

    end say

    end say

    end say

    Which returns:

    { of character 1 to 22 character text 236 of the identity document 'Untitled 1' history application "Adobe InDesign CS4", text of character 23 to 23 character 236 of the identity document history "Untitled-1" application "Adobe InDesign CS4", text of the character 48 to 48 character 236 of the identity document history "Untitled-1" application "Adobe InDesign CS4", text of 49 to 62 character character 236 of the identity document history "Untitled-1" application "Adobe InDesign CS4" "" "} , of character 63 to 64 character text 236 of the identity document 'Untitled 1' history application "Adobe InDesign CS4", from 65 to 76 character character text 236 of the identity document history "Untitled-1" application "Adobe InDesign CS4", from 77 to 77 character character text 236 of the identity document history "Untitled-1" application "Adobe InDesign CS4", from 78 to 98 character character text history 236 of the document id "Untitled-1" application «Adobe InDesign CS4»»» " , from 99 to 129 character character text 236 of the identity document 'Untitled 1' history application "Adobe InDesign CS4", text of 130 to 153 character character 236 of the identity document history "Untitled-1" application "Adobe InDesign CS4", text of character 179 to character 228 236 of the identity document history "Untitled-1" application "Adobe InDesign CS4", text of character 229 to 245 to 236 of the document id story character "Untitled-1" application "Adobe InDesign CS4" text of character 246 to character 275 236 of the document history»»» identity 'Untitled 1' application "Adobe InDesign CS4", text of 276 to 292 character character 236 of the identity document history "Untitled-1" application "Adobe InDesign CS4", text of character 293 to character 361 236 of the identity document history "Untitled-1" application "Adobe InDesign CS4"}»»

Maybe you are looking for

  • Do I need to use the software to clean my Mac pro

    MacBook Pro safety.  Is it necessary to buy a security / anti virus software?  If so, what is recommended?

  • How to uninstall firefox greasemonkey (mac)?

    Today I installed greasemonkey because my friend told me it was a good complement for firefox, but now ads appear on every page, I will and I want to remove it but there not all delete or uninstall option.If someone could help me and write how to rem

  • My Motospeak works not-how to return the original which has made?

    A week ago, I received a notification that there is an update for MotoSpeak. I have a Droid3 with the Roadster and MotoSpeak worked fine with it. The new update was an application called My Motospeak. It has been listed as a beta. I was not given any

  • the label data

    Hi, how can I tag that secure data in Excel file?

  • 0x8007371c error trying to install sp2

    I tried for months install sp2 with no luck. I tried the suggestions in the forum without success. My laptop came without a CD of Vista, because the recovery files are on a disk partition, so I can't use the remedy listed on the forum. Can someone he