Hierarchical queries for table of account
HelloW to allI have a Table that's graphic account
The column of this table is
Acc_id and Acc_name
I insert data into this table of account
Insert into the COA
values
* (01, 'ASSETS'); *
values
* (01001, 'active'); *
values
* (01002, "fixed assets"); *
values
* (010010001, 'banks'); *
values
* (010010002, "cash"); *
values
* (01001000100001, 'Metrol politan Bank'); *
values
* (01001000100002, 'Royal Bank'); *
values
* (01001000100003, 'stander charted Bank'); *
values
* (01001000200001, 'body'); *
values
* ('01001000200002, Patty Cash"); *
This is my case, now I need to create a hierarchical tree
That looks like this
* 01 - active *.
-010001 active+.
Bank-010010001+.
Metrol politan Bank---01001000100001+.
Royal - 01001000100002 Bank+.
---01001000100003 stander charted Bank+.
---010010002 cash+.
-01001000200001 money in hand+.
01001000200002 Patty Cash+.
Capital - 010002+.
---010020001 active machines.
---01002000100001 needle Machine+.
Machine GGT - 01002000100002+.
-010020002 computer active+.
-01002000200001 Server computer+.
-01002000200002 other computer+.
Hope you guys understand that I need the hierarchical query to do this kind of tree
Concerning
Therese
Like this?
SQL> select
2 lpad('-',(level-1)*4,'-')|| acc_id ||
3 ' ' || acc_name as tree
4 from coa
5 connect by prior
6 acc_id = rtrim(substr(acc_id,1,instr(acc_id,'0',-1)),'0')
7 start with rtrim(substr(acc_id,1,instr(acc_id,'0',-1)),'0') is null
8 ;
TREE
------------------------------------------------------------
01 ASSETS
----01001 Current Assets
--------010010001 Banks
------------01001000100001 Metrol Politan Bank
------------01001000100002 Royal Bank
------------01001000100003 Stander Charted Bank
--------010010002 Cash
------------01001000200001 Cash in Hand
------------01001000200002 Patty Cash
----01002 Fixed Assets
10 rows selected.
Best regards
Maxim
Tags: Database
Similar Questions
-
Hierarchical queries for subnets
I need to write a hierarchical query for quite a number of (contiguous groups of IP addresses) IP subnets. What I'm hoping to do, is let the database do the bulk of the work here and I will not need to write code to do this. I'll do that if I have to but I would really rather not.
General information may be in order for those who do not know subnets. IP subnets have unique characteristics, based on network management standards (caveat: I'm not a guru/subnet on the network, but I know enough to be dangerous). The first thing to know is that a subnet is a contiguous block of IP addresses that help define the IP network protocol. Another thing is that an IP address can be converted to a binary or decimal/numeric value. This is useful because it can take us out of the sphere of analysis of strings and comparing a group of text values, which will eventually be converted to numbers in order to make meaningful comparisons anyway.
The result is that subnets can be defined by digital upper and lower limits. And the trick here is that some of these blocks of IP addresses live in the other blocks. Look at the data below and I'll explain if you need. In addition, the network address is the lower limit of the subnet and dissemination is the upper limit. This is a create table and examples of data from my dataset where you can see the IP addresses and name of each subnet and numeric limits for each subnet.
CREATE TABLE "SUBNET_DECIMAL_VALS" ( "SUBNET" VARCHAR2(4000 BYTE), "CIDR_BLOCK" VARCHAR2(30 BYTE), "NETWORK" VARCHAR2(4000 BYTE), "BROADCAST" VARCHAR2(4000 BYTE), "NETWORK_DEC" NUMBER, "BROADCAST_DEC" NUMBER ) ;
Insert into SUBNET_DECIMAL_VALS (SUBNET,CIDR_BLOCK,NETWORK,BROADCAST,NETWORK_DEC,BROADCAST_DEC) values ('128.110.0.0/20','/20','128.110.0.0','128.110.15.255',2154692608,2154696703); Insert into SUBNET_DECIMAL_VALS (SUBNET,CIDR_BLOCK,NETWORK,BROADCAST,NETWORK_DEC,BROADCAST_DEC) values ('128.110.1.0/24','/24','128.110.1.0','128.110.1.255',2154692864,2154693119); Insert into SUBNET_DECIMAL_VALS (SUBNET,CIDR_BLOCK,NETWORK,BROADCAST,NETWORK_DEC,BROADCAST_DEC) values ('128.110.4.0/22','/22','128.110.4.0','128.110.7.255',2154693632,2154694655); Insert into SUBNET_DECIMAL_VALS (SUBNET,CIDR_BLOCK,NETWORK,BROADCAST,NETWORK_DEC,BROADCAST_DEC) values ('128.110.8.0/22','/22','128.110.8.0','128.110.11.255',2154694656,2154695679); Insert into SUBNET_DECIMAL_VALS (SUBNET,CIDR_BLOCK,NETWORK,BROADCAST,NETWORK_DEC,BROADCAST_DEC) values ('128.110.12.0/22','/22','128.110.12.0','128.110.15.255',2154695680,2154696703); Insert into SUBNET_DECIMAL_VALS (SUBNET,CIDR_BLOCK,NETWORK,BROADCAST,NETWORK_DEC,BROADCAST_DEC) values ('128.110.16.0/21','/21','128.110.16.0','128.110.23.255',2154696704,2154698751); Insert into SUBNET_DECIMAL_VALS (SUBNET,CIDR_BLOCK,NETWORK,BROADCAST,NETWORK_DEC,BROADCAST_DEC) values ('128.110.16.0/22','/22','128.110.16.0','128.110.19.255',2154696704,2154697727); Insert into SUBNET_DECIMAL_VALS (SUBNET,CIDR_BLOCK,NETWORK,BROADCAST,NETWORK_DEC,BROADCAST_DEC) values ('128.110.20.0/22','/22','128.110.20.0','128.110.23.255',2154697728,2154698751); Insert into SUBNET_DECIMAL_VALS (SUBNET,CIDR_BLOCK,NETWORK,BROADCAST,NETWORK_DEC,BROADCAST_DEC) values ('128.110.24.0/22','/22','128.110.24.0','128.110.27.255',2154698752,2154699775); Insert into SUBNET_DECIMAL_VALS (SUBNET,CIDR_BLOCK,NETWORK,BROADCAST,NETWORK_DEC,BROADCAST_DEC) values ('128.110.28.0/22','/22','128.110.28.0','128.110.31.255',2154699776,2154700799); Insert into SUBNET_DECIMAL_VALS (SUBNET,CIDR_BLOCK,NETWORK,BROADCAST,NETWORK_DEC,BROADCAST_DEC) values ('128.110.28.0/24','/24','128.110.28.0','128.110.28.255',2154699776,2154700031); Insert into SUBNET_DECIMAL_VALS (SUBNET,CIDR_BLOCK,NETWORK,BROADCAST,NETWORK_DEC,BROADCAST_DEC) values ('128.110.29.0/24','/24','128.110.29.0','128.110.29.255',2154700032,2154700287); Insert into SUBNET_DECIMAL_VALS (SUBNET,CIDR_BLOCK,NETWORK,BROADCAST,NETWORK_DEC,BROADCAST_DEC) values ('128.110.30.0/24','/24','128.110.30.0','128.110.30.255',2154700288,2154700543); Insert into SUBNET_DECIMAL_VALS (SUBNET,CIDR_BLOCK,NETWORK,BROADCAST,NETWORK_DEC,BROADCAST_DEC) values ('128.110.31.0/24','/24','128.110.31.0','128.110.31.255',2154700544,2154700799);
SELECT * FROM SUBNET_DECIMAL_VALS subnet cidr network broadcast network_dec broadcast_dec 128.110.0.0/20 /20 128.110.0.0 128.110.15.255 2154692608 2154696703 128.110.1.0/24 /24 128.110.1.0 128.110.1.255 2154692864 2154693119 128.110.4.0/22 /22 128.110.4.0 128.110.7.255 2154693632 2154694655 128.110.8.0/22 /22 128.110.8.0 128.110.11.255 2154694656 2154695679 128.110.12.0/22 /22 128.110.12.0 128.110.15.255 2154695680 2154696703 128.110.16.0/21 /21 128.110.16.0 128.110.23.255 2154696704 2154698751 128.110.16.0/22 /22 128.110.16.0 128.110.19.255 2154696704 2154697727 128.110.20.0/22 /22 128.110.20.0 128.110.23.255 2154697728 2154698751 128.110.24.0/22 /22 128.110.24.0 128.110.27.255 2154698752 2154699775 128.110.28.0/22 /22 128.110.28.0 128.110.31.255 2154699776 2154700799 128.110.28.0/24 /24 128.110.28.0 128.110.28.255 2154699776 2154700031 128.110.29.0/24 /24 128.110.29.0 128.110.29.255 2154700032 2154700287 128.110.30.0/24 /24 128.110.30.0 128.110.30.255 2154700288 2154700543 128.110.31.0/24 /24 128.110.31.0 128.110.31.255 2154700544 2154700799
What I tried to do is a hierarchical query traditional and used more than and less than the comparisons in the where clause. I'm trying to find the limits of subnet (top and bottom numbers) that match among other numerical limits. This is an example, and it gives me the results I need.
select level, subnet, cidr_block cidr, network, broadcast, network_dec, broadcast_dec from poc_subnet_decimal_vals connect by nocycle prior network_dec > network_dec and broadcast_dec < broadcast_dec
Do I have to create from this, it is something like this:
Level Subnet CIDR Network Broadcast Network_Dec Broacast_Dec 1 128.110.0.0/20 /20 128.110.0.0 128.110.15.255 2154692608 2154696703 2 128.110.1.0/24 /24 128.110.1.0 128.110.1.255 2154692864 2154693119 2 128.110.4.0/22 /22 128.110.4.0 128.110.7.255 2154693632 2154694655 2 128.110.8.0/22 /22 128.110.8.0 128.110.11.255 2154694656 2154695679 2 128.110.12.0/22 /22 128.110.12.0 128.110.15.255 2154695680 2154696703 1 128.110.16.0/21 /21 128.110.16.0 128.110.23.255 2154696704 2154698751 2 128.110.16.0/22 /22 128.110.16.0 128.110.19.255 2154696704 2154697727 2 128.110.20.0/22 /22 128.110.20.0 128.110.23.255 2154697728 2154698751 2 128.110.24.0/22 /22 128.110.24.0 128.110.27.255 2154698752 2154699775 2 128.110.28.0/22 /22 128.110.28.0 128.110.31.255 2154699776 2154700799 3 128.110.28.0/24 /24 128.110.28.0 128.110.28.255 2154699776 2154700031 3 128.110.29.0/24 /24 128.110.29.0 128.110.29.255 2154700032 2154700287 3 128.110.30.0/24 /24 128.110.30.0 128.110.30.255 2154700288 2154700543 3 128.110.31.0/24 /24 128.110.31.0 128.110.31.255 2154700544 2154700799
Once, I get a hierarchical query of good work I can do the rest of the formatting with the values of the path and CYCLE but I'm not able to get a basic querying work. Does anyone have an idea of how to go on this subject using SQL only? I can write a PL/SQL procedure to add an ID of parent to each row, and then I know that I can create a hierarchical query from that but I was trying to avoid this method if possible.
Hello
Earl Lewis wrote:
I need to write a hierarchical query for quite a number of (contiguous groups of IP addresses) IP subnets. What I'm hoping to do, is let the database do the bulk of the work here and I will not need to write code to do this. I'll do that if I have to but I would really rather not.
General information may be in order for those who do not know subnets. IP subnets have unique characteristics, based on network management standards (caveat: I'm not a guru/subnet on the network, but I know enough to be dangerous). The first thing to know is that a subnet is a contiguous block of IP addresses that help define the IP network protocol. Another thing is that an IP address can be converted to a binary or decimal/numeric value. This is useful because it can take us out of the sphere of analysis of strings and comparing a group of text values, which will eventually be converted to numbers in order to make meaningful comparisons anyway.
The result is that subnets can be defined by digital upper and lower limits. And the trick here is that some of these blocks of IP addresses live in the other blocks. Look at the data below and I'll explain if you need. In addition, the network address is the lower limit of the subnet and dissemination is the upper limit. This is a create table and examples of data from my dataset where you can see the IP addresses and name of each subnet and numeric limits for each subnet.
- CREATE TABLE 'SUBNET_DECIMAL_VALS '.
- (
- VARCHAR2 (4000 BYTE) "SUBNET."
- VARCHAR2 (30 BYTE) "CIDR_BLOCK."
- VARCHAR2 (4000 BYTE) 'NETWORK ',.
- "BROADCASTING" VARCHAR2 (4000 BYTE),
- NUMBER OF "NETWORK_DEC."
- NUMBER OF 'BROADCAST_DEC '.
- ) ;
- Insert into SUBNET_DECIMAL_VALS (subnet, CIDR_BLOCK, NETWORK, BROADCAST, NETWORK_DEC, BROADCAST_DEC) values ('128.110.0.0/20','/20','128.110.0.0','128.110.15.255',2154692608,2154696703);
- Insert into SUBNET_DECIMAL_VALS (subnet, CIDR_BLOCK, NETWORK, BROADCAST, NETWORK_DEC, BROADCAST_DEC) values ('128.110.1.0/24','/24','128.110.1.0','128.110.1.255',2154692864,2154693119);
- Insert into SUBNET_DECIMAL_VALS (subnet, CIDR_BLOCK, NETWORK, BROADCAST, NETWORK_DEC, BROADCAST_DEC) values ('128.110.4.0/22','/22','128.110.4.0','128.110.7.255',2154693632,2154694655);
- Insert into SUBNET_DECIMAL_VALS (subnet, CIDR_BLOCK, NETWORK, BROADCAST, NETWORK_DEC, BROADCAST_DEC) values ('128.110.8.0/22','/22','128.110.8.0','128.110.11.255',2154694656,2154695679);
- Insert into SUBNET_DECIMAL_VALS (subnet, CIDR_BLOCK, NETWORK, BROADCAST, NETWORK_DEC, BROADCAST_DEC) values ('128.110.12.0/22','/22','128.110.12.0','128.110.15.255',2154695680,2154696703);
- Insert into SUBNET_DECIMAL_VALS (subnet, CIDR_BLOCK, NETWORK, BROADCAST, NETWORK_DEC, BROADCAST_DEC) values ('128.110.16.0/21','/21','128.110.16.0','128.110.23.255',2154696704,2154698751);
- Insert into SUBNET_DECIMAL_VALS (subnet, CIDR_BLOCK, NETWORK, BROADCAST, NETWORK_DEC, BROADCAST_DEC) values ('128.110.16.0/22','/22','128.110.16.0','128.110.19.255',2154696704,2154697727);
- Insert into SUBNET_DECIMAL_VALS (subnet, CIDR_BLOCK, NETWORK, BROADCAST, NETWORK_DEC, BROADCAST_DEC) values ('128.110.20.0/22','/22','128.110.20.0','128.110.23.255',2154697728,2154698751);
- Insert into SUBNET_DECIMAL_VALS (subnet, CIDR_BLOCK, NETWORK, BROADCAST, NETWORK_DEC, BROADCAST_DEC) values ('128.110.24.0/22','/22','128.110.24.0','128.110.27.255',2154698752,2154699775);
- Insert into SUBNET_DECIMAL_VALS (subnet, CIDR_BLOCK, NETWORK, BROADCAST, NETWORK_DEC, BROADCAST_DEC) values ('128.110.28.0/22','/22','128.110.28.0','128.110.31.255',2154699776,2154700799);
- Insert into SUBNET_DECIMAL_VALS (subnet, CIDR_BLOCK, NETWORK, BROADCAST, NETWORK_DEC, BROADCAST_DEC) values ('128.110.28.0/24','/24','128.110.28.0','128.110.28.255',2154699776,2154700031);
- Insert into SUBNET_DECIMAL_VALS (subnet, CIDR_BLOCK, NETWORK, BROADCAST, NETWORK_DEC, BROADCAST_DEC) values ('128.110.29.0/24','/24','128.110.29.0','128.110.29.255',2154700032,2154700287);
- Insert into SUBNET_DECIMAL_VALS (subnet, CIDR_BLOCK, NETWORK, BROADCAST, NETWORK_DEC, BROADCAST_DEC) values ('128.110.30.0/24','/24','128.110.30.0','128.110.30.255',2154700288,2154700543);
- Insert into SUBNET_DECIMAL_VALS (subnet, CIDR_BLOCK, NETWORK, BROADCAST, NETWORK_DEC, BROADCAST_DEC) values ('128.110.31.0/24','/24','128.110.31.0','128.110.31.255',2154700544,2154700799);
- SELECT * FROM SUBNET_DECIMAL_VALS
- subnet cidr network network_dec broadcast_dec broadcast
- 128.110.0.0/20 20 128.110.0.0 128.110.15.255 2154692608 2154696703
- 128.110.1.0/24 24 128.110.1.0 128.110.1.255 2154692864 2154693119
- 22 128.110.4.0/22 128.110.4.0 128.110.7.255 2154693632 2154694655
- 22 128.110.8.0/22 128.110.8.0 128.110.11.255 2154694656 2154695679
- 22 128.110.12.0/22 128.110.12.0 128.110.15.255 2154695680 2154696703
- 128.110.16.0/21 21 128.110.16.0 128.110.23.255 2154696704 2154698751
- 22 128.110.16.0/22 128.110.16.0 128.110.19.255 2154696704 2154697727
- 22 128.110.20.0/22 128.110.20.0 128.110.23.255 2154697728 2154698751
- 22 128.110.24.0/22 128.110.24.0 128.110.27.255 2154698752 2154699775
- 22 128.110.28.0/22 128.110.28.0 128.110.31.255 2154699776 2154700799
- 128.110.28.0/24 24 128.110.28.0 128.110.28.255 2154699776 2154700031
- 128.110.29.0/24 24 128.110.29.0 128.110.29.255 2154700032 2154700287
- 128.110.30.0/24 24 128.110.30.0 128.110.30.255 2154700288 2154700543
- 128.110.31.0/24 24 128.110.31.0 128.110.31.255 2154700544 2154700799
. I'm trying to find the limits of subnet (top and bottom numbers) that match among other numerical limits. This is an example, and it gives me the results I need.What I tried to do is a hierarchical query traditional and used more than and less than the comparisons in the where clause
- Select the level, subnet, cidr_block cidr, broadcast network, network_dec, broadcast_dec
- of poc_subnet_decimal_vals
- nocycle to connect before network_dec > network_dec and broadcast_dec<>
Do I have to create from this, it is something like this:
- Level of subnet CIDR network broadcast Network_Dec Broacast_Dec
- 1 20 128.110.0.0/20 128.110.0.0 128.110.15.255 2154692608 2154696703
- 2 128.110.1.0/24 24 128.110.1.0 128.110.1.255 2154692864 2154693119
- 2 128.110.4.0/22 22 128.110.4.0 128.110.7.255 2154693632 2154694655
- 2 128.110.8.0/22 22 128.110.8.0 128.110.11.255 2154694656 2154695679
- 2 128.110.12.0/22 22 128.110.12.0 128.110.15.255 2154695680 2154696703
- 1 128.110.16.0/21 21 128.110.16.0 128.110.23.255 2154696704 2154698751
- 2 128.110.16.0/22 22 128.110.16.0 128.110.19.255 2154696704 2154697727
- 2 128.110.20.0/22 22 128.110.20.0 128.110.23.255 2154697728 2154698751
- 2 128.110.24.0/22 22 128.110.24.0 128.110.27.255 2154698752 2154699775
- 2 128.110.28.0/22 22 128.110.28.0 128.110.31.255 2154699776 2154700799
- 3 128.110.28.0/24 24 128.110.28.0 128.110.28.255 2154699776 2154700031
- 3 128.110.29.0/24 24 128.110.29.0 128.110.29.255 2154700032 2154700287
- 3 128.110.30.0/24 24 128.110.30.0 128.110.30.255 2154700288 2154700543
- 3 128.110.31.0/24 24 128.110.31.0 128.110.31.255 2154700544 2154700799
Once, I get a hierarchical query of good work I can do the rest of the formatting with the values of the path and CYCLE but I'm not able to get a basic querying work. Does anyone have an idea of how to go on this subject using SQL only? I can write a PL/SQL procedure to add an ID of parent to each row, and then I know that I can create a hierarchical query from that but I was trying to avoid this method if possible.
This is the right forum. I can see why there is only a single forum for SQL and PL/SQL, but I do not see why they suggest that there are separate forums.
I'm not sure that you understand the problem. In the ouptu (the line whose number 11) you have
- 2 128.110.28.0/22 22 128.110.28.0 128.110.31.255 2154699776 2154700799
I guess this level = 2 means that the row is a child of a few rows, but which? It was numbered line 7:
- 1 128.110.16.0/21 21 128.110.16.0 128.110.23.255 2154696704 2154698751
? This would mean that the child has a higher than its parent network_dec.
I think you want something like this:
WITH got_parent AS
(
SELECT s. *- or whatever the desired columns
, (
SELECT MIN (ss.subnet) DUNGEON (DENSE_RANK FIRST ORDER BY ss.broadcast_dec - ss.network_dec)
OF subnet_decimal_vals ss
WHERE ss.network_dec<=>=>
AND ss.broadcast_dec > = s.broadcast_dec
AND ss.subnet <> s.subnet
) As a parent
OF s subnet_decimal_vals
)
SELECT LEVEL AS lvl
subnet, cidr_block, network, broadcast, network_dec, broadcast_dec
OF got_parent
START WITH parent IS NULL
Parent = subnet PRIOR CONNECTION
;
The result is:
LVL SUBNET NETWORK BROADCAST NETWORK_DEC BROADCAST_DEC CID
--- ---------------- --- ---------------- ---------------- ----------- -------------
1 20 128.110.0.0/20 128.110.0.0 128.110.15.255 2154692608 2154696703
2 128.110.1.0/24 24 128.110.1.0 128.110.1.255 2154692864 2154693119
2 128.110.4.0/22 22 128.110.4.0 128.110.7.255 2154693632 2154694655
2 128.110.8.0/22 22 128.110.8.0 128.110.11.255 2154694656 2154695679
2 128.110.12.0/22 22 128.110.12.0 128.110.15.255 2154695680 2154696703
1 128.110.16.0/21 21 128.110.16.0 128.110.23.255 2154696704 2154698751
2 128.110.16.0/22 22 128.110.16.0 128.110.19.255 2154696704 2154697727
2 128.110.20.0/22 22 128.110.20.0 128.110.23.255 2154697728 2154698751
1 22 128.110.24.0/22 128.110.24.0 128.110.27.255 2154698752 2154699775
1 22 128.110.28.0/22 128.110.28.0 128.110.31.255 2154699776 2154700799
2 128.110.28.0/24 24 128.110.28.0 128.110.28.255 2154699776 2154700031
2 128.110.29.0/24 24 128.110.29.0 128.110.29.255 2154700032 2154700287
2 128.110.30.0/24 24 128.110.30.0 128.110.30.255 2154700288 2154700543
2 128.110.31.0/24 24 128.110.31.0 128.110.31.255 2154700544 2154700799
Close enough to what you have requested, but not exact. If this isn't what you want, explain how you can tell if a line is one ancestor of the other in the tree.
I guess that this subnet is unique. If this is not the case, the above query will have to be changed a little, but only a little.
-
Hierarchical queries - problem with condition "begins by".
Hi people
I play with the connection by and start with clause and am faced with a particular problem which I can not solve...
My data set is:
Create table dates_q (start_date date, end_date date) /
REM INSERTING into dates_q Insert into dates_q ("START_DATE","END_DATE") values (to_date('01-JAN-14','DD-MON-RR'),to_date('10-JAN-14','DD-MON-RR')); Insert into dates_q ("START_DATE","END_DATE") values (to_date('11-JAN-14','DD-MON-RR'),to_date('20-JAN-14','DD-MON-RR')); Insert into dates_q ("START_DATE","END_DATE") values (to_date('10-MAR-14','DD-MON-RR'),to_date('20-MAR-14','DD-MON-RR')); Insert into dates_q ("START_DATE","END_DATE") values (to_date('21-MAR-14','DD-MON-RR'),to_date('31-MAR-14','DD-MON-RR')); Insert into dates_q ("START_DATE","END_DATE") values (to_date('01-APR-14','DD-MON-RR'),to_date('10-APR-14','DD-MON-RR'));
Now I basically just want to get your hands on hierarchical queries and working with the syntax of various...
What I now want is, start with the date of April 1 as my start date and work backward to build my 'tree '. The condition of my tree is between two rows; my start and end dates differ from 1 day. If they do not; I don't want these records in my tree.
And using sys_connect_by_path, I want to get all the way from the root.
Thus, for example,.
SELECT a.*, sys_connect_by_path(start_date, '|'), LEVEL lvl FROM dates_q a CONNECT BY PRIOR end_date = (start_date - 1)
I get the following output
START_DATE END_DATE SYS_CONNECT_BY_PATH(START_DATE,'|') LVL 01.01.2014 10.01.2014 | 1 JANUARY 14 1 11.01.2014 20.01.2014 | 1 JANUARY 14 | JANUARY 11, 14 2 11.01.2014 20.01.2014 | JANUARY 11, 14 1 10.03.2014 20.03.2014 | MARCH 10, 14 1 21.03.2014 31.03.2014 | MARCH 10, 14. MARCH 21, 14 2 01.04.2014 10.04.2014 |10-MAR-14|21-MAR-14|01-APR-14 3 21.03.2014 31.03.2014 | MARCH 21, 14 1 01.04.2014 10.04.2014 | MARCH 21, 14. 1 APRIL 14 2 01.04.2014 10.04.2014 | 1 APRIL 14 1 But for the moment I did not have any starting point... Now comes the FUN part...
When I give the State of departure; I get a single row :-(
Example of
SELECT a.*, sys_connect_by_path(start_date, '|'), LEVEL lvl FROM dates_q a CONNECT BY PRIOR end_date = (start_date - 1) START WITH start_date = To_Date('01-apr-2014','dd-mon-yyyy');
The result is
START_DATE END_DATE SYS_CONNECT_BY_PATH(START_DATE,'|') LVL 01.04.2014 10.04.2014 | 1 APRIL 14 1 Just a line...!
I'm unable to understand this and work more and need help.
The formation of the tree works only in a 'sense' and I'm going the other way around? Don't know what it means but just something that comes to mind. :/
Thank you
K
P.S. - database is 10g R2.
Hello
Thanks for the display of the data of the sample; It is very useful.
What do you expect the result will be and why?
LEVEL = 1 contains all rows that meet the condition to START WITH. The rows that meet the condition
start_date = To_Date('01-apr-2014','dd-mon-yyyy')
in this case? Only the line you actually obtained.
LEVEL = N (where N > 1) contains all rows that meet the conditions regarding some FRONT CONNECT BY rank level = N - 1. Since the only line level = 1 to end_date = To_Date('10-apr-2014','dd-mon-yyyy'), lines satisfy the condition
End_date PRIOR = (start_date - 1).
? None. End_date PREREQUISITE is April 10, while rows with start_date April 11 would fulfill this condition, there is no line on LEVEL = 2 and the query stops there.
You would have expected this from your previous results. The line with the start_date April 1 had no children in the previous application, so there no children in any application that has the same State of CONNECT BY.
Maybe you meant the CONNECT BY condtion to be
End_date = BEFORE (start_date - 1).
-
Gites join vs hierarchical queries
Hello
Please tel me who must use a 1?
I have to get job list of the simple Manger, should I use self-join or hierarchical queries (CONNECT BY and earlier versions)?
Yours sincerelyHello
944768 wrote:
HelloPlease tel me who must use a 1?
I have to get job list of the simple Manger, should I use self-join or hierarchical queries (CONNECT BY and earlier versions)?It depends on your data and your needs.
Whenever you have a question, please post a small example of data (CREATE TABLE and INSERT statements) for all the tables involved, so people who want to help you can recreate the problem and test their ideas. Also post the results you want from this data, as well as an explanation of how you get these results from these data.
Explain, using specific examples, how you get these results from these data.
If you show what the problem using commonly available tables (suc as scott.emp, who has a hierarchy of level 4), then you do not have ot post sample data, just the results and explanations.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002}If your hierarchy consists only of 2 levels, then a self-join will be probably more effective, simpler code and easier to maintain.
If you don't know how many levels in the hierarchy, then self-join is not an option. Use CONNECT BY or, if you have Oracle 11.2, a WITH recursive clause.
If you have a fixed number of levels (or an upper limit) greater than 2, then CONNECT BY (or a WITH recursive clause) will probably be the best.
-
How to order a tree balanced with SQL hierarchical queries
by searching the forum I found this
is there a way I can order this tree in alphabetical order so that the result looks like
LEVEL INDENTED_ENAME
---------- --------------------
1 KING BED
2 BLAKE
3 ALLEN
3 JAMES
MARTIN 3
3 TURNER
WARD 3
2 CLARK
3 MILLER
2 JONES
3 FORD
4 SMITH
3 SCOTT
4 ADAMS
-the original query-
SELECT THE LEVEL
, LPAD (' ', 3 * LEVEL) | Ename AS indented_ename
FROM scott.emp
START WITH mgr IS NULL
CONNECT BY PRIOR empno = mgr
;
LEVEL INDENTED_ENAME
---------- --------------------
1 KING BED
2 JONES
3 SCOTT
4 ADAMS
3 FORD
4 SMITH
2 BLAKE
3 ALLEN
WARD 3
MARTIN 3
3 TURNER
3 JAMES
2 CLARK
3 MILLERHello
Bodin wrote:
Hi Frank, I can order it selectively depending on the level, which means that only siblings stopped at third level, but rest of the brothers and sisters remain Nations United orderedIt's actually quite difficult. You can "ORDER of brothers and SŒURS BY CASE... ', like this:
SELECT LEVEL , LPAD (' ', 3 * LEVEL) || ename AS indented_ename FROM scott.emp START WITH mgr IS NULL CONNECT BY mgr = PRIOR empno ORDER SIBLINGS BY CASE WHEN job = 'MANAGER' THEN ename ELSE NULL END ;
In this case to get desired results in table scott.emp, as the lines are LEVEL = 2 if and only if use = "MANAGER".
But if you reference LEVEL in the CASE expression (for example, if you replace ' job = 'MANAGER' ' with "2 LEVEL =" above "), then you will get the error" ORA-00976: LEVEL, PRIOR or ROWNUM not allowed here. "
The best way I can think to do exactly what you asked is to do 2 CONNECT BY queries; one just to get the LEVEL and the other for the brothers and SŒURS ORDER BY:
{code}
WITH got_lvl AS
(
SELECT LEVEL AS lvl
Bishop
empno
ename
FROM scott.emp
START WITH mgr IS NULL
CONNECT BY PRIOR empno = mgr
)
SELECT lvl
, LPAD (' ', 3 * LEVEL) | Ename AS indented_ename
OF got_lvl
START WITH mgr IS NULL
CONNECT BY PRIOR empno = mgr
BROTHERS AND SŒURS OF ORDER OF CASES
ONCE lvl = 2 THEN ename
ANOTHER NULL
END
;
{code}
Why you can't simply "Brothers and SŒURS of ORDER BY ename" at all levels? If all you care is the order of the items of LEVEL = 2, then this is probably the most effective and simplest way. It really hurt anything if nodes on levels 3, 4, 5,... are in order, too?Here's something you can do if you want to order by different unique things to different levels:
{code}
WITH got_sort_key AS
(
SELECT LEVEL AS lvl
, LPAD (' ', 3 * LEVEL) | Ename AS indented_ename
empno
SYS_CONNECT_BY_PATH (LPAD (CASE
WHEN LEVEL = 2
THEN ename
Of OTHER TO_CHAR (empno)
END
10
)
, ','
) AS sort_key
FROM scott.emp
START WITH mgr IS NULL
CONNECT BY PRIOR empno = mgr
)
SELECT lvl
indented_ename
empno
OF got_sort_key
ORDER BY sort_key
;
{code}
However, all possible values of the CASE expression must uniquely identify the node; otherwise, the output won't necessarily hierarchical order. You can assign arbitrary unique IDS to the lines (using the ROW_NUMBER analytic function, for example), but that requires another subquery and is also complex and perhaps as ineffective as the solution above with 2 garages CONNECT. -
unnecessary SQL queries for ViewObject used in different tab
In my application, I have a table A in the first tab and table B in the second tab.
Sometimes when I work as a user with table B in the second tab, the ViewObjectA for table A is executed.
Of course this ViewObjectA execution is absolutely useless, because I work in another tab and I don't don't even see table A.
Unfortunately, the query takes a long time and it makes the application slower.
Question: why the ADF runs the query for a table that is not visible and the user accesses not?
Is it possible to prevent it?
A note on the configuration that may be linked to the problem:
The ViewObjectA has an implementation customized with debug messages (that's how I discovered the ViewObject is exectuted).
Due to the limitation of the DB, I have configured my pool ApplicationModule instances of timeout after 120 idle seconds (because the DB does not like the many connections and long-term).
I also found that after the expiry of the ApplicationModule, a new instance of ViewObjectA is created (Yes, it should according to the ViewObjectImpl API).
It seems to me that the unnecessary ViewObjectA execution happens after this new creation of instance of ViewObjectA.
Well, the execution of the query of a VO is part of the creation of a VO.
You can try to adjust it for example, you add a where clause such as 1 = clause: bindVar' and init the bindVar to 0 so that the query is performed from the user interface (see JDeveloper: obstacle to the return of the games to outline on the loading of the page of VO using the binding variable |) JDev & amp; ADF Goodies).
Timo
-
SQL queries for the date and year
Hi friends,
I have a named view - item_sales with 4 columns
Item code
Name of the element
Transaction_YYYYMM (Date stored in a format YYYYMM)
QTY_RECEIVED
QTY_SOLD
Sample data is
ITEM_CODE POINT NAME TRANSACTION_YYYMM QTY_RECD QTY_SOLD
TSHIRT 201307 3000 2000 AX
TSHIRT AX 500 2000 201308
TSHIRT 201309 1000 3000 AX
CX 201307 3000 2000 XLSHIRT
XLSHIRT CX 201308 3000 2500
CX 201309 3000 2500 XLSHIRT
END OF EACH MONTH I'LL RUN THIS QUERY TO FIND OUT THE DETAILS BELOW
1. TO FIND NOM_ELEMENT WISE - QTY_RECEIVED AND QTY_SOLD (FOR THE CURRENT MONTH - EXAMPLE SEP)
2. TO FIND NOM_ELEMENT WISE - QTY_RECEIVED AND QTY_SOLD (EXAMPLE EXERCISE OF JAN TO SEP)
OUTPUT FOR SEPTEMBER MONTH LOOK LIKE THIS
SEVEN MONTHS JAN TO SEP
ITEM_CODE NOM_ELEMENT QTY_RECEIVED QTY_RECEIVED QTY_SOLD QTY_SOLD
TSHIRT 1000, 3000, 6000, 5500 AX
CX 3000 2000 9000 7000 XLSHIRT
Pls advise me how to write queries for this
RDK
Hello
This is called a Pivot, and here's a way to do it:
WITH got_display_yyyymm AS
(
SELECT TO_CHAR (ADD_MONTHS (SYSDATE-1)
, "YYYYMM.
) AS YYYYMM
OF the double
)
SELECT i.item_code
i.item_name
SUM (CASE
WHEN i.transaction_yyyymm = d.yyyymm
THEN i.qty_received
END
) AS month_received
SUM (CASE
WHEN i.transaction_yyyymm = d.yyyymm
THEN i.qty_sold
END
) AS month_sold
SUM (CASE
WHEN SUBSTR (i.transaction_yyyymm, 1, 4)
= SUBSTR (d.yyyymm, 1, 4)
THEN i.qty_received
END
) AS year_received
SUM (CASE
WHEN SUBSTR (i.transaction_yyyymm, 1, 4)
= SUBSTR (d.yyyymm, 1, 4)
THEN i.qty_sold
END
) AS year_sold
Item_sales I have
CROSS JOIN got_display_yyyymm d
I.item_code GROUP, i.item_name
ORDER BY i.item_code, i.item_name
;
If you would care to post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data, then I could test it.
The subquery got_display_yyyymm digit which is the previous month; It is not to change anything from month to month. If you run the query in October 2013, then YYYYMM Gets the value '201309'. If you run it in January 2014, then YYYYMM will be '201312'.
As posted, it will work in Oracle 9.1 or higher. The SELECT... PIVOT function that was introduced in Oracle 11.1 would not help in this problem, so you do not miss anything using Oracle 10 in this case.
-
Reg: Prior in hierarchical queries:
Hi Experts,
A little doubt - I've been working on the requests, but it still haunts me... Hierarchical queries
One thing I am more confused about is the prior clause.
I'll try to explain my concern below.
Here, the tree yesterday gets reversed by changing the clause PRIOR to 'Manager Id' to 'Employee Id' and vice versa.
Exactly how to understand where to put FORWARD... which column?
I can get my results just double check... but I just want to know the concept. So stupid right... but do not want to take this doubt more far. ;)
Please help guys.ranit@XE11GR2>> select * from 2 emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-DEC-08 800 20 7566 NORGAARD MANAGER 7839 01-APR-07 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-07 1250 1400 30 7698 BLAKE MANAGER 7839 01-MAY-09 2850 30 7782 FOOTE MANAGER 7839 09-JUN-08 2450 10 7788 SCOTT ANALYST 7566 19-APR-87 3000 20 7839 ELLISON PRESIDENT 17-NOV-06 5000 10 7844 TURNER SALESMAN 7698 08-SEP-08 1500 0 30 7876 ADAMS CLERK 7788 18-JUN-07 1100 20 7900 JAMES CLERK 7698 03-DEC-07 950 30 7902 LOFSTROM ANALYST 7566 04-DEC-08 3000 20 7934 MILLER CLERK 7782 23-JAN-08 1300 10 12 rows selected. Elapsed: 00:00:00.04 ranit@XE11GR2>> select * from 2 emp 3 connect by empno = prior mgr 4 start with empno = 7698; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7698 BLAKE MANAGER 7839 01-MAY-09 2850 30 7839 ELLISON PRESIDENT 17-NOV-06 5000 10 Elapsed: 00:00:00.01 ranit@XE11GR2>> select * from 2 emp 3 connect by prior empno = mgr 4 start with empno = 7698; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7698 BLAKE MANAGER 7839 01-MAY-09 2850 30 7654 MARTIN SALESMAN 7698 28-SEP-07 1250 1400 30 7844 TURNER SALESMAN 7698 08-SEP-08 1500 0 30 7900 JAMES CLERK 7698 03-DEC-07 950 30 Elapsed: 00:00:00.07
Thank youOracle Database 11g Express Edition Release 11.2.0.2.0 - Production PL/SQL Release 11.2.0.2.0 - Production "CORE 11.2.0.2.0 Production" TNS for 32-bit Windows: Version 11.2.0.2.0 - Production NLSRTL Version 11.2.0.2.0 - Production
Vanessa B.I know the feeling!
START WITH gives you the first line of the result set.
CONNECT BY gets you the next row. At this point, you already have is the "before" line and the line that you get is the current line.
If the current line is supposed to be the Manager of the previous line, this means that Bishop PREREQUISITE = empno.
If the previous line is supposed to be the Manager of the current line, which means PRIOR empno = mgr.
Think AHEAD as referring to the line that you just received and "without any preconditions" as the line you want.
Another way of thinking that is to ask "what new information I receive?
If you say "Bishop PREREQUISITE = empno", you already know the Director of the previous row. New information will be the Director of the current line. As you continue, you will learn step by step who are managers.
If you say "PRIOR empno = mgr", you already know that the employee of the previous row. New information will be the new empno. So step by step, you will find the empnos.
You always ' move to before current. "Of mgr to empno" descends from the string, "empno to Bishop" goes to the top of the chain.
Published by: stew Ashton on February 16, 2013 11:57
-
How I find myself with two passwords to iCloud for the same account?
How I find myself with two passwords to iCloud for the same account?
For security reasons, I only use iCloud for Contacts and "find my iPhone".
Several months ago Apple forced me to change my password to iCloud. So I did this. In the last months, I used successfully the new password to 10 or 12 times when asked without problem.
However, I received a notification of a software update for my Apple Watch. I did the update without problem. However, after completing the update my iPhone asked me to connect to my iCloud account. When I did this, she rejected my password. I made 4 attempts typing very slowly and with care for you sure I did it right.
Then, operating under a hunch, I decided to enter my old password to iCloud. It worked? I'm confused about this, any ideas would be appreciated.
I had a similar problem last year. I had to call Apple. Contact is a bottom of this page.
-
I did an extra e-mail for my partner account. We read emails in our two accounts when I am connected, but she can't read his email, if it is logged in and of itself. How can we make accessible account directly for her?
deleted
-
How can I get the tabs colorful to use different distinct colors for 2 gmail accounts?
Under Firefox 29.0.1 iMac OSX 10.9.3. I have multiple Google accounts: 2 1 Google Calendar and gmail accounts. Colorful tabs add-on will allow me to choose a color for a gmail account, but it also uses this same color for the other gmail account. How can I get the different colors on 2 gmail accounts?
In addition, colorful tabs is also the same for my homepage (google.com) and my google calendar. How can I get different colors on these 2?
Personally, I use 'Fabtabs' for my mozilla FireFox.
https://addons.Mozilla.org/en-us/Firefox/addon/FabTabs/
This add-on has problems like that when I use it.
-
How long should you wait for your apple account unlock
How long should you wait for your apple account unlock?
of > If your identifier Apple is locked - Apple supports
...
When you see one of these alerts, you can go to iforgot.apple.com to unlock your account with your existing password or reset your password. After multiple unsuccessful attempts to unlock your account, your identifier Apple will remain locked and you can try again the next day.
...
-
my calendar is stuck on "mobile timetables for the server account" after mountain lion update
my calendar is stuck on "mobile timetables for the server account" after mountain lion update
HOPE TO HEAR SOME ADVICE PLEASE :)
1) go in your user library folder (~ / library). Hold down the option/alt key while accessing the menu Finder go.
2) go to the calendar folder
(3) delete all files that say "cache" (replace the your desktop in the case where you want to move them at least)
(4) always in the user library folder, go to the Preferences folder
(5) delete the com.apple.calendar.plist (on the desktop again)
(6) restart your computer
-
My computer is Toshiba A665 w/Intel core I7 and Windows 7 installed. When I run the installer of firefox 10, he asked for the user account ID and password. I entered the name of the computer that is mine with admin enter the account and a correct password. Installation of Firefox to quit smoking. No screen / another reply?
Hello
Please try a right click on the downloaded file and select run as administrator.
-
Firefox remember my password for my email account. How can I cancel it?
Firefox remember my password for my email account. How to cancel it?
To remove a password stored by Firefox, go here:
Orange button or Firefox menu Tools > Options > Security
Click on the "Saved passwords" button to view/delete saved passwords.
You may also need to delete a cookie for your site from email, but first try the above dialog box.
Maybe you are looking for
-
Today, Safari on my iMac went nuts. In the search bar, there are two ' search or enter us site name ', with the other having only the magnifying glass symbol before text: I also can't ad text in the search field. This has happened before installing t
-
Laptop Pavilion g7; Computer overheats and turns off
Hello Last year, I had my laptop, a g7 Windows 8 Pavilion and it was fine for about 5 months, but after that, it began to overheat sometimes and give me the link www.hp.com/go/techcenter/startupward to help. After that he became more frequent and it
-
hoax or not do Windows phone you
I get phone calls telling me that windows downloaded updates bad - it has to be a scam - or if it is passed
-
I'm having a problem of construction of an installer in 2011SP1 of LabVIEW. It has been a while since I tried to build an installer but it used to work properly and building executables still works fine. Now when I try to compile the installer, I get
-
How can I open the system configuration
I am running windows xp (version 2002). How to find the system configuration?