Connect By clause

I have a custom folder which contains a "connect by" sql like following example. Does anyone know how I could made a dynamic parameter pass in start with clause??
ex.
select id, parent_id
from table
start with id = ??
connect by prior id = parent_id

select id, parent_id
from table
start with id = &parameter_id
connect by prior id = parent_id

Similar Messages

  • Connect By Clause -  Major Bug in Oracle 9.0.1

    Currently I am working with Oracle 8.1.6 database,
    now we are migrating to Oracle 9.0.1.
    We are often using "Connect By" clause in our queries since our database structure is hierarchical.
    I am facing one problem with "Connect By" clause in
    Oracle 9.0.1, actually which is working properly with Oracle 8.1.6.
    I am giving the Problem.
    I have created a Table say Object_Master,
    Then I insert 3 rows in that table,
    and then I commit and try to execute one query,
    Same thing is working properly in Oracle 8.1.6 but same query is not working in Oracle 9.0.1.
    Following is the script.
    Create table Object_Master
    ObjectId Number(5),
    ObjectName Varchar2(255),
    ParentId Number(5),
    DeleteStatus Varchar2(1),
    IsSecuritySet Varchar2(1))
    Insert Into Object_Master Values (1,'john',0,'N','Y')
    Insert Into Object_Master Values (2,'ADMIN',1,'N','Y')
    Insert Into Object_Master Values (3,'ADMIN',1,'N','Y')
    Commit
    Select * from
    Object_Master
    Start with ObjectId = 1
    Connect By parentid = Prior ObjectId
    And DeleteStatus = 'N' And ( IsSecuritySet = 'N' Or ObjectName = 'ADMIN' )
    This script is working perfectly with Oracle 8.1.6 but when I try to run this sc[i]Long postings are being truncated to ~1 kB at this time.

    Hey Mitesh,
    What's going on? So many posting for the same question, and that is also not comlete. Try to post rest of your question.
    Dharmesh Patel

  • Without using order by and connect by clause

    hi all,
    can i write a tree query without using start with clause and connect by clause
    and
    can i order the employee names in a select query without using order by clause
    can those things are possible in select statement...

    dipuna wrote:
    hi all,
    can i write a tree query without using start with clause and connect by clause
    and
    can i order the employee names in a select query without using order by clause
    can those things are possible in select statement...A very odd question.
    Those clauses are the means to do what you are asking. Why would you be looking for some other method?

  • Database error says connect by clause for Oracle10g

    Hi All,
    I am trying to select details from anodestable where error says SQLException connect by clause is required in this query block.
    Please respond if you know how to resolve this error.
    Thanks in advance.
    Bye

    Katheresh wrote:
    Hi All,
    I am trying to select details from anodestable where error says SQLException connect by clause is required in this query block.
    Please respond if you know how to resolve this error.
    Thanks in advance.
    ByeCould you post the SQL code and the error you got?

  • Hierarchical Query - Connect By clause

    Hi
    I've written a query using the Connect By clause to generate the table data in Tree structure with the appropriate levels.
    But Data might not correct such that it may have data which loops around. Like Table1 is parent of Table 2 and Table 2 is parent of Table 3 and Table 3 is again Parent of Table 1. If such incorrect Data exists then I'm getting Oracle Error "ORA-01436: CONNECT BY loop in user data" which is correct.
    What I need is, whenever this error message is raised I need to give my own error message instead of this Oracle error in SQL statement. Please note, I'm not using any PLSQL block, I just have one SQL statement. Appreciate any help on this subject. Thanks.

    Hi,
    Outside of PL/SQL, I don't know of any way to substitute your own error messages for the ones Oracle provides.
    In Oracle 10 (and up), you can write a query using the CONNECT_BY_ISCYCLE pseudo-column. Using CONNECT BY NOCYCLE, the query will never actually raise the ORA-01436 error, but you can get it to display your message in cases where it would have, had you not been using CONNECT BY NOCYCLE.
    Here's how to do it:
    Put your real query, plus CONNECT_BY_ISCYCLE, in the WITH-clause.
    Get the MAX (CONNECT_BY_ISCYCLE) from that sub-query. Let's call this max_cbi.
    Do a UNION ALL of two prongs:
    (1) SELECTs everything (except, pehaps, CONNECT_BY_ISCYCLE) from the sub-query, WHERE max_cbi = 0
    (2) SELECTs your "error message" from dual, WHERE max_cbi = 1.
    Edited by: Frank Kulash on Nov 26, 2008 2:09 PM

  • Does oracle6i support connect by clause

    Want to just a list of all children to a parent ( Multi-Level tree) for the data stored in a table . How is it possible in oracle 6i ? can we use connect by clause in oracle 6i ?

    OK..iS THERE ANY OTHER WAY OUT TO GET THE ALL THE
    CHILD VLAUES FOR A PARTICULAR PARENTsomething like
    10g
    SQL> select connect_by_root ename, ename
      2  from emp
      3  connect by prior empno=mgr
      4  order by 1,2;
    CONNECT_BY ENAME
    ADAMS      ADAMS
    ALLEN      ALLEN
    BLAKE      ALLEN
    BLAKE      BLAKE
    BLAKE      JAMES
    BLAKE      MARTIN
    BLAKE      TURNER
    BLAKE      WARD
    CLARK      CLARK
    CLARK      MILLER
    FORD       FORD
    FORD       SMITH
    JAMES      JAMES
    JONES      ADAMS
    JONES      FORD
    JONES      JONES
    JONES      SCOTT
    JONES      SMITH
    KING       ADAMS
    KING       ALLEN
    KING       BLAKE
    KING       CLARK
    KING       FORD
    KING       JAMES
    KING       JONES
    KING       KING
    KING       MARTIN
    KING       MILLER
    KING       SCOTT
    KING       SMITH
    KING       TURNER
    KING       WARD
    MARTIN     MARTIN
    MILLER     MILLER
    SCOTT      ADAMS
    SCOTT      SCOTT
    SMITH      SMITH
    TURNER     TURNER
    WARD       WARDOracle7
    SQL> select 'BLAKE', ename
      2  from emp
      3  connect by prior empno=mgr
      4  start with ename='BLAKE'
      5  order by 1,2;
    'BLAK ENAME
    BLAKE ALLEN
    BLAKE BLAKE
    BLAKE JAMES
    BLAKE MARTIN
    BLAKE TURNER
    BLAKE WARD

  • Extending connect by clause in tree component

    Hi guys,
    I am afraid I know the answer to this one but I'll ask anyway.
    The build-in tree component only lets you enter the basic sql-statement. It "handles" the connect by clause. Now that is all fine and dandy, but some of our connect by clauses are a little bit more complex. So I would like to add to the connect by clause and the start with clause.
    Alternatively, allow us to write the complete sql-statement
    Also there is no way now to utilise the 10g features.
    I guess an enhancement request for Version 2 please?

    Is there any equivalent command in SQL Server's T/SQL for the command :-
    select parent, offspring from table_family start by offspring='child1' connect by parent=PRIOR offspring I had this problem some time ago. I don`t found an eqivalent on MS-SQL-server 7.0. So I wrote a T-SQL procedure wich calls itself recusively. ( I don`t have the souce-code any more ).
    I don4t know if there is an equivalent on MS-SQL-server 2000.

  • Connect by clause - Major bug with Oracle 9.0.1

    Currently I am working with Oracle 8.1.6 database,
    now we are migrating to Oracle 9.0.1.
    We are often using "Connect By" clause in our queries since our database structure is hierarchical.
    I am facing one problem with "Connect By" clause in
    Oracle 9.0.1, actually which is working properly with Oracle 8.1.6.
    I am giving the Problem.
    I have created a Table say Object_Master,
    Then I insert 3 rows in that table,
    and then I commit and try to execute one query,
    Same thing is working properly in Oracle 8.1.6 but same query is not working in Oracle 9.0.1.
    Following is the script.
    Create table Object_Master
    ObjectId Number(5),
    ObjectName Varchar2(255),
    ParentId Number(5),
    DeleteStatus Varchar2(1),
    IsSecuritySet Varchar2(1))
    Insert Into Object_Master Values (1,'john',0,'N','Y')
    Insert Into Object_Master Values (2,'ADMIN',1,'N','Y')
    Insert Into Object_Master Values (3,'ADMIN',1,'N','Y')
    Commit
    Select * from
    Object_Master
    Start with ObjectId = 1
    Connect By parentid = Prior ObjectId
    And DeleteStatus = 'N' And ( IsSecuritySet = 'N' Or ObjectName = 'ADMIN' )
    This script is working perfectly with Oracle 8.1.6 but when I try to run this sc[i]Long postings are being truncated to ~1 kB at this time.

    Hey Mitesh,
    What's going on? So many posting for the same question, and that is also not comlete. Try to post rest of your question.
    Dharmesh Patel

  • Getting strange error with connect by clause

    Hi Everyone,
    I have a 2 test oracle databases and each of them contain a table called department (dept_no,dept_name, main_dept_no) where each department entry is connected to main department by dept_no in the MAIN_DEPT_NO column.
    The strange problem is when I execute the query on the 1 ^st^ database I get D.DEPT_NO is not available column (D.* all columns from department table) but it is there and what is more strange this query works fine on 2 ^nd^ database.
    Is there any settings I have to do in the database so that it can work with connect by clause ?
    SELECT SUBSTR(LPAD(' ', 4*(LEVEL))  || '· ' ||DEPT_NAME,1,50)  DEPT_NAME_HY, D.*
    FROM PERSONEL.DEPARTMENT D
    START WITH MAIN_DEPT_NO IS NULL
    CONNECT BY PRIOR DEPT_NO=MAIN_DEPT_NOThank you.

    SSU wrote:
    Hi Everyone,
    I have a 2 test oracle databases and each of them contain a table called department (dept_no,dept_name, main_dept_no) where each department entry is connected to main department by dept_no in the MAIN_DEPT_NO column. Did you mean two SCHEMAs or tow databases?
    Please post DB version.
    The exact error message you are getting.
    output of the below from the DB rom where you are getting the error
    DESC PERSONEL.DEPARTMENT

  • Recursive joins / how to define query using connect by clause

    Hi,
    I have a table A have 1-1 reltionship with table Employee
    Structure of table is as follows
    Table A
    id name employee_id
    100 aa 1
    200 bb 2
    300 cc 3
    400 dd 4
    500 ee 5
    Table Employee
    id parent_id
    1 null
    2 1
    3 2
    4 3
    5 1
    6 1
    I want to get all records from A table whose employee_id is equal to 2 or (recursive)decendants/child of employee with id 2 (i.e. employee with id 2,3,4 )
    i.e I want recursively join where in I get records from table A as
    id name employee_id
    200 bb 2
    300 cc 3 (because it is child of employee with id 2)
    400 dd 4 (becaue it is child of employee with id 3 which is child of 2)
    I know we can use In clause , but it will be performance wise not good.
    Can we do it in Toplink without using IN clause?
    Oracle has connect by clause, but other database might not have this caluse. So how can write a toplink query which can run on any database.
    Any help is highly appreciated.
    Thanks a lot.

    You can use TopLink's Hierarchical Query support but this only works with Oracle DB as it relies on the database to perform the query.
    --Shaun                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Tricky question on Connect By Clause Urgent!!!!!

    Hi All,
    Can anyone tell me is there any way to use connect by prior clause with group by statement?.Or is there any alternative to connect by clause.?
    I have a stored function which is having select with connect by clause.
    I use that function in the select query for my reports.But now I want connect by clause to run against group by query.
    I have a stored function which I use for most of the reports.I want to change connect by clause on the view based on group by clause which gives me an error.And also I cannot use Insert statements in a stored function
    which I use in select statements.Is there any alternate way to do this???
    Thank u all...
    Satish

    For given parent_task_idI would add:
    SELECT task_id, wbs_level, parent_task_id
    FROM pa_tasks
    WHERE task_id != :given_task_id
    START WITH task_id = :given_task_id
    CONNECT BY PRIOR task_id = parent_task_id;
    It gives to you all chilren and grand-grand-...-grandchildren without parent:
    SQL> select ename, empno, mgr from emp;
    ENAME           EMPNO        MGR
    SMITH            7369       7902
    ALLEN            7499       7698
    WARD             7521       7698
    JONES            7566       7839
    MARTIN           7654       7698
    BLAKE            7698       7839
    CLARK            7782       7839
    SCOTT            7788       7566
    KING             7839
    TURNER           7844       7698
    ADAMS            7876       7788
    JAMES            7900       7698
    FORD             7902       7566
    MILLER           7934       7782
    14 rows selected.
    SQL> select ename from emp start with mgr is null
      2  connect by prior empno = mgr;
    ENAME
    KING
    JONES
    SCOTT
    ADAMS
    FORD
    SMITH
    BLAKE
    ALLEN
    WARD
    MARTIN
    TURNER
    JAMES
    CLARK
    MILLER
    14 rows selected.
    SQL>/* Without JONES but childer of JONES*/
    SQL> select ename from emp where empno != 7566
      2  start with empno = 7566
      3  connect by prior empno = mgr;
    ENAME
    SCOTT
    ADAMS
    FORD
    SMITHRgds.

  • Splitting of comma delimited string CONNECT BY Clause

    Hi ,
    I have got a problem in splitting a comma separated strings into rows .
    I am explaining the use case below :
    i have a table x_imp
    --> create table x_imp (id number, int_status varchar2(100),c_ref varchar2(30), s_ref varchar2(30));
    I inserted values into the table :
    insert into x_imp (id, int_status,c_ref,s_ref) values (1,'a1,a2,a3,a4','A','AS');
    insert into x_imp (id, int_status,c_ref,s_ref) values (1,'b1,b2,b3,b4','B', 'BS');
    insert into x_imp (id, int_status,c_ref,s_ref) values (1,'c1,c2,c3,c4', 'C', null);
    insert into x_imp (id, int_status, cust_ref, site_ref) values (1,NULL, 'D', NULL);
    I need to split the comma separated int_status into individual rows . That means my expected result is :
    . What I need or looking for as expected result:
    1, A, AS, a1
    1, A, AS, a2
    1, A, AS, a3
    1, A, AS, a4
    1, B, BS, b1
    1, B, BS, b2
    1, B, BS, b3
    1, B, BS, b4
    1, C, null, c1
    1, C, null, c2
    1, C, null, c3
    1, C, null, c4
    I currently have a solution using Regex . But this solution uses UNIQUE keyword .
    The solution i have currently :
    select UNIQUE c_ref,s_ref, regexp_substr(int_status,'[^,]+', 1, level) error_code
    from x_imp
    connect by regexp_substr(int_status, '[^,]+', 1, level) is not null;
    I need a better solution . Any pointers ?
    Thanks,
    Bibin

    One way of doing using MODEL clause:
    select c_ref, s_ref, res err_code
      FROM x_imp
    model
    partition by ( id, c_ref, s_ref)
    dimension by ( 1 rn)
    measures( int_status, cast(null as varchar2(100)) res,
              nvl(length(regexp_replace(int_status, '[^,]')),0)+1 nb )
    (res[for rn from 1 to nb[1] increment 1]=regexp_substr(int_status[1], '[^,]+', 1, cv(rn)))
    order by c_ref, s_ref;
    C_REF                          S_REF                          ERR_CODE                                                                                            
    A                              AS                             a3                                                                                                  
    A                              AS                             a4                                                                                                  
    A                              AS                             a1                                                                                                  
    A                              AS                             a2                                                                                                  
    B                              BS                             b2                                                                                                  
    B                              BS                             b1                                                                                                  
    B                              BS                             b3                                                                                                  
    B                              BS                             b4                                                                                                  
    C                                                             c4                                                                                                  
    C                                                             c3                                                                                                  
    C                                                             c1                                                                                                  
    C                                                             c2                                                                                                  
    D                                                                                                                                                                 
    13 rows selected

  • Can i restrict the number of rows in Connect by clause

    Hi,
    I have atable with data with two columns as
    MAIN SUB
    9 10
    9 11
    11 13
    12 13
    The query which i am using
    SELECT Main,Sub
    FROM My_Tab
    START WITH Main = 9
    CONNECT BY PRIOR Sub= Main
    gives
    9 10 also in the result
    My question is can i restirct the output by specifying the the child eg in case 13
    so that i dont get a row in the output with 9 10 in it.
    Thanks

    Nikhil Juneja wrote:
    My question is can i restirct the output by specifying the the child eg in case 13
    so that i dont get a row in the output with 9 10 in it.
    Can you explain this please...
    Do you mean..
    if you give like child is 13 in your query, then it should give only nodes which has 13 as their childs??
    with tab as
      select 9 MAIN,10 SUB from dual union all
      select 9 MAIN,11 SUB from dual union all
      select 11 MAIN,13 SUB from dual union all
      select 12 MAIN,13 SUB from dual
    SELECT Main,Sub
    FROM tab
    START WITH sub=13
    CONNECT BY  Sub=PRIOR Main is this??
    Ravi Kumar

  • SQL query using connect by clause

    Hi,
    I have table:
    SQL> col id for 999
    SQL> col code for a30
    SQL> select id,code from t1;
      ID CODE
    704 ,2,3,7,8,
    707 ,15,12,17,18,
    742 ,23,25,27,28,
       5 ,53,65,67,58,
    4 rows selected.---
    When I run query:
    select id,
           substr(code,instr(code,chr(44),1,level)+1,instr(code,chr(44),1,level+1)-instr(code,chr(44),1,level)-1) code
          from(
            select  id,
                    code,
                    length(code) - length(replace(code,',',''))-1 len
            from t1
            where id=5)
    connect by level <= len;
      ID CODE
       5 53
       5 65
       5 67
       5 58
    4 rows selected.How to modify my query to get this output:
    ID CODE
    5 53
    5 65
    5 67
    5 58
    704 2
    704 3
    704 7
    704 8
    707 15
    707 12
    707 17
    707 18
    742 23
    742 25
    742 27
    742 28What is the best way to get this output?
    My db:
    SQL> select * from v$version;
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
    PL/SQL Release 9.2.0.6.0 - Production
    CORE    9.2.0.6.0       Production
    TNS for Solaris: Version 9.2.0.6.0 - Production
    NLSRTL Version 9.2.0.6.0 - Production
    5 rows selected.Thanks for answers!
    Regards,
    Marko

    Hi,
    Generate a separate "counter table" that has the numbers 1, 2, 3, ... , x, where x is the greatest number you'll ever need.
    Join to this table, using a join condition that gets the exact numbers you need for each row.
    Use the number from the counter table where you are currently using LEVEL.
    That is:
    WITH     cntr      AS
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL <= ( SELECT  MAX ( LENGTH (code)
                                             - LENGTH (REPLACE (code, ','))
                           FROM        t1
                         ) - 1
    select id,
           substr(code,instr(code,chr(44),1,n)+1,instr(code,chr(44),1,n+1)-instr(code,chr(44),1,n)-1) code
    FROM   t1
    JOIN   cntr     ON     cntr.n <= LENGTH (code) - LENGTH (REPLACE (code, ','))
    ;If you're using Oracle 10 (or higher) regular expressions would simplify this a lot.

  • Equivalent of "connect by " clause in SQL Server's T/SQL to get family tree branches

    Is there any equivalent command in SQL Server's T/SQL for the command :-
    select parent, offspring from table_family start by offspring='child1' connect by parent=PRIOR offspring

    Is there any equivalent command in SQL Server's T/SQL for the command :-
    select parent, offspring from table_family start by offspring='child1' connect by parent=PRIOR offspring I had this problem some time ago. I don`t found an eqivalent on MS-SQL-server 7.0. So I wrote a T-SQL procedure wich calls itself recusively. ( I don`t have the souce-code any more ).
    I don4t know if there is an equivalent on MS-SQL-server 2000.

Maybe you are looking for

  • Error Message when trying to sign into account

    So I just got some itunes giftcards for xmas and when I go onto the itunes store and try to log into my account and message comes up that has a red "x" and it says "We could not complete your itunes store request. An unknown error has occured(-9812).

  • JVM vs JRE vs Java Plug-In and Yahoo Chat

    Hi I am a little confused as to what is required in the browser to run an applet. Do I require JVM installed in my browser? Do I require Java Plug-In installed in my browser? Do I require JVM installed in my browser? What is the difference between th

  • How to validate two items on a form that arent necessarily required

    I have a NON REQUIRED text field in which a user will enter in a value. I have a Display as Text field that will populate the result based on what is entered in the text field. I am wanting to validate the information that is entered in the text box.

  • Message M8444 in MIRO

    Good morning Requesting their support in the MIRO transaction to perform the operation of the bill reducing the error by sending the M8444, this in an environment which made the updating of various support packages (13 to 22 in the case of SAP R / 3

  • Interface determination issue.

    Hi Experts, We are using Idoc(Matmas) to file scenario wherein we are facing the below issue SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">   <SAP:Category>XIServer