Advanced:   How to traverse a tree representation in PL/SQL (procedure)?

I am looking to write a method that will create a collection of records, each of which represents a node in a tree.
TYPE t_all_folders IS TABLE OF get_all_folders%ROWTYPE INDEX BY PLS_INTEGER;
v_all_folders t_all_folders;
so first need help in figuring out what the cursor 'get_all_folders' would look like
I have a folder structure represented in a database that is used basically to show visually
(with a front end app) a folder structure (much like a folder structure in a file system).
So each row has an entry in the 'folders' table like do:
table folder:
     column           column
     folder_id          name
     1                    folder1               <= say this is a root folder
     2                    folder2               <= say this is a root folder
     3                    folder3               <= say this is a root folder
     4                    folder1a          <= all below are child folders..
     5                    folder1b
     6                    folder1c
     7                    folder1aa
     8                    folder1ab
     There is nothing in this table that indicates a hiearchy.
The hiearchy is represented by another single table with two columns
(I cannot change this, it is what it is)
There is no left node or right node (not like a tree), just imagine sub folders.
table: parent_child
     column          column
     parent_id     child_id
such that visually when the tables are queried and the UI uses a folder icon to
represent each row:
it would look like this:
     folder1                              1
          - folder1a                         2
               -folder1aa                    3
               - folder1ab                    4
          - folder1b                         5
               - folder1ba                    6
               - folder1bb                    7
          - folder1c                         8
     folder2                              9
     folder3                              10
