How to retrieve the parent and the child in different columns when they exist in a single column.

For example, my table contains data in a column as follows.

COLUMN_DATA

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

A00 FOOD 0

A01 0 DENTAL

A02 0 PLASMA

A01A0 CLEAR

A02A0 CHANNEL

A01A1 ANTACIDS

A01A2 ANTACIDS + Napthalone

A01A3 ANTACIDS + Olive

A02A1 ACIDS

A02A2 PLASMAACIDS

Now, there is a relationship between codes. Four level hierarchy is maintained. EG - A01A1-> A01A0-> A01-> A00 0 0

I want to receive data as in the format below:

T4_CODE T4_DESC T3_CODE T3_DESC T2_CODE T2_DESC T1_CODE T1_DESC

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

ANTACIDS A01A PLAIN A01 DENTAL A01A1 A DIGESTIVE

A01A2 ANTIACIDES + Napthalone A01A PLAIN A01 DENTAL a DIGESTIVE

A01A3 ANTIACIDES + Olive A01A PLAIN A01 DENTAL a DIGESTIVE

A02A1                      ACIDS                                  A02A                        CANAL                     A02                    PLASMA                         A                ALIMENTARY

A02A2 PLASMAACIDS A02A A02 PLASMA CHANNEL HAS DIGESTIVE

So we must derive the level four of codes and their descriptions in different columns.

Any help is really appreciated.

Thanks in advance.

And I got a simpler and more efficient way to do ds.

with t as

(select text

case

When substr (text, 4, 1) = ""

then rtrim (substr (text, 1, 3), ' 0')

of another rtrim (substr (text, 1.5), ' 0')

end of the code

, substr (text, 7) descript

of lc_load

)

t2 as

(select

case length (t.code)

When 1

then 1

When 3

then 2

When 4

then 3

When 5

then 4

end lvl

, t.*

t

)

Select t2_4.code

t2_4.descript

t2_3.code

t2_3.descript

t2_2.code

t2_2.descript

t2_1.code

t2_1.descript

of t2_1 t2

Join t2 t2_2

on t2_1.code = substr (t2_2.code, 1, 1)

Join t2 t2_3

on t2_2.code = substr (t2_3.code, 1, 3)

Join t2 t2_4

on t2_3.code = substr (t2_4.code, 1, 4)

where t2_1.lvl = 1

and t2_2.lvl = 2

and t2_3.lvl = 3

and t2_4.lvl = 4

Tags: Database

