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?

Similar Messages

  • 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

  • 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.

  • How to count the tree levels?

    Hi..
    I'm a new memeber here.. and I have a problem :S
    My problem is about counting the maximum number of a tree levels.
    the question was: write a methode that receives a root of a binary tree and returns the maximum number of levels it has.
    I wrote the following methodes:
    public void depth() {
    System.out.print(depthHelper(root));
    private int depthHelper(TreeNode node) {
    int level = 1;
    if (node == null) {
    return 0;
    level = level + depthHelper(node.rightNode);
    return level;
    The problem is that these methodes count levels from one side which is the right side or left side if I wrote "node.leftNode".
    SO, how can I count them from both sides?
    I'll be very glad if you help me.

    It's often best to start with standard recursive tree traversal algoritm,
    private dH(TreeNode node) {
       if (node != null) {
          dH(node.leftNode);
          dH(node.rightNode);
    }You must keep track of the current depth and the maximum depth so far. The current depth is easy. You just increment it each time you go deeper.
    private dH(TreeNode node, int current) {
       if (node != null) {
          dH(node.leftNode, current + 1);
          dH(node.rightNode, current + 1);
    }The maximum depth is global to the tree so you should keep it outside the method. In each recursive step you compare it to the current depth
    int maximum = 0;
    private dH(TreeNode node, int current) {
       if (node != null) {
          if (current > maximum)
             maximum = current;
          dH(node.leftNode, current + 1);
          dH(node.rightNode, current + 1);
    }Now maximum contains the maximum depth.

  • How to make the tree sibling nodes sorting  in memory per the VO default?

    Hi,
    I have a question on the uncommitted tree nodes sorting. The tree was built using the same VO with the view link to itself (parent/child relation). I have defined a default sorting on my VO. Now if I insert a node to the tree, the sibling nodes may not sort correctly if it is not committed. I tried to insert it to the RowsetIterator at the right position, it seems OK. but when you right click or something that make the tree to refresh, the order will mess up. If I do an auto save after each action, everything looks OK. But the fusion pattern is to do a global save, I have to manipulate the tree with the uncommitted data. I know I can set the view object's SQL mode to do the in-memory sorting. But not sure if it works on the tree structure, because it is not a single RowsetIteroator.. Can someone give an advice? Many thanks.
    Edited by: user736572 on Jan 20, 2012 2:48 PM

    Thanks Sudipto for trying to help. I did try that, and as I mentioned in the previous posting, it doesn't work for the tree nodes (multiple RowSetIterator). the following is my code, where the treeVO is the vo instance for the firstLevel tree nodes and it has view link to its children. I am not sure how to sort all children for each level. Even for the first level where I did the explicit sorting in memory, it still not sorting at all.
    treeVO.setSortBy("code");
    treeVO.setQueryMode(ViewObject.QUERY_MODE_SCAN_ENTITY_ROWS|ViewObject..QUERY_MODE_SCAN_DATABASE_TABLES);
    treeVO.executeQuery();

  • How to get the tree index of a child node

    Hi, I am loading a tree object from an XML source file (via
    an XMLListCollection)
    I can find the children on the currently selected node, like:
    var children:XMLList =
    XMLList(myTree.selectedItem).children();
    for(var i:Number=0; i < children.length(); i++) {
    trace("Child Found: " + children
    .@caption);
    But how can I determine the tree index for each of the
    children? I would like to be able to grab and save the tree index
    for each child, so that I can later just to do
    "myTree.selectedIndex = (saved child index) (based on some form
    action the user performs). I can't find any method of determining
    what the tree index for a child is, other than walking down the
    tree from the parent node and counting the number of nodes till I
    hit each child. Is there a simple method?

    Tree is hierarchical, index is linear. I have never seen
    anyone successfully use selectedIndex with Tree.
    You best bet is to put an id on each node and use e4x
    expression to find that node when you want.
    Tracy

  • Displayed DOM on an tree, then how to modify the tree

    Hi,
    This my first time here.
    I have DOM object parsed from xml. I displayed it on a tree using following 2 classes. My question is how do I reload the treeModelAdapter when I update/insert the tree node? How do I implement valueForPathChanged(...) method? My tree didn't updated using the method.
    Note the methods in DefaultTreeModel do not work here.
    public class DomToTreeModelAdapter implements TreeModel{
    Element element;
    public DomToTreeModelAdapter(Element elem) {
    element = elem;
    public Object getRoot() {
    return new AdapterNode(element);
    public void valueForPathChanged(TreePath path, Object newValue) {
    AdapterNode adapter = new AdapterNode(element);
    Object currentNode = path.getLastPathComponent();
    Object parentNode = path.getPathComponent(path.getPathCount()-2);
    int[] index = {getIndexOfChild(parentNode, currentNode)};
    Object[] children = {(Object)newValue};
    TreeModelEvent ev = new TreeModelEvent(adapter, path, index, children);
    fireTreeNodesChanged( ev);
    private Vector listenerList = new Vector();
    public void addTreeModelListener( TreeModelListener listener ) {
    if ( listener != null && ! listenerList.contains( listener ) ) {
    listenerList.addElement( listener );
    public void removeTreeModelListener( TreeModelListener listener ) {
    if ( listener != null ) {
    listenerList.removeElement( listener );
    public void fireTreeNodesChanged( TreeModelEvent e ) {
    Enumeration listeners = listenerList.elements();
    while ( listeners.hasMoreElements() ) {
    TreeModelListener listener = (TreeModelListener) listeners.nextElement();
    listener.treeNodesChanged( e );
    public class AdapterNode {
    Node domNode;
    public AdapterNode(Node node) { 
    domNode = node;
    public String toString() { ...
    public AdapterNode child(int searchIndex) {
    org.w3c.dom.Node node = domNode.getChildNodes().item(searchIndex);
    int elementNodeIndex = 0;
    for (int i=0; i<domNode.getChildNodes().getLength(); i++) {
    node = domNode.getChildNodes().item(i);
    if (node.getNodeType() == ELEMENT_TYPE )
    && elementNodeIndex++ == searchIndex) {
    break;
    return new AdapterNode(node);
    public int index(AdapterNode child) {
    int count = childCount();
    for (int i=0; i<count; i++) {
    AdapterNode n = this.child(i);
    if (child.toString().equalsIgnoreCase(n.toString())) { return i; }
    return -1; // Should never get here.
    I also added listener class:
    public class DomTreeModelListener implements TreeModelListener {
         Element element;
         public DomTreeModelListener(Element elem){
              element = elem;
         public void treeNodesChanged(TreeModelEvent e) {
              //DefaultMutableTreeNode node;
    Object node = e.getTreePath().getLastPathComponent();
    System.out.println("node: " + node);
    try {
    int index = e.getChildIndices()[0];
    System.out.println("index: " + index);
    //node = node.getChildAt(index);
    node = new DomToTreeModelAdapter(element).getChild(node, index);
    } catch (NullPointerException exc) {}
    What is the problem?
    Thank you in advance for any help.

    I ment give us a runnable code that demenstrates your problem, try and duplicate it... Dont post use a 5000line class, just one that shows the problem,
    ie create a new class that just does what your one is supose to with out all the bits and pieces, if if works then work from there, else post that code.
    ps did you also read the code formating tags

  • How to populate the Tree having Directories only like Explorer

    Hello,
    Can u guys tell me how to populate the File Structure Tree which is having directories only like Explorer
    Thanx in advance !!
    Vijay Gupta

    On key-exeqry you have to program.  Delete all other trigger codings for checking your condition.
    It dint work on key-exeqry.
    I tried key-exeqry on form trigger, block (enqacmdtl) and also on field(:enqacmdtl.enqno) , but none of them worked.
    It did not display the message.
    I have a 'PUSH-BUTTON:EXEC_QUERY.
    For EXEC_QUERY, Trigger : WHEN_BUTTON_PRESSED;
    I added the following code:
    if to_number(substr(:enqacmdtl.enqno,1,4))<to_number(to_char(add_months(sysdate,-12),'YYYY')) then
         message('The Rating is not present for the present year and the previous year');message(' ',no_acknowledge);
         raise form_trigger_failure;
    else
         execute_query;
    end if;
    It is working fine and the message is being displayed.
    But again I have a new problem and that is;
    On the field :enqacmdtl.enqno, when i enter the '2013%' and press 'EXEC_QUERY', it works fine.
    but when i enter '2006%' and press 'EXEC_QUERY', it shows the following error
    FRM-50016: Legal characters are 0-9 - +E. It does not display the message also.
    but when i enter the complete number, '2006580002', then it works fine , that is it displays the message (The Rating is not present for the present year and the previous year).
    The problem is because of '%', only when i put in the restricted data (which does not satisfy where condition).
    How do i solve this?
    Thank You Priyasagi.

  • Syncing iPod to Selected Playlists: How to collapse the tree

    My iTunes library is much larger than my 60GB iPod, so I have two ways to pare things down when I download to the pod.
    1) I can uncheck things in playlists that I don't wish to load on my iPod. This is what I do.
    2) I can check the "Selected Playlists" button and then check the playlists I wish to download. I'd like to do this, but it's a little hard to get around a problem:
    Whenever I connect my iPod and go to the "Music" tab that controls how I download, my "tree" of playlists is always fully expanded (I have folders within folder). Of course I can manually collapse the tree, but this operation doesn't appear to be "sticky". As soon as I apply changes, or simply reconnect the iPod, there's the tree fully expanded again. It's a large tree and this is rather a large pain.
    So does anyone know how I can collapse the tree (or pieces of the tree) and have it stick? Many thanks.

    You might provide feedback to Apple regarding this issue, so they know you care.
    I too, would assume that the state of the "tree" should be remembered, or at least, it should be in the same state than in the sidebar when you connect you iPod.
    http://www.apple.com/feedback/itunesapp.html
    Frédéric

  • How to limit the Tree's level

    Hi all,
    I have a tree with 10 levels, But I want it just display from level 1 to level 4, The node bigger than level4 will not be displayed on the tree. How can I implement this issue? Thanks a lot!
    Regards,
    Peter

    JNI is java native interface. It let us allow platform dependent code in c / c++ and we can use it them in java.
    JNI should be used only when you need to do some thing faster in native machine language. You problem is too trivial to use JNI. So better stick to what sun people have done..
    for more info : http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html

  • How to view the sapscript result without directing to Printer

    Hi All,
    I am new to ABAP. can any one tell me how to view the sapscript output without redirecting to the printer from an abap program.
    Help would be appriciated.
    Thanks,
    hima

    There are several ways you can view the output of the SAPscript, without redirecting it to the printer.
    1. You can directly view the output  using Menu --> Utilities -->  Printing Test --> give the default printer as LP01  and click Print Preview button, that should give you the print preview of the SAP Script.
    2. You can execute the the driver program, if it is a custom program (Z program)  then execute the program, it will give you an option of selecting printer,, give the printer as LP01 and select print preview.
    lets say you are trying to view the purchase order "Zmedruck", the driver program for the same can be found using the transaction code NACE. or else you can execute the transaction code ME23N, There you will find a button called "Print Preview"  Click that to preview your SAP Script. Menu --> GoTo --> Print Preview.
    Similarly you will find options to view your sap script in almost all the standard transactions where you are using your SAP Script.
    If you need further information,, give me a mail at [email protected]
    if found useful, don't forget to reward points.
    Thanks-
    Shrikant

  • How to save the tree hierarchy into an excel

    Is there any untility avaliable in Application express to save the tree hierarchy into an excel, when shown in a page.

    Using this example, you may export any query:
    http://spendolini.blogspot.com/2006/04/custom-export-to-csv.html
    Denes Kubicek

  • How can traverse the  xpath attribute name having namespace?

    tell application "Adobe InDesign CS5"
        set Xpath to {"//*/ext-link[@xlink:href !='']"}
        set myXPath to {Xpath}
        set myRuleProcessor to make XML rule processor with properties {rule paths:Xpath}
        set myRootXMLElement to XML element 1 of active document
        tell myRuleProcessor
            set myMatchData to start processing rule set initial element myRootXMLElement
            repeat while myMatchData is not equal to nothing
                set myParentElement to get element of myMatchData
                select myParentElement
                set myMatchData to find next match
            end repeat
        end tell
    end tell
    -- error occur........

    Here's an idea. Have your error page (in the hidden frame), look something like this:
    <%
      String strErrorMessage = ... // get your error message text here
    %>
    <html>
    <head>
      <script language="JavaScript">
        parent.mainframe.location = "ErrorPage.jsp";
      </script>
    </head>
    </html>So the error page loads in the hidden frame, which then extracts the error information from the exception object. Then, using javascript, the hidden frame tells the main frame (using window references) to reload to the desired page. The only issue is how to get the error message text to the new page since your exception object is lost. You can store it as a session variable, and then pass the id of the message in the url to the new page, or you could just pass the text in the url itself.
    I hope that gives you some ideas!
    Michael

  • How to traverse the XML tree.

    hi ,
    i would like to know if there is a sample code snippet
    showing how to walk through the Document object tree
    generated by the DOM parser for a given XML input.
    Thanks.
    Sandeep.
    null

    sandeep (guest) wrote:
    : hi,
    : can you please tell as to where is the selectNodes() method
    : defined. I could not locate it.
    : Thanks.
    : Sandeep.
    : Oracle XML Team wrote:
    : : Sandeep (guest) wrote:
    : : : hi ,
    : : : i would like to know if there is a sample code snippet
    : : : showing how to walk through the Document object tree
    : : : generated by the DOM parser for a given XML input.
    : : : Thanks.
    : : : Sandeep.
    : : Take a look at the selectNodes() method. It takes XPath
    syntax
    : : to navigate through the XML document.
    : : Oracle XML Team
    : : http://technet.oracle.com
    : : Oracle Technology Network
    selectNodes() is part of oracle.xml.parser.v2.XMLNode. You can
    find any method by opening AllNames.html in the doc directory.
    Oracle XML Team
    http://technet.oracle.com
    Oracle Technology Network
    null

  • How to print the content in Reverse which is read from the file

    i have written a program to display the content of the file using files concept. now the task is how to display it in reverse order i.e from last to first which is read from the file.

    If it will all fit in memory read the file as you are doing now appending everything into a StringBuilder. Then use the reverse() method of that class to obtain your output.
    http://java.sun.com/javase/6/docs/api/java/lang/StringBuilder.html#reverse()

Maybe you are looking for

  • Help me to make this

    hi for all, i need a help to put an image and make a JFrame for ChatLogin similar to yahoo messenger chat login frame, my problem is i don't know how to arrange the instruction and how to make the image named "Face.jpg" in the upper position like kee

  • Can I share my iTune library on both Mac/Windows on my new MacBook Pro

    I just ordered a new MBP. I have 15GB iTune library on my old Mac. I'm planning to install Windows Vista and using BootCamp or fusion to use both Mac and Windows on MBP. I will use only Windows during work hours and will use Mac when I get back home.

  • How can I expand text fields in my PDF file which I built in Forms Central?

    I'm working in Windows 7 and just created my first form in Forms Central. I have many text fields that I intended for the end user to be able to type as much information in them as necessary. I selected the "multiple lines of text" setting for each o

  • Convert internal HD from iMac g5 to external HD for Powermac G5?

    I have an iMac G5 (PPC) that apparently has a failed motherboard. I don't want to fix it. Instead I want to remove the HD and convert it to an external HD that I can access on a Powermac G5 (PPC) via usb, firewire, or other cable that fits the Powerm

  • Best way to write readable code?

    So I'm waist deep in building my GUI by hand and it occurs to me that I'm probably not doing this the best way possible. What I have now is listed below and I was thinking that other possibilities would be to write other methods like initMainFrame()