I am attempting to create a query that will add to a collection folder records in the
order above (1..10)
In other words traverse the tree depth first going from:
          folder1 -> folder1a -> folder1aa -> folder1ab ->(back out to next level) folder1b -> folder1ba -> folder1bb -> folder1c
          then add folder2 (and traverse down that hiearch if needed)
          and then add folder3 to the colleciton and traverse down that hiearchy if there is one
          and continue adn so on.
          The requirement is to have them added to the collection in that order and when I iterate through the collection,
          they would of course need to be pulled out in that order (so use vararray with a counter to iterate through
          after the collection has been created.
After the collection has been created, I have to iterate in that specific order to create records in another table where there is a column that requires an integer value that is the 1... order they come out of the collection
and then have to iterate again and do something else in that order (and then other things - all the while needing in that order).
Edited by: user12200443 on Nov 19, 2012 11:49 AM

awesome, thanks for the help.
put this in 'schema.sql' and run to create a reference schema and data for the example
drop sequence seq_folders;
CREATE SEQUENCE seq_folders
INCREMENT BY 1
MINVALUE 1
START WITH 1
CACHE 1000;
drop table folders;
create table folders (
     folder_id number not null,
     name varchar2(20) not null
drop table parent_child;
create table parent_child (
     parent_id number not null,
     child_id number not null);
-- creation order (in order to have parent)
-- folder1
-- folder2
-- folder3
-- folder1a
-- folder1b
-- folder1c
-- folder1aa
-- folder1ab
-- folder1ac
-- folder1aaa
-- folder1aba
-- folder1aab
-- folder1abb
-- folder1aac
-- folder1abc
-- Visual hiearchy
-- folder1                              1
--      folder1a                         2
--           folder1aa               3
--                folder1aaa          4
--                folder1aab          5
--                folder1aac          6
--           folder1ab               7
--                folder1aba          8
--                folder1abb          9
--           folder1ac               10
--      folder1b                         11
--      folder1c                         12
-- folder2                              13
-- folder3                              14
--- insert folders
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder1');
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder2');
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder3');
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder1a');
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder1b');
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder1c');
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder1aa');
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder1ab');
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder1ac');
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder1aaa');
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder1aba');
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder1aab');
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder1abb');
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder1aac');
insert into folders(folder_id, name) values(seq_folders.nextval, 'folder1abc');
commit;
-- setup hiearchy
insert into parent_child(parent_id, child_id) values (0, (select folder_id from folders where name = 'folder1'));
insert into parent_child(parent_id, child_id) values (0, (select folder_id from folders where name = 'folder2'));
insert into parent_child(parent_id, child_id) values (0, (select folder_id from folders where name = 'folder3'));
-- 1a,1b,1c
insert into parent_child(parent_id, child_id) values ((select folder_id from folders where name ='folder1'), (select folder_id from folders where name = 'folder1a'));
insert into parent_child(parent_id, child_id) values ((select folder_id from folders where name ='folder1'), (select folder_id from folders where name = 'folder1b'));
insert into parent_child(parent_id, child_id) values ((select folder_id from folders where name ='folder1'), (select folder_id from folders where name = 'folder1c'));
-- aa,ab,ac
insert into parent_child(parent_id, child_id) values ((select folder_id from folders where name ='folder1a'), (select folder_id from folders where name = 'folder1aa'));
insert into parent_child(parent_id, child_id) values ((select folder_id from folders where name ='folder1a'), (select folder_id from folders where name = 'folder1ab'));
insert into parent_child(parent_id, child_id) values ((select folder_id from folders where name ='folder1a'), (select folder_id from folders where name = 'folder1ac'));
-- aaa,aba,aab
insert into parent_child(parent_id, child_id) values ((select folder_id from folders where name ='folder1aa'), (select folder_id from folders where name = 'folder1aaa'));
insert into parent_child(parent_id, child_id) values ((select folder_id from folders where name ='folder1aa'), (select folder_id from folders where name = 'folder1aab'));
insert into parent_child(parent_id, child_id) values ((select folder_id from folders where name ='folder1aa'), (select folder_id from folders where name = 'folder1aac'));
-- aba,abb,abc
insert into parent_child(parent_id, child_id) values ((select folder_id from folders where name ='folder1ab'), (select folder_id from folders where name = 'folder1aba'));
insert into parent_child(parent_id, child_id) values ((select folder_id from folders where name ='folder1ab'), (select folder_id from folders where name = 'folder1abb'));
insert into parent_child(parent_id, child_id) values ((select folder_id from folders where name ='folder1ab'), (select folder_id from folders where name = 'folder1abc'));
commit;
then run this to get the error message
WITH joined_data     AS
     SELECT     f.folder_id,     f.name,     pc.parent_id
     FROM     folders     f
     JOIN     parent_child     pc ON pc.child_id = f.folder_id
SELECT     j.*,     ROWNUM     
AS r_num
FROM joined_data     j
START WITH     parent_id =0
CONNECT BY     parent_id= PRIOR child_id
ORDER SIBLINGS BY     name;
thanks for the help, hopefully I can find a way to read the rows/record into a data structure (does not have to be a single sql statement - can be anything I can do in PL/SQL.
Edited by: user12200443 on Nov 19, 2012 5:55 PM

Similar Messages

  • How to pass Unix environment variable to a SQL procedure or SQL * Plus

    Can any body suggest me how to ,
    How to pass Unix environment variable to a SQL procedure or SQL * Plus file..
    I am trying to invoke a SQL Procedure from Unix
    by passing the value of a Unix environment variable.
    Is it possible..?
    Thanks in advance.
    Regards,
    Srinivas Jaltaru

    Within your shell script you can use what is known as a "here document" which is basically a way of wrapping a call to Oracle. The following call to Oracle loops and writes rows to files with numerically increasing file names. Two unix shell variables are used, one in a select statement and one in a spool command :
    <pre>
    #!/bin/bash
    export ORACLE_SID=DEV05
    FILENO=1007351
    while [ ${FILENO} -le 1008400 ]
    do
    FILENAME=farm_${FILENO}.txt
    DUMMY=`sqlplus -s user20/user20 <<SQLSTOP
    set lines 73
    set pages 0
    set head off
    set termout off
    set echo off
    set feedback off
    select rpad(searchx, 8)
    from blastx@PRODUCTION
    where searchx = ${FILENO} ### here's a shell variable
    spool /export/home/user20/sql/psiblast/BACKUP2_D/${FILENAME} ### here's a shell variable
    spool off
    SQLSTOP`
    FILENO=`expr ${FILENO} + 1`
    done
    exit 0
    </pre>

  • How to send nested object collection to PL/SQL Procedure as an Input param

    How to send nested object collection to PL/SQL Procedure as an Input parameter.
    The scenario is there is a parent mapping object containing a collection(java.sql.Array) of child objects.
    I need to send the parent object collection to PL/SQL procedure as a input parameter.
    public class parent{
    String attr1;
    String attr2;
    Child[] attr3;
    public class Child{
    String attr1;
    SubChild[] attr2;
    public class SubChild{
    String attr1;
    Urgent!!!
    Edited by: javiost on Apr 30, 2008 2:09 AM

    javiost wrote:
    How to send nested object collection to PL/SQL Procedure as an Input parameter.There are a few ways to do this, all of which likely depend on the particular database you're using.
    Urgent!!!Not to me...

  • How to traverse a tree with a search

    I have a tree that has many leaves or nodes.
    I would like to have a search button where I put in a leaf or node name and it will go to the first occurrence on the tree and a next button that will take me to the next occurrence on the tree.
    The table I have looks like this.
    table name = PASS_NODE
    ID number,
    PARENT_ID NUMBER,
    NODE_NAME VARCHAR2(20)
    the sql code for the tree is:
    select "ID" id,
    "PARENT_ID" pid,
    CASE
    WHEN id = :P1_ID
    THEN '<span class="t1000url">'
    || node_name
    || ' >>'
    || '</span>'
    ELSE node_name
    END name,
    'f?p=&APP_ID.:1:&SESSION.::NO::P1_ID:'||id LINK,
    null a1,
    null a2
    from "#OWNER#"."PASS_NODE"
    order by NODE_NAME
    In the search text field the user will put in the NODE_NAME . I would like the search to traverse the tree by NODE NAME .
    Any ideas?

    I figured this out. In the "Search" process logic it was able to assign the value of the ID to the P1_ID page item.

  • N level tree based on PL/SQL procedure

    Hi everyone,
    I want to display a tree of n levels of employees (n is not known in advance) :
    Root(Boss)
    | Employee1
    | Employee11
    ......... | Employee1NN...
    | Employee12
    | EmployeeN
    .....| EmployeeNN..
    The problem is that I don't have access to tables containing the employees. For each employee I get the "sub-employees" list by calling a PL/SQL stored procedure getEmployees(masterEmployeeName).
    So is there a way in ApEx to create a n level and sublevel tree, each level corresponding to a PL/SQL procedure ?
    Best regards,
    Othman.

    Hi Othman,
    I haven't tried this for a while, the last time I had to do anything like this was to construct a folder structure starting from a root folder.
    Assuming that you can retrieve ID's and employee names in your function, the principle would be something like:
    1 - Create two collections - one for the Tree (to hold ID, Name and Parent ID) and one to hold a list of Employee IDs
    2 - Into the Tree collection, create a new member and insert 0, Root, null (Where 0 is the ID for the top boss and Root is whatever name you need to give this), into c001, c002 and c003
    3 - Into the Employee collection, create a new member and insert 0 into column c001
    4 - Now create a loop to run while the Employee collection contains at least one member
    5 - In the loop:
    5 A) Get the value from c001 in the first member in the collection (this will be the "Parent ID")
    5 B) run your function to retrieve a list of employees relating to that Parent ID, if any
    5 C) Loop through the list and insert a member into the Tree collection: ID, Name, Parent ID and insert the employee's ID into the Employee collection
    5 D) Delete the first member from the Employee collection and resequence the collection (to give you a new member number 1)
    6 - Eventually, you will have no members left in the Employee Collection - your loop should terminate
    7 - You should now have a complete structure in the Tree collection which can be used on the page
    Regards
    Andy

  • How to call shell script from a pl/sql procedure

    Hi all,
    I am little bit new to plsql programming, i have a small problem as follows
    I have to call a shell script from a pl/sql procedure ..
    Please suggest me some methods in oracle 10g, which i could make use of to achieve my goal. also please tell me what are the constraints for those methods if any.
    I already came across dbms_scheduler, but i have got a problem and its nor executing properly its exiting giving 255 error or saying that permission problem, but i have already given full access to my shell scripts.
    Thanks in advance
    Best Regards
    Satya

    Hi,
    Read this thread, perhaps is there your response :
    Host...
    Nicolas.

  • How to access IFS document contents in PL/SQL procedure ?

    I am interested in using IFS as a way to load documents
    (PDF, HTML, RFT, text...) in an Oracle database table, and
    then access the table via a regular application Server.
    I understand that the right way to do this is via a Java API
    mapped on top of IFS.
    But we already have a fairly sophisticated web application using
    Java and PL/SQL procedures so that I would ideally need
    to write a PL/SQL procedure such as :
    function get_document (ifs_file_name in varchar, ifs_file_path in varchar) return clob
    For this I need to outline how to query the IFS schema using SQL.
    Any idea which table to query ?
    Have a nice day

    Many thanks to Chris Schneider : it works. Withing a few hours
    I was able to make a servlet with a file name as a parameter which sends back
    the file contents (in our case its a PDF file).
    Here is a sample servlet which uses this access scheme :
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class TestIFS extends HttpServlet
    * Handle the GET and HEAD methods by building a simple web page.
    * HEAD is just like GET, except that the server returns only the
    * headers (including content length) not the body we write.
    public void doGet (HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException
    //PrintWriter out;
    String title = "Test d'acchs IFS";
    // set content type and other response header fields first
    response.setContentType("application/pdf");
    // then write the data of the response
              ServletOutputStream outbin = response.getOutputStream();
              String theQuery=
         "SELECT "+
         " odm_publicobject.name object_name"+
         ", odmm_contentstore.id content_id"+
         ", odm_format.mimetype"+
         ", odmm_contentstore.globalindexedblob "+
         "FROM odm_publicobject"+
         ", odm_document"+
         ", odm_contentobject"+
         ", odmm_contentstore"+
         ", odm_format "+
         "WHERE odm_publicobject.id = odm_document.id "+
         "AND odm_document.contentobject = odm_contentobject.id "+
         "AND odm_contentobject.content = odmm_contentstore.id "+
         "AND odm_contentobject.format = odm_format.id "+
         "AND odm_publicobject.name = ";
              theQuery += "'" + request.getParameter("fic") + "'";
              try {
                   System.out.println("TestIFS debut");
                   DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
                   Connection conn = DriverManager.getConnection ("jdbc:oracle:oci8:@LXP9","ifssys","ifssys");
                   Statement stmt = conn.createStatement ();
                   ResultSet rset = stmt.executeQuery (theQuery);
                   while (rset.next ()) {
                        byte b[] = new byte[10000000];               
                        b = rset.getBlob(4).getBytes (1,10000000);
                        outbin.write (b);
                   rset.close();
                   System.out.println("TestIFS fin");
              catch (Exception e) {
    (beware mime type is forced to PDF, and file size max 10Mb)

  • How to insert BLOB datatype image using PL/SQL Procedure and SQL Loader

    Hi,
    How to insert an image into database using PL/SQL Procedure and also how to insert using SQL Loader. Please help by giving sample code and process description.
    Thanks,
    Vijay V

    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:232814159006

  • How to traverse the tree in reverse direction?

    How do I roll up numbers up a tree? Suppose I have the following tree (diagram #1). Each node is designated with an ID number,
    representing a primay key in a table. Only leaf nodes have a number (preceded by the @ sign) associated with it (see
    diagram #1). How do I write an efficient SQL that will add up numbers from the leaf nodes and roll up the numbers
    up the entire tree all the way to the root node so the final tree looks like that depicted in diagram #2?
    Diagram #1
                                (1)
                                 |
                                 |
                       |         |            |
                       |         |            |
                      (2)       (3)          (4)@10
                       |          |
                       |           |
                  -------           |
                  |     |           |
                  |     |             |
                 (5)   (6)@20   (7)(@null)
                  |
                  |
                 (8)@30
    Diagram #2
                                (1)@60
                                 |
                                 |
                       |         |            |
                       |         |            |
                      (2)@50    (3)@0        (4)@10
                       |         |(if null)
                       |             |
               ----------             |
               |        |              |
               |        |               |
              (5)@30   (6)@20   (7)(@null)
               |
               |
              (8)@30DB version is 10.2 and OS is Windows server 2008
    create table ad_treenode
    (ad_client_id number(10),
    ad_org_id number(10),
    node_id number(10), --PK
    parent_id number(10)
    INSERT INTO ad_treenode VALUES (11,11,709,704);
    INSERT INTO ad_treenode VALUES (11,11,710,709);
    INSERT INTO ad_treenode VALUES (1000000,0,1000001,0);
    INSERT INTO ad_treenode VALUES (1000000,0,1000002,0);
    INSERT INTO ad_treenode VALUES (1000000,0,1000003,0);
    INSERT INTO ad_treenode VALUES (1000000,0,1000004,0);
    INSERT INTO ad_treenode VALUES (1000000,0,1000005,0);
    INSERT INTO ad_treenode VALUES (1000000,0,1000006,0);
    INSERT INTO ad_treenode VALUES (1000000,0,1000070,0);
    INSERT INTO ad_treenode VALUES (1000000,0,1000071,0);
    INSERT INTO ad_treenode VALUES (1000000,0,1000072,0);
    INSERT INTO ad_treenode VALUES (1000000,0,1000073,0);
    INSERT INTO ad_treenode VALUES (1000000,0,1000074,1000099);
    INSERT INTO ad_treenode VALUES (1000000,0,1000075,0);
    INSERT INTO ad_treenode VALUES (1000000,0,1000076,0);
    INSERT INTO ad_treenode VALUES (1000000,0,1000077,1000074);
    INSERT INTO ad_treenode VALUES (1000000,0,1000078,0);
    INSERT INTO ad_treenode VALUES (1000000,0,1000079,0);
    INSERT INTO ad_treenode VALUES (1000000,0,1000080,1000070);
    INSERT INTO ad_treenode VALUES (1000000,0,1000081,1000070);
    INSERT INTO ad_treenode VALUES (1000000,0,1000082,1000070);
    INSERT INTO ad_treenode VALUES (1000000,0,1000083,1000070);
    INSERT INTO ad_treenode VALUES (1000000,0,1000084,1000070);
    INSERT INTO ad_treenode VALUES (1000000,0,1000085,1000070);
    INSERT INTO ad_treenode VALUES (1000000,0,1000086,1000070);
    INSERT INTO ad_treenode VALUES (1000000,0,1000087,1000070);
    INSERT INTO ad_treenode VALUES (1000000,0,1000088,1000070);
    INSERT INTO ad_treenode VALUES (1000000,0,1000089,1000074);
    INSERT INTO ad_treenode VALUES (1000000,0,1000090,1000074);
    INSERT INTO ad_treenode VALUES (1000000,0,1000091,1000074);
    INSERT INTO ad_treenode VALUES (1000000,0,1000092,1000074);
    INSERT INTO ad_treenode VALUES (1000000,0,1000093,1000076);
    INSERT INTO ad_treenode VALUES (1000000,0,1000094,1000071);
    INSERT INTO ad_treenode VALUES (1000000,0,1000095,1000071);
    INSERT INTO ad_treenode VALUES (1000000,0,1000096,1000071);
    INSERT INTO ad_treenode VALUES (1000000,0,1000097,1000071);
    INSERT INTO ad_treenode VALUES (1000000,0,1000098,1000074);
    INSERT INTO ad_treenode VALUES (1000000,0,1000099,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000100,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000101,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000102,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000103,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000104,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000105,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000106,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000107,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000108,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000109,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000110,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000111,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000112,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000113,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000114,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000115,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000116,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000117,1000075);
    INSERT INTO ad_treenode VALUES (1000000,0,1000118,1000072);
    INSERT INTO ad_treenode VALUES (1000000,0,1000119,1000072);
    INSERT INTO ad_treenode VALUES (1000000,0,1000120,1000077);
    INSERT INTO ad_treenode VALUES (1000000,0,1000000,1000074);
    INSERT INTO ad_treenode VALUES (1000000,0,1000001,1000380);
    INSERT INTO ad_treenode VALUES (1000000,0,1000002,1000090);
    INSERT INTO ad_treenode VALUES (1000000,0,1000003,1000093);
    INSERT INTO ad_treenode VALUES (1000000,0,1000004,1000372);
    INSERT INTO ad_treenode VALUES (1000000,0,1000005,1000093);
    INSERT INTO ad_treenode VALUES (1000000,0,1000006,1000141);
    INSERT INTO ad_treenode VALUES (1000000,0,1000007,1000073);
    INSERT INTO ad_treenode VALUES (1000000,0,1000008,1000094);
    INSERT INTO ad_treenode VALUES (1000000,0,1000009,1000168);
    INSERT INTO ad_treenode VALUES (1000000,0,1000010,1000122);
    INSERT INTO ad_treenode VALUES (1000000,0,1000011,1000168);
    INSERT INTO ad_treenode VALUES (1000000,0,1000012,1000073);
    INSERT INTO ad_treenode VALUES (1000000,0,1000013,1000119);
    INSERT INTO ad_treenode VALUES (1000000,0,1000014,1000080);
    INSERT INTO ad_treenode VALUES (1000000,0,1000015,1000093);
    INSERT INTO ad_treenode VALUES (1000000,0,1000016,1000080);
    INSERT INTO ad_treenode VALUES (1000000,0,1000017,1000080);
    INSERT INTO ad_treenode VALUES (1000000,0,1000018,1000092);
    INSERT INTO ad_treenode VALUES (1000000,0,1000019,1000117);
    INSERT INTO ad_treenode VALUES (1000000,0,1000020,1000090);
    INSERT INTO ad_treenode VALUES (1000000,0,1000021,1000141);
    INSERT INTO ad_treenode VALUES (1000000,0,1000022,1000073);
    INSERT INTO ad_treenode VALUES (1000000,0,1000023,1000117);
    INSERT INTO ad_treenode VALUES (1000000,0,1000024,1000092);
    INSERT INTO ad_treenode VALUES (1000000,0,1000025,1000117);
    INSERT INTO ad_treenode VALUES (1000000,0,1000026,1000120);
    INSERT INTO ad_treenode VALUES (1000000,0,1000027,1000077);
    INSERT INTO ad_treenode VALUES (1000000,0,1000028,1000116);
    INSERT INTO ad_treenode VALUES (1000000,0,1000029,1000380);
    INSERT INTO ad_treenode VALUES (1000000,0,1000030,1000090);
    INSERT INTO ad_treenode VALUES (1000000,0,1000031,1000139);
    INSERT INTO ad_treenode VALUES (1000000,0,1000032,1000081);
    INSERT INTO ad_treenode VALUES (1000000,0,1000033,1000091);
    INSERT INTO ad_treenode VALUES (1000000,0,1000034,1000120);
    INSERT INTO ad_treenode VALUES (1000000,0,1000035,1000094);
    INSERT INTO ad_treenode VALUES (1000000,0,1000036,1000093);
    INSERT INTO ad_treenode VALUES (1000000,0,1000037,1000229);
    INSERT INTO ad_treenode VALUES (1000000,0,1000038,1000380);
    INSERT INTO ad_treenode VALUES (1000000,0,1000039,1000192);
    INSERT INTO ad_treenode VALUES (1000000,0,1000040,1000094);
    INSERT INTO ad_treenode VALUES (1000000,0,1000041,1000120);
    INSERT INTO ad_treenode VALUES (1000000,0,1000042,1000192);
    INSERT INTO ad_treenode VALUES (1000000,0,1000043,1000080);
    INSERT INTO ad_treenode VALUES (1000000,0,1000044,1000074);
    INSERT INTO ad_treenode VALUES (1000000,0,1000045,1000094);
    INSERT INTO ad_treenode VALUES (1000000,0,1000046,1000091);
    INSERT INTO ad_treenode VALUES (1000000,0,1000047,1000083);
    INSERT INTO ad_treenode VALUES (1000000,0,1000048,1000139);
    INSERT INTO ad_treenode VALUES (1000000,0,1000049,1000080);
    INSERT INTO ad_treenode VALUES (1000000,0,1000050,1000117);
    INSERT INTO ad_treenode VALUES (1000000,0,1000051,1000080);
    INSERT INTO ad_treenode VALUES (1000000,0,1000052,1000120);
    INSERT INTO ad_treenode VALUES (1000000,0,1000053,1000122);
    INSERT INTO ad_treenode VALUES (1000000,0,1000054,1000091);
    INSERT INTO ad_treenode VALUES (1000000,0,1000055,1000229);
    INSERT INTO ad_treenode VALUES (1000000,0,1000056,1000116);
    INSERT INTO ad_treenode VALUES (1000000,0,1000057,1000074);
    INSERT INTO ad_treenode VALUES (1000000,0,1000058,1000079);
    INSERT INTO ad_treenode VALUES (1000000,0,1000059,1000117);
    INSERT INTO ad_treenode VALUES (1000000,0,1000060,1000106);
    INSERT INTO ad_treenode VALUES (1000000,0,1000061,1000083);
    INSERT INTO ad_treenode VALUES (1000000,0,1000062,1000076);
    INSERT INTO ad_treenode VALUES (1000000,0,1000063,1000230);
    INSERT INTO ad_treenode VALUES (1000000,0,1000064,1000117);
    INSERT INTO ad_treenode VALUES (1000000,0,1000065,1000117);
    INSERT INTO ad_treenode VALUES (1000000,0,1000066,1000120);
    INSERT INTO ad_treenode VALUES (1000000,0,1000067,1000112);
    INSERT INTO ad_treenode VALUES (1000000,0,1000068,1000108);
    INSERT INTO ad_treenode VALUES (1000000,0,1000069,1000074);
    INSERT INTO ad_treenode VALUES (1000000,0,1000121,1000073);
    INSERT INTO ad_treenode VALUES (1000000,0,1000122,1000073);
    INSERT INTO ad_treenode VALUES (1000000,0,1000123,1000080);
    INSERT INTO ad_treenode VALUES (1000000,0,1000124,1000080);
    INSERT INTO ad_treenode VALUES (1000000,0,1000125,1000080);
    INSERT INTO ad_treenode VALUES (1000000,0,1000126,1000380);
    INSERT INTO ad_treenode VALUES (1000000,0,1000127,1000380);
    INSERT INTO ad_treenode VALUES (1000000,0,1000128,1000081);
    INSERT INTO ad_treenode VALUES (1000000,0,1000129,1000128);
    INSERT INTO ad_treenode VALUES (1000000,0,1000130,1000128);
    INSERT INTO ad_treenode VALUES (1000000,0,1000131,1000128);
    INSERT INTO ad_treenode VALUES (1000000,0,1000132,1000128);
    INSERT INTO ad_treenode VALUES (1000000,0,1000133,1000128);
    INSERT INTO ad_treenode VALUES (1000000,0,1000134,1000081);
    INSERT INTO ad_treenode VALUES (1000000,0,1000135,1000081);
    INSERT INTO ad_treenode VALUES (1000000,0,1000136,1000135);
    INSERT INTO ad_treenode VALUES (1000000,0,1000137,1000135);
    INSERT INTO ad_treenode VALUES (1000000,0,1000138,1000135);
    INSERT INTO ad_treenode VALUES (1000000,0,1000139,1000081);
    INSERT INTO ad_treenode VALUES (1000000,0,1000141,1000081);
    INSERT INTO ad_treenode VALUES (1000000,0,1000142,1000081);
    INSERT INTO ad_treenode VALUES (1000000,0,1000143,1000082);
    INSERT INTO ad_treenode VALUES (1000000,0,1000144,1000082);
    INSERT INTO ad_treenode VALUES (1000000,0,1000145,1000082);
    INSERT INTO ad_treenode VALUES (1000000,0,1000146,1000150);
    INSERT INTO ad_treenode VALUES (1000000,0,1000147,1000150);
    INSERT INTO ad_treenode VALUES (1000000,0,1000148,1000150);
    INSERT INTO ad_treenode VALUES (1000000,0,1000149,1000150);
    INSERT INTO ad_treenode VALUES (1000000,0,1000150,1000084);
    INSERT INTO ad_treenode VALUES (1000000,0,1000151,1000084);
    INSERT INTO ad_treenode VALUES (1000000,0,1000152,1000151);
    INSERT INTO ad_treenode VALUES (1000000,0,1000153,1000151);
    INSERT INTO ad_treenode VALUES (1000000,0,1000154,1000151);
    INSERT INTO ad_treenode VALUES (1000000,0,1000155,1000084);
    INSERT INTO ad_treenode VALUES (1000000,0,1000156,1000155);
    INSERT INTO ad_treenode VALUES (1000000,0,1000157,1000085);
    INSERT INTO ad_treenode VALUES (1000000,0,1000158,1000085);
    INSERT INTO ad_treenode VALUES (1000000,0,1000159,1000085);
    INSERT INTO ad_treenode VALUES (1000000,0,1000160,1000085);
    INSERT INTO ad_treenode VALUES (1000000,0,1000161,1000085);
    INSERT INTO ad_treenode VALUES (1000000,0,1000162,1000086);
    INSERT INTO ad_treenode VALUES (1000000,0,1000163,1000086);
    INSERT INTO ad_treenode VALUES (1000000,0,1000164,1000086);
    INSERT INTO ad_treenode VALUES (1000000,0,1000165,1000086);
    INSERT INTO ad_treenode VALUES (1000000,0,1000166,1000086);
    INSERT INTO ad_treenode VALUES (1000000,0,1000167,1000086);
    INSERT INTO ad_treenode VALUES (1000000,0,1000168,1000086);
    INSERT INTO ad_treenode VALUES (1000000,0,1000169,1000087);
    INSERT INTO ad_treenode VALUES (1000000,0,1000170,1000087);
    INSERT INTO ad_treenode VALUES (1000000,0,1000171,1000087);
    INSERT INTO ad_treenode VALUES (1000000,0,1000172,1000087);
    INSERT INTO ad_treenode VALUES (1000000,0,1000173,1000087);
    INSERT INTO ad_treenode VALUES (1000000,0,1000174,1000087);
    INSERT INTO ad_treenode VALUES (1000000,0,1000175,1000087);
    INSERT INTO ad_treenode VALUES (1000000,0,1000176,1000087);
    INSERT INTO ad_treenode VALUES (1000000,0,1000177,1000087);
    INSERT INTO ad_treenode VALUES (1000000,0,1000178,1000087);
    INSERT INTO ad_treenode VALUES (1000000,0,1000179,1000088);
    INSERT INTO ad_treenode VALUES (1000000,0,1000180,1000179);
    INSERT INTO ad_treenode VALUES (1000000,0,1000181,1000179);
    INSERT INTO ad_treenode VALUES (1000000,0,1000182,1000179);
    INSERT INTO ad_treenode VALUES (1000000,0,1000183,1000179);
    INSERT INTO ad_treenode VALUES (1000000,0,1000184,1000179);
    INSERT INTO ad_treenode VALUES (1000000,0,1000185,1000088);
    INSERT INTO ad_treenode VALUES (1000000,0,1000186,1000088);
    INSERT INTO ad_treenode VALUES (1000000,0,1000187,1000229);
    INSERT INTO ad_treenode VALUES (1000000,0,1000188,1000230);
    INSERT INTO ad_treenode VALUES (1000000,0,1000189,1000230);
    INSERT INTO ad_treenode VALUES (1000000,0,1000190,1000230);
    INSERT INTO ad_treenode VALUES (1000000,0,1000191,1000230);
    INSERT INTO ad_treenode VALUES (1000000,0,1000192,1000094);
    INSERT INTO ad_treenode VALUES (1000000,0,1000193,1000094);
    INSERT INTO ad_treenode VALUES (1000000,0,1000194,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000195,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000196,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000197,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000198,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000199,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000201,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000202,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000203,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000204,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000205,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000207,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000208,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000209,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000210,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000211,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000212,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000213,1000096);
    INSERT INTO ad_treenode VALUES (1000000,0,1000214,1000096);
    INSERT INTO ad_treenode VALUES (1000000,0,1000215,1000097);
    INSERT INTO ad_treenode VALUES (1000000,0,1000216,1000097);
    INSERT INTO ad_treenode VALUES (1000000,0,1000217,1000097);
    INSERT INTO ad_treenode VALUES (1000000,0,1000218,1000097);
    INSERT INTO ad_treenode VALUES (1000000,0,1000219,1000097);
    INSERT INTO ad_treenode VALUES (1000000,0,1000220,1000118);
    INSERT INTO ad_treenode VALUES (1000000,0,1000221,1000118);
    INSERT INTO ad_treenode VALUES (1000000,0,1000222,1000118);
    INSERT INTO ad_treenode VALUES (1000000,0,1000223,1000118);
    INSERT INTO ad_treenode VALUES (1000000,0,1000225,1000119);
    INSERT INTO ad_treenode VALUES (1000000,0,1000226,1000119);
    INSERT INTO ad_treenode VALUES (1000000,0,1000229,1000094);
    INSERT INTO ad_treenode VALUES (1000000,0,1000230,1000094);
    INSERT INTO ad_treenode VALUES (1000000,0,1000231,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000232,1000095);
    INSERT INTO ad_treenode VALUES (1000000,0,1000233,1000073);
    INSERT INTO ad_treenode VALUES (1000000,0,1000234,1000073);
    INSERT INTO ad_treenode VALUES (1000000,0,1000235,1000121);
    INSERT INTO ad_treenode VALUES (1000000,0,1000236,1000121);
    INSERT INTO ad_treenode VALUES (1000000,0,1000237,1000121);
    INSERT INTO ad_treenode VALUES (1000000,0,1000238,1000121);
    INSERT INTO ad_treenode VALUES (1000000,0,1000239,1000121);
    INSERT INTO ad_treenode VALUES (1000000,0,1000240,1000121);
    INSERT INTO ad_treenode VALUES (1000000,0,1000241,1000121);
    INSERT INTO ad_treenode VALUES (1000000,0,1000242,1000121);
    INSERT INTO ad_treenode VALUES (1000000,0,1000243,1000121);
    INSERT INTO ad_treenode VALUES (1000000,0,1000244,1000121);
    INSERT INTO ad_treenode VALUES (1000000,0,1000245,1000073);
    INSERT INTO ad_treenode VALUES (1000000,0,1000247,1000122);
    INSERT INTO ad_treenode VALUES (1000000,0,1000248,1000074);
    INSERT INTO ad_treenode VALUES (1000000,0,1000249,1000074);
    INSERT INTO ad_treenode VALUES (1000000,0,1000250,1000074);
    INSERT INTO ad_treenode VALUES (1000000,0,1000251,1000089);
    INSERT INTO ad_treenode VALUES (1000000,0,1000252,1000089);
    INSERT INTO ad_treenode VALUES (1000000,0,1000253,1000090);
    INSERT INTO ad_treenode VALUES (1000000,0,1000254,1000074);
    INSERT INTO ad_treenode VALUES (1000000,0,1000255,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000256,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000257,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000258,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000259,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000260,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000261,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000262,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000263,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000264,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000265,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000266,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000267,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000268,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000269,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000270,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000271,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000272,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000273,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000274,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000275,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000276,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000277,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000278,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000279,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000280,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000281,1000098);
    INSERT INTO ad_treenode VALUES (1000000,0,1000282,1000099);
    INSERT INTO ad_treenode VALUES (1000000,0,1000283,1000099);
    INSERT INTO ad_treenode VALUES (1000000,0,1000284,1000099);
    INSERT INTO ad_treenode VALUES (1000000,0,1000285,1000100);
    INSERT INTO ad_treenode VALUES (1000000,0,1000286,1000100);
    INSERT INTO ad_treenode VALUES (1000000,0,1000287,1000100);
    INSERT INTO ad_treenode VALUES (1000000,0,1000288,1000100);
    INSERT INTO ad_treenode VALUES (1000000,0,1000289,1000100);
    INSERT INTO ad_treenode VALUES (1000000,0,1000290,1000100);
    INSERT INTO ad_treenode VALUES (1000000,0,1000291,1000100);
    INSERT INTO ad_treenode VALUES (1000000,0,1000292,1000101);
    INSERT INTO ad_treenode VALUES (1000000,0,1000293,1000101);
    INSERT INTO ad_treenode VALUES (1000000,0,1000294,1000101);
    INSERT INTO ad_treenode VALUES (1000000,0,1000295,1000102);
    INSERT INTO ad_treenode VALUES (1000000,0,1000296,1000102);
    INSERT INTO ad_treenode VALUES (1000000,0,1000297,1000102);
    INSERT INTO ad_treenode VALUES (1000000,0,1000298,1000102);
    INSERT INTO ad_treenode VALUES (1000000,0,1000299,1000103);
    INSERT INTO ad_treenode VALUES (1000000,0,1000300,1000103);
    INSERT INTO ad_treenode VALUES (1000000,0,1000301,1000104);
    INSERT INTO ad_treenode VALUES (1000000,0,1000302,1000104);
    INSERT INTO ad_treenode VALUES (1000000,0,1000303,1000104);
    INSERT INTO ad_treenode VALUES (1000000,0,1000304,1000104);
    INSERT INTO ad_treenode VALUES (1000000,0,1000305,1000105);
    INSERT INTO ad_treenode VALUES (1000000,0,1000306,1000105);
    INSERT INTO ad_treenode VALUES (1000000,0,1000307,1000105);
    INSERT INTO ad_treenode VALUES (1000000,0,1000308,1000105);
    create table c_elementvalue
    (ad_client_id number(10),
    ad_org_id number(10),
    c_elementvalue_id number(10), --PK     and   ad_treenode.node_id = c_elementvalue.c_elementvalue_id
    name varchar(100)
    INSERT INTO c_elementvalue VALUES (1000000,0,1000070, 'Assets');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000073, 'Sales');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000074, 'Cost of Goods Sold');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000075, 'Expenses');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000076, 'Other Income');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000077, 'Other Expenses');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000078, 'Costing');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000079, 'Commitment Accounting');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000080, 'Cash');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000081, 'Account Receivable');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000082, 'Investments');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000083, 'Inventory');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000085, 'Land And Building');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000087, 'Accumulated Depriciation');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000088, 'Other Assets');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000089, 'Returns');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000090, 'Inventry CoGs');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000091, 'CoGs Variances');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000092, 'CoGs Discounts');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000093, 'Currency gain');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000094, 'Account Payables');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000095, 'Accrued Expenses');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000096, 'Current Note Payables');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000097, 'Long Term liabilities');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000098, 'Payroll Expenses');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000099, 'Occupancy Cost');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000384, 'Late Fee Charge Revenue');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000385, 'Cash Transfer to Tower');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000386, 'Cash Transfer From B.Ed College');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000387, 'Cash Transfer from BHM College');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000388, 'Cash Transfer from Engg College');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000389, 'Cash Transfer from MBA College');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000390, 'Cash Transfer from Polytechnic College');
    INSERT INTO c_elementvalue VALUES (1000000,0,1000391, 'Cash Transfer from School');
    create table t_trialbalance
    (ad_client_id number(10),
    ad_org_id number(10),
    account_id number(10), --PK   and   t_trialbalance.account_id = t_trialbalance.t_trialbalance_id   or   ad_tree.node_id  =   t_trialbalance.account_id
    amtsourcecr number(10),
    amtsourcedr number(10)
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000051, 0 , 21000);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000029, 21000 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 15900);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 15200);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 10500);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 18500);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 40400);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000008, 100500 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000012, 34550 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000029, 0 , 34550);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000023, 1000 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000029, 0 , 1000);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000017, 0 , 20000);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000051, 20000 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000051, 0 , 20000);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000029, 20000 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000012, 6400 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000029, 0 , 6400);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000017, 0 , 39695);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000051, 39695 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 1160);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000008, 1160 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 580);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 48);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000008, 628 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000023, 1000 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000029, 0 , 1000);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 23.34);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000023, 1000 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000029, 0 , 1000);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000017, 0 , 63650);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000051, 63650 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000051, 0 , 63650);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000029, 63650 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000017, 0 , 35795);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000051, 35795 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000017, 0 , 51900);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000051, 51900 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000051, 0 , 51900);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000029, 51900 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000051, 0 , 35795);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000029, 35795 , 0);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 13700);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 8120);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 13700);
    INSERT INTO t_trialbalance VALUES (1000000,1000002,1000061, 0 , 36200);
    I had two sql's but not upto mark
    SELECT LPAD(' ', 2*level-1)||SYS_CONNECT_BY_PATH(node_id, '/') "Path"
          FROM ad_treenode
          START WITH parent_id = 0
          CONNECT BY PRIOR node_id = parent_id;
    select ad_client_id, ad_org_id, rpad('*',2*level,'*') || node_id , parent_id,
             (select sum(amtsourcecr)
                    from t_trialbalance t2
                       start with t2.account_id = t1.node_id
                       connect by prior node_id = parent_id) amtsourcecr,
             (select name from c_elementvalue where c_elementvalue_id=t1.node_id) name
    from ad_treenode t1
    start with parent_id = 0
    connect by prior node_id = parent_id;The o/p i want according to diagram-2 is
    node_id    node_name(from c_elementvalue)      amtsourcecr(from t_trialbalance)
    1                     aaa                                            60
    2                     bbb                                            50
    3                     ccc                                               0
    4                     ddd                                            10
    5                     eee                                            30
    6                     fff                                               20
    7                     ggg                                             null
    8                      hhh                                            30Edited by: Navneet Singh on Mar 6, 2012 4:02 PM
    Edited by: Navneet Singh on Mar 6, 2012 4:03 PM

    I tried according the upper suggestions. The below query is too slow that i made. It takes 10 minutes to fetch the result. I think the data is too much thats y. Is there any other method that it can fetches out the result with in 1-2 minutes.
    SELECT     e.ad_client_id, e.ad_org_id,
                  LPAD (' ', LEVEL * 2) || e.NAME AS NAME, e.node_id, e.parent_id,
                  amtcr,
                  NVL ((SELECT     SUM (amtcr)
                              FROM (SELECT   a.ad_client_id, a.ad_org_id,
                                             a.node_id, a.parent_id,
                                             SUM (b.amtsourcecr) AS amtcr,
                                             SUM (b.amtsourcedr) AS amtdr, c.NAME,
                                             b.c_acctschema_id, b.c_period_id,
                                             b.dateacct, b.account_id,
                                             b.accountvalue, b.postingtype,
                                             b.ad_pinstance_id
                                        FROM ad_treenode a LEFT OUTER JOIN t_trialbalance b
                                             ON b.account_id = a.node_id
                                             LEFT OUTER JOIN c_elementvalue c
                                             ON c.c_elementvalue_id = a.node_id
                                    GROUP BY a.ad_client_id,
                                             a.ad_org_id,
                                             a.node_id,
                                             a.parent_id,
                                             NAME,
                                             b.c_acctschema_id,
                                             b.c_period_id,
                                             b.dateacct,
                                             b.account_id,
                                             b.accountvalue,
                                             b.postingtype,
                                             b.ad_pinstance_id) e2
                              WHERE e2.ad_pinstance_id = e.ad_pinstance_id
                               AND e2.dateacct = e.dateacct
                               AND e2.postingtype = e.postingtype
                               AND e2.c_acctschema_id = e.c_acctschema_id
                               AND e2.ad_org_id = e.ad_org_id
                               AND e2.ad_client_id = e.ad_client_id
                        START WITH e2.node_id = e.node_id
                        CONNECT BY e2.parent_id = PRIOR e2.node_id),
                       0
                      ) amt_cr2,
                  amtdr,
                  NVL ((SELECT     SUM (amtdr)
                              FROM (SELECT   a.ad_client_id, a.ad_org_id,
                                             a.node_id, a.parent_id,
                                             SUM (b.amtsourcecr) AS amtcr,
                                             SUM (b.amtsourcedr) AS amtdr, c.NAME,
                                             b.c_acctschema_id, b.c_period_id,
                                             b.dateacct, b.account_id,
                                             b.accountvalue, b.postingtype,
                                             b.ad_pinstance_id
                                        FROM ad_treenode a LEFT OUTER JOIN t_trialbalance b
                                             ON b.account_id = a.node_id
                                             LEFT OUTER JOIN c_elementvalue c
                                             ON c.c_elementvalue_id = a.node_id
                                    GROUP BY a.ad_client_id,
                                             a.ad_org_id,
                                             a.node_id,
                                             a.parent_id,
                                             NAME,
                                             b.c_acctschema_id,
                                             b.c_period_id,
                                             b.dateacct,
                                             b.account_id,
                                             b.accountvalue,
                                             b.postingtype,
                                             b.ad_pinstance_id) e2
                              WHERE e2.ad_pinstance_id = e.ad_pinstance_id
                               AND e2.dateacct = e.dateacct
                               AND e2.postingtype = e.postingtype
                               AND e2.c_acctschema_id = e.c_acctschema_id
                               AND e2.ad_org_id = e.ad_org_id
                               AND e2.ad_client_id = e.ad_client_id
                         START WITH e2.node_id = e.node_id
                        CONNECT BY e2.parent_id = PRIOR e2.node_id),
                       0
                      ) amt_dr2,
                  e.c_acctschema_id, e.c_period_id, e.dateacct, e.account_id,
                  e.accountvalue, e.postingtype, e.ad_pinstance_id
             FROM (SELECT   a.ad_client_id, b.ad_org_id, a.node_id, a.parent_id,
                            SUM (b.amtsourcecr) AS amtcr,
                            SUM (b.amtsourcedr) AS amtdr, c.NAME,
                            b.c_acctschema_id, b.c_period_id, b.dateacct,
                            b.account_id, b.accountvalue, b.postingtype,
                            b.ad_pinstance_id
                       FROM ad_treenode a LEFT OUTER JOIN t_trialbalance b
                            ON b.account_id = a.node_id
                            LEFT OUTER JOIN c_elementvalue c
                            ON c.c_elementvalue_id = a.node_id
                   GROUP BY a.ad_client_id,
                            b.ad_org_id,
                            a.node_id,
                            a.parent_id,
                            NAME,
                            b.c_acctschema_id,
                            b.c_period_id,
                            b.dateacct,
                            b.account_id,
                            b.accountvalue,
                            b.postingtype,
                            b.ad_pinstance_id) e
        where e.ad_org_id=1000002
       START WITH e.parent_id = 0
       CONNECT BY e.parent_id = PRIOR e.node_id
         ORDER SIBLINGS BY e.NAME;
    SQL> select count(*) from t_trialbalance;
      COUNT(*)
        108384
    SQL> select count(*) from ad_treenode;
      COUNT(*)
          1366
    SQL> select count(*) from c_elementvalue;
      COUNT(*)
           971Is there any way to get out this hangout?

  • How to load my tree with data from SQL database????

    Hello friends
    May i know how i can load my tree with my database??
    i have 3 different tables and i need them to be the 3 main nodes of my tree
    They are
    1.fiche
    2.amis and
    3.famille
    and in each of these nodes need to load the 3 databases
    thank u in advance

    Heres my program so i loaded my vector ,
    Now how can i integrate the coding u gave me, and where ??
    Is it where i put the quetion mark?
    if so
    can you tell me how?? because i didnt understood well the codings you gave me as im nt at all familiar with this
    Thank you in advance
    public class carnetf extends javax.swing.JFrame  {
       DefaultMutableTreeNode root =null;
        public carnetf() {
           root= new DefaultMutableTreeNode("Carnet");
            DefaultMutableTreeNode tnFiche=new DefaultMutableTreeNode("Fiche");
           root.add( tnFiche);
            DefaultMutableTreeNode tnAmis=new DefaultMutableTreeNode("Amis");
            root.add( tnAmis);
            DefaultMutableTreeNode tnFamille=new DefaultMutableTreeNode("Famille");
            root.add( tnFamille);
           initComponents();
        public Vector vecfiche() {
            Vector v = new Vector();    
            Connection connection = null;
            try
                Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
                DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());;
            catch (Exception E)
                System.out.println("Unable to load driver.");
                System.out.println(E.getMessage());
                E.printStackTrace();
                return null;
            try
                connection = DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433;user=sa;password=sa;DatabaseName=carnet");
            catch (Exception E)
                System.out.println("Unable to connect.");
                System.out.println(E.getMessage());
                return null;
            try
                Statement Stmt = connection.createStatement();
                if(jRadioButton1.isSelected()==true)  
                    String Query = "SELECT * FROM fiche";
                ResultSet RS= Stmt.executeQuery( Query );
                while ( RS.next())
                 v.add( new vecfiche( RS.getString("Nom"), RS.getString("Prenom")));
                if( RS!= null) RS.close();}
                if(jRadioButton2.isSelected()==true)  
                    String Query = "SELECT * FROM amis";
                ResultSet RS= Stmt.executeQuery( Query );
                while ( RS.next())
                 v.add( new vecfiche( RS.getString("Anom"), RS.getString("Aprenom")));
                if( RS!= null) RS.close();}
                if(jRadioButton3.isSelected()==true)  
                    String Query = "SELECT * FROM famille";
                ResultSet RS= Stmt.executeQuery( Query );
                while ( RS.next())
                 v.add( new vecfiche( RS.getString("Fnom"), RS.getString("Fprenom")));
                if( RS!= null) RS.close();}
                if( Stmt!= null) Stmt.close();
            catch (Exception E)
                System.out.println("Unable to query.");
                System.out.println(E.getMessage());
                return null;
            try
                connection.close();
            } catch (Exception E)
                System.out.println("Unable to close.");
                System.out.println(E.getMessage());
                return null;
            return v;
        }

  • How to collapse all tree nodes in PL/SQL?

    I'm experimenting with manipulating trees in page processes by using e.g. FLOWS_030100.WWV_FLOW_TREE.EXPAND but I don't see how to implement the functionality of the "Collapse All" button in PL/SQL. Maybe somehow manipulate the FLOWS_030100.WWV_FLOW_TREE_GLOBAL_VARS variables directly but how?

    Hi,
    I'm also interested in something like this. I'm trying to collapse all when a selectlist with submit that affects the tree is changed. I've tried creating a conditional branch that catches said change, using the 'COLLAPSE ALL' request that the autogenerated button calls, but it didn't work.
    Any ideas?
    Thank You,
    Marc

  • How to generate a form based on PL/SQL-procedures instead of tables?

    Hi all,
    I'm trying to generate a form based on a package, which has procedures for insert/update/delete/select. In Forms, this is no problem. It is unclear to me how to do this in Oracle Designer (10g). Online Help of Designer doesn't clear things up a lot, it seems I have to generate a table API and a module component API. But when I do this, these are generated as file and no definitions are created in Designer. So what do I base my block on?
    Can somebody assist me in this?
    Kind regards,
    Ronald

    Hi:
    Thank you for reply to my question.
    I have tried your codes and apply them the following the form. However, I always got the following error:
    Error: (WWV-00000)
    No conversion performed for type INTEGER, value . (WWC-49102)
    No conversion performed for type INTEGER, value . (WWC-49102)
    No conversion performed for type INTEGER, value . (WWC-49102)
    No conversion performed for type INTEGER, value . (WWC-49102)
    My codes is:
    declare
    request_no number;
    blk varchar2(30) := 'DEFAULT';
    l_url varchar2(4000);
    begin
    request_no := p_session.get_value_as_NuMBER(
    p_block_name => blk,
    p_attribute_name => 'A_WORK_REQUEST_ID');
    l_url := 'portal30.wwa_app_module.link?p_arg_names=_moduleid&p_arg_values=11880470335&p_arg_names=_sessionid&p_arg_values=&p_arg_names=work_request_id&p_arg_values='||request_no;
    portal30.wwa_app_module.set_target(l_url,'call');
    end;
    then,
    I created another form which has two fields and the dattype of pk is varchar2 and change manually put the pk's p_arg_value into the url.
    e.g.
    l_url:='PORTAL30.wwa_app_module.link?p_arg_names=_moduleid&p_arg_values=9029417810&p_arg_names=WORK_AREA_CD&p_arg_values=APP';
    portal30.wwa_app_module.set_target(l_url,'call');
    However, I still get the error message as below:
    Error: (WWV-00000)
    No conversion performed for type INTEGER, value . (WWC-49102)
    No conversion performed for type INTEGER, value . (WWC-49102)
    No conversion performed for type INTEGER, value . (WWC-49102)
    No conversion performed for type INTEGER, value . (WWC-49102)
    No conversion performed for type INTEGER, value . (WWC-49102)
    Your help would be highly appreciated.
    Wei Ye

  • How to accept user values into a pl/sql procedure or function on every execution

    As we accept user values on every execution in a C or a java program, is it possible to do so with a pl/sql procedure or a funtion without using parameters?
    I cannot use parameters because it is required to be interactive while accepting the user-values like,
    Please enter your date of birth in 'dd/mm/yyyy' format:

    It depends from where you are calling your PLSQL routine. If it is SQL*Plus then you can use & (ampersand) with the variable to be input at run time.
    If you are executing the PLSQL routine from another application (some front end application) then it's not possible. Because when a procedure is executing at server side, the front end application does not have control, and the control is only transfered back to front end application when the PLSQL routine either completes successfully or throws an exception.
    In either case, you can not go back to the PLSQL routine.
    In this case, what you can do is, write code in your front end application to get that variable value from user and then pass that value to PLSQL routine.

  • How do I delete cascade with a PL/SQL procedure?

    This script will create a PL/SQL procedure that deletes cascade. This is a post to contribute to the Oracle community. Take the code as is and test it before you use it in production. Make sure this is what you want.
    Procedure Delete Cascade (prc_delete_cascade)
    Description
    =============
    The principle is very simple. The procedure uses a table called TO_BE_DELETED to keep a list of records to be deleted. This
    table keeps the table name and the rowid of those records that need to be deleted. The procedure also uses a function called
    DELETE_BOTT_ROW which takes one record of the table and tries to delete it. If the deletion fails with a foreign key constraint
    violation, the function parses the SQL error message (SQLERRM) to get the name of the constraint. With the name of the constraint,
    the function finds the name of the child table, all the child records that have references to the parent table primary or unique key,
    and the parent key primary or unique key column name. Once the child records of the failed delete are identified, the function takes their table name and rowids
    and records them into the TO_BE_DELETED table by inserting records of their table name and their rowids. Al the records inserted also contain the level (which
    is 1 for the original records, 2 for child records, 3 for granchild records, etc.) and the sequence number of the order in wich they
    are recorded. This way, when the function picks up a record to be deleted, it takes the one with the highest level and the highest
    inserted sequence, or the "bottom" record. Once all the child records of the failed delete are appended to the TO_BE_DELETED table, it calls itself
    recursevely, and the function takes the record at the "bottom" of the table and tries to delete it. If it succeeds, it calls
    itself recursevely to delete the next record. If it fails, it goes and finds the child records as described before and once they are
    inserted into the TO_BE_DELETED table, it calls itself again recursevely to try to delete again the "bottom" record. All records
    that are successfully deleted are flagged as deleted usig the flag_del column so they are not pickt up again. Once all the (parent,
    child, grandchild, etc.) records are deleted, the procedure ends without commiting, giving the option to the user to commit or
    rollback deletions. The table TO_BE_DELETED is, at the end of the procedure, a list of all the records that were deleted, including their table names
    and the order in with they were deleted. The user then can review its content and decide to commit or rollback.
    Restrictions
    ============
    1. Single tables only. The procedure only takes one table name and a WHERE clause to identified the records to be deleted.
    2. Single columns only. Ther procedure only works with single-column primary, unique and foreign key constraints.
    3. Single schema only.
    4. Unpredictable results with circular references.
    drop table to_be_deleted purge;
    create table to_be_deleted
    (tname varchar2(30)       -- table name
    ,rid rowid                -- rowid
    ,lvl number               -- level: 1=parent, 2=child, 3=grandchild, etc.
    ,seq_ins number           -- sequence order of record inserted
    ,flg_del char             -- flag deleted: Y=record deleted
    ,seq_del number           -- global order of record deletion
    set serveroutput on size 1000000
    create or replace procedure prc_delete_cascade
    (p_tname varchar2  -- table name
    ,p_where varchar2  -- where clause identifying records to be cascade deleted
    is
      dummy         char;
      v_sqlcode     number;
      v_sqlerrm     varchar2(32767);
      v_param_val   integer := 0;
      v_sql         varchar2(4000);
      v_ret_cde     number;
      e_bad_params  exception;
      v_iter        number;
      v_plvl        number;
      v_seq_del     number;
      v_max_iter    number := 1000000000;
      function delete_bott_row
      return number
      is
        v_sql        varchar2(4000);
        v_ptname     varchar2(30);  -- parent table name
        v_ppkname    varchar2(30);  -- parent primary key constraint name
        v_ppkcname   varchar2(30);  -- parnet primary key column name
        v_prowid      rowid;
        v_crowid      rowid;
        v_ctname     varchar2(30);  -- child table name
        v_cfkname    varchar2(30);  -- child foreign key constraint name
        v_cfkcname   varchar2(30);  -- child foreign key column name
        v_ins        number;
        v_seq_ins    number;
        v_sqlerrm    varchar2(4000);
        v_sqlcode    number;
        e_const_viol exception;
        pragma exception_init(e_const_viol, -2292);
        e_max_iter_reached exception;
      begin
        v_iter := v_iter + 1;
        if v_iter >= v_max_iter then
          raise e_max_iter_reached;
        end if;
        dbms_output.put_line('- Iter '||to_char(v_iter));
        dbms_output.put_line('----------');
        dbms_output.put_line('- Starting function delete_bott_row');
        v_sql := 'select tname, rid, lvl, seq_ins from (select * from to_be_deleted where flg_del = ''N'' order by lvl desc, seq_ins desc) where rownum=1';
        --  dbms_output.put_line('- SQL: '||v_sql);
        execute immediate v_sql into v_ptname, v_prowid, v_plvl, v_seq_ins;
        dbms_output.put_line('- Selected row: table name: '||v_ptname||', level: '||v_plvl||', seq: '||v_seq_ins);
        v_sql := 'delete from '||v_ptname||' where rowid='''||v_prowid||'''';
        dbms_output.put_line('- SQL: '||v_sql);
        execute immediate v_sql;
        dbms_output.put_line('- Row deleted !!!');
        v_ret_cde := 1;
        v_seq_del := v_seq_del + 1;
        dbms_output.put_line('- Mark the row deleted');
        v_sql := 'update to_be_deleted set flg_del = ''Y'', seq_del = '||to_char(v_seq_del)||' where tname='''||v_ptname||''' and rid='''||v_prowid||'''';
        -- dbms_output.put_line('- SQL: '||v_sql);
        execute immediate v_sql;
        -- dbms_output.put_line('- Updated table to_be_deleted, row marked deleted');
        -- dbms_output.put_line('- End of iter '||to_char(v_iter));
        dbms_output.put_line('----------');
        -- call function delete_bott_row recursively
        v_ret_cde := delete_bott_row;
        return 0;
      exception
        when no_data_found then
          dbms_output.put_line('- Table to_be_deleted is empty, delete cascade has completed successfully.');
          v_ret_cde := 0;
          return 0;
        when e_const_viol then
          v_sqlcode := SQLCODE;
          v_sqlerrm := SQLERRM;
          v_ret_cde := v_sqlcode;
          dbms_output.put_line('>Constraint Violation. Record has children');
          -- dbms_output.put_line('Error code: '||to_char(v_sqlcode));
          v_cfkname := substr(v_sqlerrm,instr(v_sqlerrm,'.')+1,instr(v_sqlerrm,')') - instr(v_sqlerrm,'.')-1);
          dbms_output.put_line('>Child FK name: '||v_cfkname);
          select table_name, column_name
            into v_ctname, v_cfkcname
            from user_cons_columns
           where constraint_name=v_cfkname;
          dbms_output.put_line('>Child table name: '||v_ctname||'. FK column name: '|| v_cfkcname);
          select constraint_name, column_name
            into v_ppkname, v_ppkcname
            from user_cons_columns
           where constraint_name = (select r_constraint_name
                                      from user_constraints
                                      where constraint_name=v_cfkname);
          dbms_output.put_line('>Parent PK/UK name: '||v_ppkname||'. Parent PK/UK column: '||v_ppkcname);
          v_sql := 'insert into to_be_deleted(tname, rid, lvl, seq_ins, flg_del) '||
                   'select '''||v_ctname||''', rowid, '||to_char(v_plvl+1)||', rownum, ''N'' '||
                   'from '||v_ctname||' '||
                   'where '||v_cfkcname||' =any (select '||v_ppkcname||' from '||v_ptname||' where rowid =any (select rid from to_be_deleted where tname = '''||v_ptname||'''))';
          -- dbms_output.put_line('- SQL: '||v_sql);
          execute immediate v_sql;
          select count(*)
            into v_ins
            from to_be_deleted
           where lvl = v_plvl+1
             and tname = v_ctname
             and flg_del = 'N';
          dbms_output.put_line('>Found '||to_char(v_ins)||' child records which were added to table to_be_deleted');  
          v_ret_cde := delete_bott_row;
          return  v_ret_cde;
        when e_max_iter_reached then
          dbms_output.put_line('Maximum iterations reached.  Terminating procedure.');
          raise;
        when others then
          raise;
      end delete_bott_row;
    begin
      dbms_output.put_line('Beginning');
      dbms_output.put_line('================================');
      -- validate p_table
      begin
        select 'Y'
          into dummy
          from user_tables
         where table_name=upper(p_tname);
      exception
        when no_data_found then
        v_param_val := 1;
        dbms_output.put_line('Table '||p_tname||' does not exist.');
        raise e_bad_params;
      end;
      dbms_output.put_line('- Parameter p_tname validated');
      -- validate p_where
      begin
        execute immediate 'select ''Y'' from '||p_tname||' where '||p_where INTO dummy;
      exception
        when no_data_found then  -- where clause returns no records
          dbms_output.put_line('Record(s) not found.  Check your where clause parameter');
          v_param_val := 2;
          raise e_bad_params;
        when too_many_rows then  -- found multiple records means it is ok
          null; 
        when others then  --  any other records means where clause has something wrong.
          dbms_output.put_line('Where clause is malformed');     
          v_param_val := 2;
          raise e_bad_params;
      end;   
      dbms_output.put_line('- Parameter p_where validated');
      if v_param_val > 0 then raise e_bad_params; end if;
      v_iter := 0;
      v_plvl := 1;
      v_seq_del := 0;
      v_sql := 'insert into to_be_deleted(tname, rid, lvl, seq_ins, flg_del) select '''||upper(p_tname)||''', rowid, '||to_char(v_plvl)||', rownum, ''N'' from '||p_tname||' where '||p_where;
      dbms_output.put_line('- Inserting initial record');
      dbms_output.put_line('- SQL: '||v_sql);
      execute immediate v_sql;
      dbms_output.put_line('- Record(s) inserted');
      dbms_output.put_line('- Calling function delete_bott_row to delete last row of table to_be_deleted');              
      dbms_output.put_line('-----------------------------------');              
      v_ret_cde :=  delete_bott_row;
      -- dbms_output.put_line('- Back from function delete_bott_row');              
      -- dbms_output.put_line('Return code: '||to_char(v_ret_cde));              
      dbms_output.put_line('- End of procedure');              
    exception
      when e_bad_params then
        dbms_output.put_line('Bad parameters, exiting.');
    end;
    show errors
    spool prc_delete_cascade.log
    --  Call to the procedure
    exec prc_delete_cascade('xent','xent_id between 1669 and 1670')
    select tname "Table Name", count(*) "Rows deleted"
      from to_be_deleted
    group by tname;
    spool off
    set lines 120
    select *
      from to_be_deleted
    order by seq_del;
    prompt  Now commit or rollaback deletions.
    -- commit;
    -- rollback;Edited by: Rodolfo4 on Mar 23, 2011 10:45 AM

    Interesting.
    I see a few areas where this could be useful. Elimiating specific test records from a Test DB for example.
    Some comments:
    <li>Since this is a recursive logic you must add a stop criteria. In this case I would add a max iteration variable. If that one is reached, raise an error message and let the procedure stop with that error.</li>
    <li>The when others exception at the end should be removed completely</li>
    <li>The when others exception in the middle should be replaced by a specific exception that handles the -2292 error</li>
    <li>A list of tables where no record should be deleted could be usefull. If the logic would encounter such a table, it should also stop. This would be to prevent that data from some system critical tables could be deleted per accident.</li>
    <li>The reference from the FK constraint to the PK constraint should include the table name and if possible the owner (as long as you use user_* views the owner is always the same. But we could extend this to the ALL_* views). I never met a system where different tables have the identical FK constraint names, however just make this fool proof.</li>

  • How to invoke a Web Service from PL/SQL with Complex Type as  input.

    Hello,
    I am trying to invoke a web service from PL/SQL using the UTL_DBWS package.
    The web service expects a complex type as input (defined below):
    <xs:complexType name="MsgType">
    <xs:sequence>
    <xs:element name="sender" type="xs:string"/>
    <xs:element name="messageId" type="xs:string"/>
    <xs:element name="messageType" type="xs:string"/>
    <xs:element name="dateSent" type="xs:date"/>
    </xs:sequence>
    </xs:complexType>
    How to construct input to this in PL/SQL Procedure?
    Has any body tried this before?
    An exmaple will be helpful.
    Thanks

    Dear,
    I have read your article, it is useful for me. But I cannot Apply to my case. Please kindly help me. Thank you.
    When running, the error occurs:
    1:39:31 Execution failed: ORA-20000: soapenv:Server.userException - org.xml.sax.SAXParseException: Attribute name &quot;password&quot; associated with an element type &quot;user&quot; must be followed by the &apos; = &apos; character.
    My webservice Url: http://abc.com.vn:81/axis/ABC_WS_TEST.jws?wsdl
    I make PL/SQL (similiar as your example)
    FUNCTION INVOKESENDMT
    RETURN VARCHAR2
    AS
    l_request soap_api.t_request;
    l_response soap_api.t_response;
    l_return VARCHAR2(32767);
    l_url VARCHAR2(32767);
    l_namespace VARCHAR2(32767);
    l_method VARCHAR2(32767);
    l_soap_action VARCHAR2(32767);
    l_result_name VARCHAR2(32767);
    p_zipcode VARCHAR2(160);
    BEGIN
    --p_zipcode:='''TEST'' ; ''TEST'';''84912187098'';''84912187098'';''0'';''8118'';''1'';''000001'';''ThuNghiem'';''''';
    p_zipcode:='TEST';
    -- Set proxy details if no direct net connection.
    --UTL_HTTP.set_proxy('myproxy:4480', NULL);
    --UTL_HTTP.set_persistent_conn_support(TRUE);
    -- Set proxy authentication if necessary.
    --soap_api.set_proxy_authentication(p_username => 'TEST',
    -- p_password => 'TEST');
    l_url := 'http://abc.com.vn:81/axis/ABC_WS_TEST.jws';
    l_namespace := 'xmlns="' || l_url || '"';
    l_method := 'sendMT';
    l_soap_action := l_url || '#sendMT';
    l_result_name := 'sendMTResponse';
    l_request := soap_api.new_request(p_method => l_method,
    p_namespace => l_namespace);
    soap_api.add_parameter(p_request => l_request,
    p_name => 'user password sender receiver chargedflag servicenumber messagetype messageid textcontent binarycontent',
    p_type => 'xsd:string',
    p_value => p_zipcode);
    l_response := soap_api.invoke(p_request => l_request,
    p_url => l_url,
    p_action => l_soap_action);
    l_return := soap_api.get_return_value(p_response => l_response,
    p_name => l_result_name,
    p_namespace => l_namespace);
    RETURN l_return;
    END;

Maybe you are looking for

  • Dreamweaver Flash not compatible with ASP

    I've build an ASP page with DW CS4 that has also a Flash element on it. When testing the page I've been surprised to see that IIS fires an error saying that is not alowed to have nested object tags in a page. And that's exactly what DW does when inse

  • Show email information  with diferent language correctly

    hi I have an web site that create with pl/sql server page script. This web site inclue forms that user can search from information of library books. One of facility of this program is email page that can email some of informations of books that user

  • PO no in Order

    Hi SAP Experts, Is the PO no field in The Sales order Header seen in Invoice Header ? I have checked it appears at item level but want to know does it exists at Header level too? Appreciating your quick reply. Thanks and Regards, Umesh Karane.

  • WebLogic 6.0 Compaq Tru64 Installation

    Hi all,I would like to ask a simple question about installing weblogic on Compaq tru64. I have installed WL 6.0 on Sun Solaris before. As it was explained in documentation to install WL yo need to write "sh filename.bin" on Solaris. But, on compaq it

  • LIS Extractor Missing Data

    I am using 2LIS_18_I0TASK to extract data into BW. If the record(notification) in SAP is created directly in SAP via tcode then I get all the bespoke fields as well as the SAP standard ones. If the record(notification) in SAP is created via an interf