Similar Questions

  • How to stop the movieclip created in flash when they are imported to seduce?

    I created a movieclip and drag it onto the main timeline(flash cs4), the movieclip have 60 fps and I put stop(); the last image. When they are imported from the swf to Captivate, the movieclip loop play. I tried the rdcmndPause = 1; but don't know where to put it. I don't really know the idea how to proceed. (already search in the forum and read adobe help, but no step by step how to do this).

    Hello

    Maybe try to animate your Flash in the main Flash timeline. I don't know if it is possible to promote a MovieClip to the main timeline, but usually people want the animation to loop and it doesn't and it is because they have not animate in a MovieClip. They did it in the main Flash timeline.

    See you soon... Rick

    Useful and practical links

    Captivate wish form/Bug report form

    Certified Adobe Captivate training

    SorcerStone blog

    Captivate eBooks

  • How to keep the chart with different colors when adding new data

    Hi, please help me.

    I want to compare my first plot the data (trace of legend) with my following data in the graph of the plot. my program didn't work it just add new field data and color for the next data has not changed.

    What's a matter of signal conditioning? Please, click on Options, and to request the removal of moderator for the jury of LabVIEW.

  • How to retrieve the network icons and the taskbar sound? They disappeared

    original title: extraction and network icons

    How to retrieve the network icons and the taskbar sound?  They disappear from the notification area of the taskbar.

    Hello

    There are different ways to fix it

    read all the information on the link below

    Try Method 1 or 3

    Method 1. :

    1. right click on the taskbar and click Properties.

    2 tab Area of Notification .

    3 check the (on) or disable (off) the options you want or do not want to display on the Taskbar Notification area

    Method of reading 3 etc. in the link below

    How to enable or disable the Notification area system icons in Vista

    http://www.Vistax64.com/tutorials/106787-notification-area-system-icons.html

  • LOBs and how to retrieve the record inserted with EMPTY_BLOb()

    Hi guys


    How to retrieve the records inserted with EMPTY_BLOb() instead of NULL value.


    Best greetings
    A.G.

    There must be a better way, but these work:

    SELECT... from tableX where length (lob_column) = 0;
    SELECT... from tableX where dbms_lob.getlength (lob_column) = 0;

    Concerning
    Jonathan Lewis
    http://jonathanlewis.WordPress.com
    http://www.jlcomp.demon.co.UK

    "All experts it is a equal and opposite expert."
    Clarke

  • How to find the child level for each table in a relational model?

    Earthlings,

    I need your help, and I know that, "Yes, we can change." Change this thread to a question answered.

    So: How to find the child level for each table in a relational model?

    I have a database of relacional (9.2), all right?
    .
         O /* This is a child who makes N references to each of the follow N parent tables (here: three), and so on. */
        /↑\ Fks
       O"O O" <-- level 2 for first table (circle)
      /↑\ Fks
    "o"o"o" <-- level 1 for middle table (circle)
       ↑ Fk
      "º"
    Tips:
    -Each circle represents a table;
    -Red no tables have foreign key
    -the picture on the front line of tree, for example, a level 3, but when 3 becomes N? How is N? That is the question.

    I started to think about the following:

    First of all, I need to know how to take the kids:
    select distinct child.table_name child
      from all_cons_columns father
      join all_cons_columns child
     using (owner, position)
      join (select child.owner,
                   child.constraint_name fk,
                   child.table_name child,
                   child.r_constraint_name pk,
                   father.table_name father
              from all_constraints father, all_constraints child
             where child.r_owner = father.owner
               and child.r_constraint_name = father.constraint_name
               and father.constraint_type in ('P', 'U')
               and child.constraint_type = 'R'
               and child.owner = 'OWNER') aux
     using (owner)
     where child.constraint_name = aux.fk
       and child.table_name = aux.child
       and father.constraint_name = aux.pk
       and father.table_name = aux.father;
    Thought...
    We will share!

    Thanks in advance,
    Philips

    Published by: BluShadow on April 1st, 2011 15:08
    formatting of code and hierarchy for readbility

    Have you looked to see if there is a cycle in the graph of dependence? Is there a table that has a foreign key to B and B has a back of A foreign key?

    SQL> create table my_emp (
      2    emp_id number primary key,
      3    emp_name varchar2(10),
      4    manager_id number
      5  );
    
    Table created.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  create table my_mgr (
      2    manager_id number primary key,
      3    employee_id number references my_emp( emp_id ),
      4    purchasing_authority number
      5* )
    SQL> /
    
    Table created.
    
    SQL> alter table my_emp
      2    add constraint fk_emp_mgr foreign key( manager_id )
      3         references my_mgr( manager_id );
    
    Table altered.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1   select level lvl,
      2          child_table_name,
      3          sys_connect_by_path( child_table_name, '/' ) path
      4     from (select parent.table_name      parent_table_name,
      5                  parent.constraint_name parent_constraint_name,
      6                  child.table_name        child_table_name,
      7                  child.constraint_name   child_constraint_name
      8             from user_constraints parent,
      9                  user_constraints child
     10            where child.constraint_type = 'R'
     11              and parent.constraint_type = 'P'
     12              and child.r_constraint_name = parent.constraint_name
     13           union all
     14           select null,
     15                  null,
     16                  table_name,
     17                  constraint_name
     18             from user_constraints
     19            where constraint_type = 'P')
     20    start with child_table_name = 'MY_EMP'
     21*  connect by prior child_table_name = parent_table_name
    SQL> /
    ERROR:
    ORA-01436: CONNECT BY loop in user data
    

    If you have a cycle, you have some problems.

    (1) it is a NOCYCLE keyword does not cause the error, but that probably requires an Oracle version which is not so far off support. I don't think it was available at the time 9.2 but I don't have anything old enough to test on

    SQL> ed
    Wrote file afiedt.buf
    
      1   select level lvl,
      2          child_table_name,
      3          sys_connect_by_path( child_table_name, '/' ) path
      4     from (select parent.table_name      parent_table_name,
      5                  parent.constraint_name parent_constraint_name,
      6                  child.table_name        child_table_name,
      7                  child.constraint_name   child_constraint_name
      8             from user_constraints parent,
      9                  user_constraints child
     10            where child.constraint_type = 'R'
     11              and parent.constraint_type = 'P'
     12              and child.r_constraint_name = parent.constraint_name
     13           union all
     14           select null,
     15                  null,
     16                  table_name,
     17                  constraint_name
     18             from user_constraints
     19            where constraint_type = 'P')
     20    start with child_table_name = 'MY_EMP'
     21*  connect by nocycle prior child_table_name = parent_table_name
    SQL> /
    
           LVL CHILD_TABLE_NAME               PATH
    ---------- ------------------------------ --------------------
             1 MY_EMP                         /MY_EMP
             2 MY_MGR                         /MY_EMP/MY_MGR
             1 MY_EMP                         /MY_EMP
             2 MY_MGR                         /MY_EMP/MY_MGR
    

    (2) If you try to write on a table and all of its constraints in a file and do it in a valid order, the entire solution is probably wrong. It is impossible, for example, to generate the DDL for MY_EMP and MY_DEPT such as all instructions for a table come first, and all the instructions for the other are generated second. So even if NOCYCLE to avoid the error, you would end up with an invalid DDL script. If that's the problem, I would rethink the approach.

    -Generate the DDL for all tables without constraint
    -Can generate the DDL for all primary key constraints
    -Can generate the DDL for all unique key constraints
    -Can generate the DDL for all foreign key constraints

    This is not solidarity all the DOF for a given in the file object. But the SQL will be radically simpler writing - there will be no need to even look at the dependency graph.

    Justin

  • After the system recovery running following a power outage, my user profile is lost. Unfortunately, he is also the administrator account. How to retrieve the profile or create a new?

    After the system recovery running following a power outage, my user profile is lost.  Unfortunately, he is also the administrator account.  How to retrieve the profile or create a new?

    ·                        Restore point:

    Try typing F8 at startup and in the list of Boot selections, select Mode safe using ARROW top to go there > and then press ENTER.

    Try a restore of the system once, to choose a Restore Point prior to your problem...

    Click Start > programs > Accessories > system tools > system restore > choose another time > next > etc.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    If the above does not work:

    ·                        http://www.Vistax64.com/tutorials/130095-user-profile-service-failed-logon-user-profile-cannot-loaded.html

    See if the information in the above tutorial will help you.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    http://windowshelp.Microsoft.com/Windows/en-AU/help/769495bf-035C-4764-A538-c9b05c22001e1033.mspx

    Difficulty of a corrupted user profile

    After creating the profile, you can copy the files from the existing profile. You must have at least three user accounts on the computer to perform these operations, including the new account that you created.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    http://support.Microsoft.com/kb/947242

    A temporary profile is loaded after you connect to a Windows Vista-based system

    See you soon.

    Mick Murphy - Microsoft partner

  • Lost admin password, how to retrieve the current password to change it?

    I forgot my Admin password, I connect on my laptop using the scanner print finger all the time and when I try to change the password for Admin it ask the password which I do not remember. How to retrieve the current password and change it in Windows 7 Home premium?

    It's a laptop Acer 5738 G

    You can change your current password as follows:

    1. click on start.
    2. type the three letters cmd in the search box.
    3. press on Ctrl + Shift + Enter
    4. click on "run as Administrator".
    5. type the following command and press ENTER after each:
    NET user "user %%nom" 123456

    Now the password is 123456. While dealing with accounts and passwords: having a single admin account on a PC is about the same as having a unique key for your car. What happens if you lose? He lost? Break it? A robust Windows Setup requires at least the following:

    • Two admin accounts fully tested, with their passwords to record on paper.
    • A password key file. Click Start / Help, then search for help on "password". Follow the instructions to create a key on your USB flash drive file so that you'll never find yourself in this uncomfortable situation.
  • How to retrieve the values of character without using single quotes

    Hi all

    How to retrieve the values of character without the use of single quotes. Its Possible in Oracle SQL

    Please answer me...

    For example

    Is actual query-> Select * from employees where name like in("SCOTT", "JAMES", "ALBERT",...);

    I want to--> Select * from employees where name like(SCOTT, JAMES, ALBERT...); -without the use of single quotes.

    Why I need this application, I need to retrieve the records more than 200 employees in a select statement by using name in where clause.

    shagarmahabubjan wrote:

    Hi all

    How to retrieve the values of character without the use of single quotes. Its Possible in Oracle SQL

    Please answer me...

    For example

    Actual query is---> Select * from employees where name like in("SCOTT", "JAMES", "ALBERT",...);

    I want to---> Select * from employees where name like(SCOTT, JAMES, ALBERT...); -without the use of single quotes.

    Why I need this application, I need to retrieve the records more than 200 employees in a select statement by using name in where clause.

    In short... you can't.  The channels are channels, and SQL and PL languages dictate that the string literals are provided within single quotes.

    I don't see how trying to retrieve more than 200 records of employees in the select statement means that you must get rid of the quotes.

    Be clear in what you ask: Re: 2. How can I ask a question on the forums?

    and take note of the FAQ link davidp provided the solution "variable IN the list.

  • How to retrieve the selected values of the selectOrderShuttle using ADF 11 g

    Hello world

    Did anyone has idea how to retrieve the selected items by using the shuttle and the order of the elements by using the 'SelectOrderShuttle '?

    Thank you

    valuechangeevent of the shuttle would fire when you shuttle points back.

        public void selectOrderShuttle1_valueChangeListener(ValueChangeEvent valueChangeEvent) {
    
            ArrayList list = new ArrayList(Arrays.asList(valueChangeEvent.getNewValue()));
    
            if (list != null){
                for (int i=0; i
    
  • How to retrieve the values of a number of column by column in pl sql

    I wanted to know how can I retrieve the values of a column just in number and not the name of the column.

    user10989720 wrote:
    I need exactly this kind of thing.

    I am retrieving the name of the column from all_tab_columns and under this column name can I retrieve values using any kind of query sub.

    Select column_name
    from all_tab_columns
    where table_name = 'QUOTE_HEADERS_EXT' and
    column_id = 58

    You're still not understanding. You need to do if you want to get the values of the table dynamically.

    Either like this:

    SQL> create or replace type t_colval is table of varchar2(4000);
      2  /
    
    Type created.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  CREATE OR REPLACE FUNCTION get_column(p_sql IN VARCHAR2, p_column_no NUMBER) RETURN t_colval PIPELINED IS
      2    v_finaltxt  VARCHAR2(4000);
      3    v_v_val     VARCHAR2(4000);
      4    v_n_val     NUMBER;
      5    v_d_val     DATE;
      6    v_ret       NUMBER;
      7    c           NUMBER;
      8    d           NUMBER;
      9    col_cnt     INTEGER;
     10    f           BOOLEAN;
     11    rec_tab     DBMS_SQL.DESC_TAB;
     12    col_num     NUMBER;
     13  BEGIN
     14    c := DBMS_SQL.OPEN_CURSOR;
     15    DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
     16    d := DBMS_SQL.EXECUTE(c);
     17    DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
     18    FOR j in 1..col_cnt
     19    LOOP
     20      CASE rec_tab(j).col_type
     21        WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
     22        WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
     23        WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
     24      ELSE
     25        DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
     26      END CASE;
     27    END LOOP;
     28    LOOP
     29      v_ret := DBMS_SQL.FETCH_ROWS(c);
     30      EXIT WHEN v_ret = 0;
     31      v_finaltxt := NULL;
     32      CASE rec_tab(p_column_no).col_type
     33        WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,p_column_no,v_v_val);
     34        WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,p_column_no,v_n_val);
     35                    v_v_val := to_char(v_n_val);
     36        WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,p_column_no,v_d_val);
     37                    v_v_val := to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS');
     38      ELSE
     39        DBMS_SQL.COLUMN_VALUE(c,p_column_no,v_v_val);
     40      END CASE;
     41      PIPE ROW (v_v_val);
     42    END LOOP;
     43    DBMS_SQL.CLOSE_CURSOR(c);
     44* END;
    SQL> /
    
    Function created.
    
    SQL> select * from table(get_column('select * from emp',1));
    
    COLUMN_VALUE
    ---------------------------------------------------------------------------------------------------------------
    7369
    7499
    7521
    7566
    7654
    7698
    7782
    7788
    7839
    7844
    7876
    7900
    7902
    7934
    
    14 rows selected.
    
    SQL> select * from table(get_column('select * from emp',2));
    
    COLUMN_VALUE
    ---------------------------------------------------------------------------------------------------------------
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    
    14 rows selected.
    
    SQL>
    

    Or like this:

    SQL> create or replace type t_colval is table of varchar2(4000);
      2  /
    
    Type created.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  CREATE OR REPLACE FUNCTION get_column(p_table IN VARCHAR2, p_column_no NUMBER) RETURN t_colval PIPELINED IS
      2    v_column_name VARCHAR2(30);
      3    v_rc          SYS_REFCURSOR;
      4    v_val         VARCHAR2(4000);
      5  BEGIN
      6    SELECT column_name
      7    INTO   v_column_name
      8    FROM   user_tab_columns
      9    WHERE  column_id = p_column_no
     10    AND    table_name = UPPER(p_table);
     11    OPEN v_rc FOR ('SELECT '||v_column_name||' FROM '||p_table);
     12    LOOP
     13      FETCH v_rc INTO v_val;
     14      EXIT WHEN v_rc%NOTFOUND;
     15      PIPE ROW(v_val);
     16    END LOOP;
     17    CLOSE v_rc;
     18* END;
    SQL> /
    
    Function created.
    
    SQL> select * from table(get_column('EMP',2));
    
    COLUMN_VALUE
    ----------------------------------------------------------------------------------------------------------------
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    
    14 rows selected.
    
    SQL>
    
  • I sent an email to someone by mistake, how to retrieve the email until the receiver reads?

    I sent an email to someone by mistake, how to retrieve the email until the receiver reads?

    I sent an email to someone by mistake, how to retrieve the email until the receiver reads?

    You can not. It's like putting a letter in a physical mailbox. There is no way to recover it.

  • How to stop the red symbols to appear when I use the question mark, the apostrophe and slash keys. This only happens in my e-mail program.

    How to stop the red symbol to appear when I use the key question mark in my e-mail program.

    HI Julie Delany.

    1. for how long are you facing this problem?

    2. is there any changes made prior to this issue?

    3. may I know what mail client do you use?

    Disable the function key (lock) and then check

  • How we split the screen for different horizontal and vertical divisions

    Hello

    How we split the screen for different horizontal and vertical divisions. I can't use panelSplitter because I need fixed screen and not the division which is movable/sliding. I tried inlineframe, but which fails because you cannot use forms, other trees components... :(

    so I would like to know how to do division without panelSplitter.

    Thanks in advance,
    Jyothi

    Hi Jyothi,

    If you set the panelSplitter attribute disabled to true, the delimiter becomes permanent/mobile no.

    
    

    Kind regards
    Amélie Chan

  • Retrieve the metadata for a column in a view

    Hello

    I can see how it is possible to retrieve the details of all the columns of a table by querying the views sys.tables and sys.columns . Is there a similar way to retrieve the details of all columns in a view?

    Thank you
    Ben

    I am not afraid. Currently, TimesTen code to display information in an internal proprietary format in the system catalogs.

    I'm sorry.

    Chris

Maybe you are looking for