Analytic Query Dense Rank Criteria

Hello folks,
I haven't had luck to figure out how to solve this problem; need someone to help me with this. I'm guessing this can't be done in a single SQL, has to be a PL / SQL logic;
Say we have an Airline system where we have flights belonging to two airlines, for example United & Continental. If someone wants to make a reservation for 10 seats, the reservation has to split equally between united & continental, in this case 5 seats should go to each airline. lets assume united has 3 flights and continental has 3 flights, and assuming flights with same routes ( unique flight numbers though),
so in this case i would need to pick 5 seats in 3 separate flights for each of United & continental. On the first iteration the diversity should be one seat per flight. So, 3 seats would be reserved on 3 separate flights for united, On the 2nd iteration 2 more seats should be reserved across those 3 flights, the only thing to consider is the seat should be on a different row from the one already selected. When reserving for continental, it has to follow the same logic as applied to united. Seat numbers selected should exactly be the same between the flights from Continental & United, we need to loop until we find a matching available seat number between the flights, If we cannot find common seat number between those flights I should error out saying request cannot be fulfilled.
Let's picture this with some test data, hopefully that makes it more clear :
AIRLINES Table:
ID
AIRLINES
1
UNITED
2
CONTINENTAL
FLIGHTS Table:
ID
ORIGIN
DESTINATION
AIRLINES
FLIGHT#
1
NYC
BOS
UNITED
100
2
CHI
LA
UNITED
101
3
DEN
ATL
UNITED
102
4
NYC
BOS
CONTINENTAL
103
5
CHI
LA
CONTINENTAL
104
6
DEN
ATL
CONTINENTAL
105
INVENTORY Table:
ID
FLIGHT#
SEAT_ROW
SEAT#
AVAILABILITY
1
100
1
A
N
2
100
1
B
Y
3
100
2
A
Y
4
100
2
B
Y
5
101
1
A
Y
6
101
1
B
N
7
101
2
A
N
8
101
2
B
Y
9
102
1
A
Y
10
102
1
B
Y
11
102
2
A
Y
12
102
2
B
Y
13
103
1
A
Y
14
103
1
B
N
15
103
2
A
N
16
103
2
B
Y
17
104
1
A
Y
18
104
1
B
Y
19
104
2
A
Y
20
104
2
B
Y
21
105
1
A
N
22
105
1
B
Y
23
105
2
A
Y
24
105
2
B
Y
With the sample data I have above, if there is a request for 10 seats,
5 seats will need to be booked over United on flights 100, 101 & 102.
5 seats will need to be booked over Continental on flights 103, 104 & 105.
On Iteration 1 >> Only 3 seats are reserved
(a) When looking for a seat availability on flight 100 (united), corresponding search needs to be done on flight 103(continental) to try and find exact seat number available on both the flights, Only Seat row 2 and Seat B satisfies this request , so the return set should be IDs ( 4, 16) from the Inventory Table.
(b) Similarly, When looking for a seat availability on flight 101 (united), corresponding search needs to be done on flight 104(continental) to try and find exact seat number available on both the flights,  the return set could be IDs ( 5, 17)  or ( 8, 20 ) from the Inventory Table.
(c) Similarly, When looking for a seat availability on flight 102 (united), corresponding search needs to be done on flight 105(continental) to try and find exact seat number available on both the flights,  the return set could be IDs ( 10, 22)  or ( 11, 23 ) or (12, 24) from the Inventory Table.
On Iteration 2 >> 2 more seats are reserved
(a) flights 100 & 103 have no more seats common seats left that satisfy our conditions.
(b) if (5, 17) were selected in the prior iteration, then (8, 20) should be the return set from Inventory table as they satisfy the condition the seats belong to two different rows.
(c) if (10, 22) or (11, 23) were selected in the prior iteration, then  (12, 24) should be the return set from the Inventory table as they satisfy the condition the seats belong to two different rows.
I would like to perform this uniform distribution in Sql or Pl/ Sql and extract the return set as part of automation. I hope the requirement here is clear enough. btw, we are using Oracle 11G R2. Let me know if you have questions,
Thanks in advance,
Chandu

Sorry for the late reply, I haven't really got a chance to test your SQL query. When I tried this morning it almost worked except for the 3rd diversity rule. I was trying to tweak your code to make it work but I hadn't had any luck. Appreciate if you could help me again
In earlier case I framed my example using Airline system, Diversity rules are still the Same. For convenient purposes I replaced with real test data.
Diversity Rules:
No.of Ports Requested := N ( which means N/ 2 should be fulfilled in each Switch & its corresponding Switch Partner within a Fabric/Partner);
Note: Odd no. requests will be rejected, system will only allow even numbered requests
Rule 1 - (a) Split request evenly between available Switches (per Fabric)
IF  (a) doesn't fully complete my request  THEN
Rule 2 - (b) Port assignment on the same Switch should happen on a different Line_NO from what has been assigned in (a)
IF  (b) did not fully complete my request THEN
Rule 3 -(c) If on the initial iteration one port from each line_No is consumed from a switch , Port assignment can repeat on the already assigned Line_No but the port should belong to different Port_group from what was initially assigned.
All the above diversity rules should take into consideration that port assignments should exactly match between Switch-Pairs (Origin - Destination) belonging to two different Fabrics ( Fabric & its Partner)
Here's some test data:
WITH PORTS_AVAIL
AS
(SELECT 'dev340h104f01' ORIGIN,'dev340h104f02' DESTINATION,'340_Fabric1' FABRIC,'340_Fabric2' FABRIC_PARTNER,'1' LINE_NO,'fc1/4' PORT_NAME,'ASIC 0' PORT_GROUP ,'20:04:00:05:1E:36:46:20' PORT_WWN FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','1','fc1/8','ASIC 0','20:08:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','1','fc1/9','ASIC 0','20:09:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','1','fc1/13','ASIC 0','20:0D:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','1','fc1/17','ASIC 1','20:81:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','1','fc1/18','ASIC 1','20:82:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','1','fc1/23','ASIC 1','20:87:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','1','fc1/24','ASIC 1','20:88:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','1','fc1/31','ASIC 1','20:8F:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/4','ASIC 0','20:14:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/6','ASIC 0','20:16:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/7','ASIC 0','20:17:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/11','ASIC 0','20:1B:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/12','ASIC 0','20:1C:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/17','ASIC 1','20:91:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/19','ASIC 1','20:93:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/25','ASIC 1','20:99:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/27','ASIC 1','20:9B:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/31','ASIC 1','20:9F:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/36','ASIC 3','2E:14:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/38','ASIC 3','2E:16:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/39','ASIC 3','2E:17:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/40','ASIC 3','2E:18:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','2','fc2/41','ASIC 3','2E:19:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','3','fc3/5','ASIC 0','20:25:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','3','fc3/8','ASIC 0','20:28:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','3','fc3/9','ASIC 0','20:29:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','3','fc3/10','ASIC 0','20:2A:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','3','fc3/11','ASIC 0','20:2B:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','3','fc3/12','ASIC 0','20:2C:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','3','fc3/13','ASIC 0','20:2D:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','3','fc3/14','ASIC 0','20:2E:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','3','fc3/18','ASIC 1','20:A2:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','3','fc3/23','ASIC 1','20:A7:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','3','fc3/30','ASIC 1','20:AE:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','3','fc3/36','ASIC 3','2E:24:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','4','fc4/4','ASIC 0','20:34:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','4','fc4/6','ASIC 0','20:36:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','4','fc4/8','ASIC 0','20:38:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','4','fc4/13','ASIC 0','20:3D:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','4','fc4/19','ASIC 1','20:B3:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','4','fc4/22','ASIC 1','20:B6:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','4','fc4/27','ASIC 1','20:BB:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','4','fc4/28','ASIC 1','20:BC:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','4','fc4/30','ASIC 1','20:BE:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','4','fc4/33','ASIC 3','2E:31:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','4','fc4/35','ASIC 3','2E:33:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/10','ASIC 0','20:4A:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/12','ASIC 0','20:4C:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/13','ASIC 0','20:4D:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/14','ASIC 0','20:4E:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/15','ASIC 0','20:4F:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/17','ASIC 1','20:C1:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/23','ASIC 1','20:C7:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/24','ASIC 1','20:C8:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/25','ASIC 1','20:C9:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/26','ASIC 1','20:CA:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/27','ASIC 1','20:CB:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/28','ASIC 1','20:CC:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/29','ASIC 1','20:CD:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/30','ASIC 1','20:CE:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/31','ASIC 1','20:CF:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/32','ASIC 3','2E:40:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/36','ASIC 3','2E:44:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/38','ASIC 3','2E:46:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/39','ASIC 3','2E:47:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','7','fc7/42','ASIC 3','2E:4A:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/6','ASIC 0','20:56:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/7','ASIC 0','20:57:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/9','ASIC 0','20:59:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/15','ASIC 0','20:5F:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/18','ASIC 1','20:D2:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/22','ASIC 1','20:D6:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/23','ASIC 1','20:D7:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/25','ASIC 1','20:D9:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/26','ASIC 1','20:DA:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/30','ASIC 1','20:DE:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/34','ASIC 3','2E:52:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/38','ASIC 3','2E:56:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/40','ASIC 3','2E:58:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/41','ASIC 3','2E:59:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/42','ASIC 3','2E:5A:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/43','ASIC 3','2E:5B:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','8','fc8/44','ASIC 3','2E:5C:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','9','fc9/5','ASIC 0','20:65:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','9','fc9/11','ASIC 0','20:6B:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','9','fc9/12','ASIC 0','20:6C:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','9','fc9/24','ASIC 1','20:E8:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','9','fc9/28','ASIC 1','20:EC:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','9','fc9/37','ASIC 3','2E:65:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','10','fc10/6','ASIC 0','20:76:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','10','fc10/11','ASIC 0','20:7B:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','10','fc10/18','ASIC 1','20:F2:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','10','fc10/27','ASIC 1','20:FB:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','10','fc10/37','ASIC 3','2E:75:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','10','fc10/38','ASIC 3','2E:76:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','10','fc10/39','ASIC 3','2E:77:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f01','dev340h104f02','340_Fabric1','340_Fabric2','10','fc10/42','ASIC 3','2E:7A:00:05:1E:36:46:20' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','1','fc1/8','ASIC 0','20:08:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','1','fc1/9','ASIC 0','20:09:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','1','fc1/17','ASIC 1','20:81:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','1','fc1/18','ASIC 1','20:82:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','1','fc1/24','ASIC 1','20:88:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','1','fc1/28','ASIC 1','20:8C:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','1','fc1/31','ASIC 1','20:8F:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/4','ASIC 0','20:14:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/11','ASIC 0','20:1B:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/12','ASIC 0','20:1C:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/17','ASIC 1','20:91:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/18','ASIC 1','20:92:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/19','ASIC 1','20:93:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/23','ASIC 1','20:97:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/25','ASIC 1','20:99:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/26','ASIC 1','20:9A:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/27','ASIC 1','20:9B:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/31','ASIC 1','20:9F:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/36','ASIC 3','2E:14:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/37','ASIC 3','2E:15:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/38','ASIC 3','2E:16:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/39','ASIC 3','2E:17:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/40','ASIC 3','2E:18:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','2','fc2/41','ASIC 3','2E:19:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','3','fc3/5','ASIC 0','20:25:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','3','fc3/8','ASIC 0','20:28:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','3','fc3/9','ASIC 0','20:29:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','3','fc3/10','ASIC 0','20:2A:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','3','fc3/11','ASIC 0','20:2B:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','3','fc3/12','ASIC 0','20:2C:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','3','fc3/13','ASIC 0','20:2D:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','3','fc3/14','ASIC 0','20:2E:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','3','fc3/18','ASIC 1','20:A2:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','3','fc3/30','ASIC 1','20:AE:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','3','fc3/36','ASIC 3','2E:24:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','4','fc4/4','ASIC 0','20:34:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','4','fc4/6','ASIC 0','20:36:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','4','fc4/8','ASIC 0','20:38:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','4','fc4/13','ASIC 0','20:3D:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','4','fc4/19','ASIC 1','20:B3:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','4','fc4/27','ASIC 1','20:BB:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','4','fc4/28','ASIC 1','20:BC:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','4','fc4/30','ASIC 1','20:BE:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','4','fc4/33','ASIC 3','2E:31:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','4','fc4/35','ASIC 3','2E:33:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/10','ASIC 0','20:4A:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/12','ASIC 0','20:4C:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/13','ASIC 0','20:4D:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/14','ASIC 0','20:4E:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/15','ASIC 0','20:4F:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/17','ASIC 1','20:C1:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/22','ASIC 1','20:C6:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/23','ASIC 1','20:C7:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/24','ASIC 1','20:C8:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/25','ASIC 1','20:C9:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/26','ASIC 1','20:CA:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/27','ASIC 1','20:CB:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/28','ASIC 1','20:CC:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/29','ASIC 1','20:CD:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/30','ASIC 1','20:CE:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/31','ASIC 1','20:CF:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/32','ASIC 3','2E:40:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/36','ASIC 3','2E:44:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/38','ASIC 3','2E:46:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/39','ASIC 3','2E:47:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','7','fc7/42','ASIC 3','2E:4A:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/5','ASIC 0','20:55:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/6','ASIC 0','20:56:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/7','ASIC 0','20:57:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/9','ASIC 0','20:59:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/15','ASIC 0','20:5F:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/18','ASIC 1','20:D2:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/25','ASIC 1','20:D9:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/26','ASIC 1','20:DA:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/30','ASIC 1','20:DE:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/34','ASIC 3','2E:52:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/38','ASIC 3','2E:56:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/40','ASIC 3','2E:58:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/41','ASIC 3','2E:59:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/42','ASIC 3','2E:5A:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/43','ASIC 3','2E:5B:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','8','fc8/44','ASIC 3','2E:5C:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','9','fc9/5','ASIC 0','20:65:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','9','fc9/11','ASIC 0','20:6B:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','9','fc9/24','ASIC 1','20:E8:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','9','fc9/37','ASIC 3','2E:65:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','10','fc10/11','ASIC 0','20:7B:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','10','fc10/18','ASIC 1','20:F2:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','10','fc10/27','ASIC 1','20:FB:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','10','fc10/37','ASIC 3','2E:75:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','10','fc10/38','ASIC 3','2E:76:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','10','fc10/39','ASIC 3','2E:77:00:05:1E:36:48:46' FROM DUAL UNION ALL
SELECT 'dev340h104f02','dev340h104f01','340_Fabric2','340_Fabric1','10','fc10/42','ASIC 3','2E:7A:00:05:1E:36:48:46' FROM DUAL
--SELECT * FROM PORTS_AVAIL
BOTH_AVAIL
     AS
(SELECT   A.ORIGIN,
                A.DESTINATION,
                TO_NUMBER(LINE_NO) LINE_NO,
                PORT_NAME,
                A.FABRIC ORG_FABRIC_NAME,
                B.FABRIC DEST_FABRIC_NAME,
                A.ORIGIN ORG_SWITCH_NAME,
                B.ORIGIN DEST_SWITCH_NAME,
                A.PORT_WWN ORG_PORT_WWN,
                B.PORT_WWN DEST_PORT_WWN,
                A.PORT_GROUP ORG_PORT_GROUP,
                B.PORT_GROUP DEST_PORT_GROUP,
                DENSE_RANK ()
                   OVER (PARTITION BY A.ORIGIN ORDER BY TO_NUMBER(LINE_NO))
                   DR_LINE_NO,
                ROW_NUMBER ()
                OVER (
                   PARTITION BY A.ORIGIN, TO_NUMBER(LINE_NO)
                   ORDER BY
                      TRIM (
                         TO_CHAR (REGEXP_SUBSTR (PORT_NAME, '[0-9]{1,3}'),
                                  '000'))
                      || TRIM (
                            TO_CHAR (
                               LTRIM (
                                  REGEXP_SUBSTR (PORT_NAME,
                                                 '(\/)[[:digit:]]{0,3}'),
                               '000')))
                   RN_PORTNAME,
                DENSE_RANK ()
                   OVER (PARTITION BY A.ORIGIN ORDER BY A.PORT_GROUP)
                   DR_PORT_GROUP
           FROM PORTS_AVAIL A JOIN PORTS_AVAIL B USING (LINE_NO, PORT_NAME)   
          WHERE 1 = 1   
                AND A.DESTINATION = B.ORIGIN
                AND A.FABRIC < B.FABRIC
--SELECT * FROM BOTH_AVAIL A
     BUY_ORDER
     AS (
SELECT A.*,
                COUNT (*)
                   OVER (ORDER BY
                            RN_PORTNAME,
                            DR_LINE_NO,
                            DR_PORT_GROUP,
                            ORG_SWITCH_NAME)
                   buy_rn,
                COUNT (*) OVER () max_possible
           FROM both_avail A              
           WHERE   (DR_LINE_NO = 1 OR DR_PORT_GROUP = 1)
SELECT
       LINE_NO "BLADE",
       PORT_NAME,
       ORG_FABRIC_NAME,
       ORG_SWITCH_NAME,
       ORG_PORT_WWN,
       DEST_FABRIC_NAME,
       DEST_SWITCH_NAME,
       DEST_PORT_WWN,
       ORG_PORT_GROUP,
       DEST_PORT_GROUP
  FROM buy_order
WHERE :seat_req / 2 BETWEEN buy_rn AND max_possible
       AND TRUNC (:seat_req / 2) = :seat_req / 2;
A total of 33 ports (per switch) can be assigned; What does the below condition do ? If I don't apply this condition I get more record set. If you could explain me the Rank_over part that would be great.
WHERE   (DR_LINE_NO = 1 OR DR_PORT_GROUP = 1)
When I run the above SQL for a request for 20 Ports, the first 8 records satisfy my diversity rules
(1) Only 1 switch-Pair combination exists (  dev340h104f01<=> dev340h104f02 ), not much there to diversify.
(2) Port assignment is distributed among the unique Line_No's for the only available Switch-Pair. Each of the first 8 ports belong to unique Line_No.
(3) Port assignment on the same line_no can happen but should belong to a different Port Group. Records (9) & (10) (highlighted in RED below) should have come from different Port_Groups ( Asic 1/2/3 not Asic 0). In this case next port (9th record) that can be made available was on Line_No 1 with port as fc1/17 which is Asic 1 & 10th record should be fc2/17 which belongs to Asic 1.
Below is the output when I run the original sql.
Blade
Port_Name
ORG_FABRIC_NAME
ORG_SWITCH_NAME
ORG_PORT_WWN
DEST_FABRIC_NAME
DEST_SWITCH_NAME
DEST_PORT_WWN
ORG_PORT_GRP
DEST_PORT_GRP
1
fc1/8
340_Fabric1
dev340h104f01
20:08:00:05:1E:36:46:20
340_Fabric2
dev340h104f02
20:08:00:05:1E:36:48:46
ASIC 0
ASIC 0
2
fc2/4
340_Fabric1
dev340h104f01
20:14:00:05:1E:36:46:20
340_Fabric2
dev340h104f02
20:14:00:05:1E:36:48:46
ASIC 0
ASIC 0
3
fc3/5
340_Fabric1
dev340h104f01
20:25:00:05:1E:36:46:20
340_Fabric2
dev340h104f02
20:25:00:05:1E:36:48:46
ASIC 0
ASIC 0
4
fc4/4
340_Fabric1
dev340h104f01
20:34:00:05:1E:36:46:20
340_Fabric2
dev340h104f02
20:34:00:05:1E:36:48:46
ASIC 0
ASIC 0
7
fc7/10
340_Fabric1
dev340h104f01
20:4A:00:05:1E:36:46:20
340_Fabric2
dev340h104f02
20:4A:00:05:1E:36:48:46
ASIC 0
ASIC 0
8
fc8/6
340_Fabric1
dev340h104f01
20:56:00:05:1E:36:46:20
340_Fabric2
dev340h104f02
20:56:00:05:1E:36:48:46
ASIC 0
ASIC 0
9
fc9/5
340_Fabric1
dev340h104f01
20:65:00:05:1E:36:46:20
340_Fabric2
dev340h104f02
20:65:00:05:1E:36:48:46
ASIC 0
ASIC 0
10
fc10/11
340_Fabric1
dev340h104f01
20:7B:00:05:1E:36:46:20
340_Fabric2
dev340h104f02
20:7B:00:05:1E:36:48:46
ASIC 0
ASIC 0
1
fc1/9
340_Fabric1
dev340h104f01
20:09:00:05:1E:36:46:20
340_Fabric2
dev340h104f02
20:09:00:05:1E:36:48:46
ASIC 0
ASIC 0
2
fc2/11
340_Fabric1
dev340h104f01
20:1B:00:05:1E:36:46:20
340_Fabric2
dev340h104f02
20:1B:00:05:1E:36:48:46
ASIC 0
ASIC 0

Similar Messages

  • Please help me with this query -- i am trying with Dense rank

    version 10g
    i received a quote for an account. if the same quote is received under different account then i should mark the previous account received as deleted.
    please help me .
    /* Formatted on 2010/06/28 14:13 (Formatter Plus v4.8.8) */
    WITH temp AS
         (SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
                 TO_DATE ('12/23/2009 3:37:54',
                          'mm/dd/yyyy hh:mi:ss PM'
                         ) captured_date
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'RFS',
                 TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'Rejected',
                 TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Ordered',
                 TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'RFS',
                 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Rejected',
                 TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Validated',
                 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'RFS',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'RFS',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8Z', 'COPS', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8Z', 'COPS', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL)
    SELECT   quote_id, ACCOUNT, status, captured_date,
             DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id,
              ACCOUNT) rn
    --         ,CASE DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id,
    --              ACCOUNT)
    --            WHEN 1
    --               THEN 'Y'
    --            ELSE 'N'
    --         END deleted_flag
        FROM temp
    ORDER BY quote_id, captured_date;output required
    WITH temp AS
         (SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
                 TO_DATE ('12/23/2009 3:37:54',
                          'mm/dd/yyyy hh:mi:ss PM'
                         ) captured_date, 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'RFS',
                 TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'Rejected',
                 TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Ordered',
                 TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'RFS',
                 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Rejected',
                 TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Validated',
                 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'RFS',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'RFS',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8Z', 'COPS', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8Z', 'COPS', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL)
    SELECT   quote_id, ACCOUNT, status, captured_date, deleted_flag
        FROM temp
    ORDER BY quote_id, captured_date;

    try to wrap your query to become an in-line view. use a case statement or decode to your derived column RN from the analytic query of DENSE RANK. either way they both will work.
    SQL> WITH temp AS
      2       (SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
      3               TO_DATE ('12/23/2009 3:37:54',
      4                        'mm/dd/yyyy hh:mi:ss PM'
      5                       ) captured_date
      6          FROM DUAL
      7        UNION ALL
      8        SELECT '1-11TWQL', 'COPS', 'RFS',
      9               TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM')
    10          FROM DUAL
    11        UNION ALL
    12        SELECT '1-11TWQL', 'COPS', 'Rejected',
    13               TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM')
    14          FROM DUAL
    15        UNION ALL
    16        SELECT '1-11TWQL', 'COPS', 'Validated',
    17               TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM')
    18          FROM DUAL
    19        UNION ALL
    20        SELECT '1-11TWQL', 'D1', 'Ordered',
    21               TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM')
    22          FROM DUAL
    23        UNION ALL
    24        SELECT '1-11TWQL', 'D1', 'RFS',
    25               TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
    26          FROM DUAL
    27        UNION ALL
    28        SELECT '1-11TWQL', 'D1', 'Rejected',
    29               TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM')
    30          FROM DUAL
    31        UNION ALL
    32        SELECT '1-11TWQL', 'D1', 'Validated',
    33               TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
    34          FROM DUAL
    35        UNION ALL
    36        SELECT '1-249A8X', 'COPS', 'RFS',
    37               TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
    38          FROM DUAL
    39        UNION ALL
    40        SELECT '1-249A8X', 'COPS', 'RFS',
    41               TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
    42          FROM DUAL
    43        UNION ALL
    44        SELECT '1-249A8X', 'COPS', 'RFS',
    45               TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
    46          FROM DUAL
    47        UNION ALL
    48        SELECT '1-249A8X', 'COPS', 'Rejected',
    49               TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
    50          FROM DUAL
    51        UNION ALL
    52        SELECT '1-249A8X', 'COPS', 'Rejected',
    53               TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
    54          FROM DUAL
    55        UNION ALL
    56        SELECT '1-249A8X', 'COPS', 'Rejected',
    57               TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
    58          FROM DUAL
    59        UNION ALL
    60        SELECT '1-249A8X', 'COPS', 'Validated',
    61               TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
    62          FROM DUAL
    63        UNION ALL
    64        SELECT '1-249A8X', 'COPS', 'Validated',
    65               TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
    66          FROM DUAL
    67        UNION ALL
    68        SELECT '1-249A8X', 'COPS', 'Validated',
    69               TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
    70          FROM DUAL
    71        UNION ALL
    72        SELECT '1-249A8X', 'D1', 'Ordered',
    73               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    74          FROM DUAL
    75        UNION ALL
    76        SELECT '1-249A8X', 'D1', 'Ordered',
    77               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    78          FROM DUAL
    79        UNION ALL
    80        SELECT '1-249A8X', 'D1', 'RFS',
    81               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    82          FROM DUAL
    83        UNION ALL
    84        SELECT '1-249A8X', 'D1', 'RFS',
    85               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    86          FROM DUAL
    87        UNION ALL
    88        SELECT '1-249A8X', 'D1', 'Validated',
    89               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    90          FROM DUAL
    91        UNION ALL
    92        SELECT '1-249A8X', 'D1', 'Validated',
    93               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    94          FROM DUAL
    95        UNION ALL
    96        SELECT '1-249A8Z', 'COPS', 'Validated',
    97               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    98          FROM DUAL
    99        UNION ALL
    100        SELECT '1-249A8Z', 'COPS', 'Ordered',
    101               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    102          FROM DUAL)
    103  select vt.quote_id,
    104         vt.account,
    105         vt.status,
    106         vt.captured_date,
    107         case when vt.rn = 1 then 'N'
    108              else 'Y'
    109         end deleted_flag
    110    from (SELECT quote_id, ACCOUNT, status, captured_date,
    111                 DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id, ACCOUNT) rn
    112            FROM temp
    113          ORDER BY quote_id, captured_date) vt;
    QUOTE_ID ACCOUNT STATUS    CAPTURED_DATE DELETED_FLAG
    1-11TWQL D1      Rejected  23-Dec-2009 3 Y
    1-11TWQL D1      RFS       23-Dec-2009 3 Y
    1-11TWQL D1      Validated 23-Dec-2009 3 Y
    1-11TWQL D1      Ordered   23-Dec-2009 3 Y
    1-11TWQL COPS    RFS       23-Dec-2009 3 N
    1-11TWQL COPS    Validated 23-Dec-2009 3 N
    1-11TWQL COPS    Rejected  23-Dec-2009 3 N
    1-11TWQL COPS    Ordered   23-Dec-2009 3 N
    1-249A8X COPS    Validated 23-Dec-2009 3 N
    1-249A8X COPS    Validated 23-Dec-2009 3 N
    1-249A8X COPS    Validated 23-Dec-2009 3 N
    1-249A8X COPS    RFS       05-Mar-2010 1 N
    1-249A8X COPS    Rejected  05-Mar-2010 1 N
    1-249A8X COPS    RFS       16-Mar-2010 7 N
    1-249A8X COPS    Rejected  16-Mar-2010 7 N
    1-249A8X COPS    Rejected  16-Mar-2010 7 N
    1-249A8X COPS    RFS       16-Mar-2010 7 N
    1-249A8X D1      Ordered   26-Mar-2010 1 Y
    1-249A8X D1      Ordered   26-Mar-2010 1 Y
    1-249A8X D1      RFS       26-Mar-2010 1 Y
    1-249A8X D1      RFS       26-Mar-2010 1 Y
    1-249A8X D1      Validated 26-Mar-2010 1 Y
    1-249A8X D1      Validated 26-Mar-2010 1 Y
    1-249A8Z COPS    Validated 26-Mar-2010 1 N
    1-249A8Z COPS    Ordered   26-Mar-2010 1 N
    25 rows selected
    SQL>

  • Can we apply Dense Rank

    Hi All,
    I am working on Oracle BI Publisher. Can we apply Dense Rank on a column directly in the template? I don't want to change the total query for this, is there any way to do in template? if yes please tell me how can we do.
    Any suggestion would be greatly appreciated.
    Thanks in advance,
    Anil.

    Anil
    I think it can be done in XSL but its going to take some effort. You might be better using the db to provide the record ranking as a value in the resulting XML. Then its just a case of sorting on the ranking values.
    Regards
    tim

  • Using Dense Rank

    Hello,
    I am using ORACLE 10g and having an error when updating a table and generating ORA-30926 'Unable to get a stable set of rows in the source tables'.
    I create a temporary working table with records pulled from 2 different tables. The query to make the temp table uses
    the DENSE RANK FUNCTION to eliminate any duplicates. But, I am still getting duplicate records.
    When it is time to update my primary table with the records from the temp table, it sees the duplicates and
    generates the error. I have all the code to create the problem. I think I almost have it but maybe need different query structure.Any help is appreciated.
    -- Create table
    create table CUSTOMER
    EMP_ID NUMBER(4) ,
    CUST_ID NUMBER(9) not null,
    CONTACT_CD          VARCHAR2(1),
    PURCHASE_DATE DATE,
    NEW_CUST_CD          VARCHAR2(1),
    CUST_NAME          VARCHAR2(25)
    -- Create table
    create table DEFERRED_MAILING
    CUST_ID NUMBER(9) not null,
    EMP_ID NUMBER(4) not null,
    PURCHASE_DATE          DATE
    insert into customer ( emp_id, cust_id, contact_cd,PURCHASE_DATE, NEW_CUST_CD,cust_name)
    values (10,444,'Y',to_date('11-01-2011 16:11:05', 'dd-mm-yyyy hh24:mi:ss'),'Y','J.J.BROWN');
    insert into customer ( emp_id, cust_id,contact_cd, PURCHASE_DATE, NEW_CUST_CD,cust_name)
    values (10,444,'Y',to_date('11-01-2011 16:11:05', 'dd-mm-yyyy hh24:mi:ss'),'Y','J.BROWN');
    insert into deferred_mailing (cust_id, emp_id, purchase_date)
    values (444, 10, to_date('11-01-2011 16:11:05', 'dd-mm-yyyy hh24:mi:ss'));
    create table UPDTE_DEFERRED_MAILING_RECORDS nologging as
    SELECT a.CUST_ID,
    a.EMP_ID,
    a.PURCHASE_DATE,
    a.DM_ROW_ID,
    a.drank,
    c.CONTACT_CD,
    c.NEW_CUST_CD/*,
    TRANS_ID_SEQ.NEXTVAL as TRANS_ID*/
    FROM (SELECT a.ROWID AS DM_ROW_ID,
    a.CUST_ID,
    a.EMP_ID,
    a.PURCHASE_DATE,
    dense_rank() over(PARTITION BY a.CUST_ID, a.EMP_ID ORDER
    BY a.PURCHASE_DATE DESC, a.ROWID) DRANK
    FROM deferred_mailing a) a,
    customer c
    WHERE a.CUST_ID = c.CUST_ID
    AND a.EMP_ID = c.EMP_ID
    AND (a.PURCHASE_DATE <= c.PURCHASE_DATE OR
    c.PURCHASE_DATE IS NULL);
    SELECT * FROM UPDTE_DEFERRED_MAILING_RECORDS;
    }

    Please try this
    create table UPDTE_DEFERRED_MAILING_RECORDS nologging as
    SELECT distinct a.CUST_ID,
    a.EMP_ID,
    a.PURCHASE_DATE,
    a.drank,
    c.CONTACT_CD,
    c.NEW_CUST_CD,
    a.DM_ROW_ID
    FROM (SELECT a.ROWID AS DM_ROW_ID,
    a.CUST_ID,
    a.EMP_ID,
    a.PURCHASE_DATE,
    dense_rank() over(PARTITION BY a.CUST_ID, a.EMP_ID ORDER
    BY a.PURCHASE_DATE DESC, a.ROWID) DRANK
    FROM deferred_mailing a) a,
    customer c
    WHERE a.CUST_ID = c.CUST_ID
    AND a.EMP_ID = c.EMP_ID
    AND (a.PURCHASE_DATE <= c.PURCHASE_DATE OR
    c.PURCHASE_DATE IS NULL)
    and a.drank=1;
    The query you've posted is behaving according to the expectations. The inner select is returning one row and the outer is returning two as the
    WHERE a.CUST_ID = c.CUST_ID
    AND a.EMP_ID = c.EMP_ID
    AND (a.PURCHASE_DATE <= c.PURCHASE_DATE OR
    c.PURCHASE_DATE IS NULL)
    conditions are seeing two rows in the table customer.
    I've added the a.drank=1 clause to skip the duplicates from the inner table and distinct in the final result to remove duplicates from the overall query result.
    For eg, if you have one more row in the deferred_mailing like this
    SQL> select * from DEFERRED_MAILING;
    CUST_ID EMP_ID PURCHASE_
    444 10 11-JAN-11
    444 10 11-JAN-11
    then the query without "a.drank=1" will return 4 rows like this by the outer query.
    CUST_ID EMP_ID PURCHASE_ DM_ROW_ID DRANK C N
    444 10 11-JAN-11 AAATi2AAGAAAACcAAB 2 Y Y
    444 10 11-JAN-11 AAATi2AAGAAAACcAAA 1 Y Y
    444 10 11-JAN-11 AAATi2AAGAAAACcAAB 2 Y Y
    444 10 11-JAN-11 AAATi2AAGAAAACcAAA 1 Y Y
    It'll return the below even if we use distinct on the same query(i.e. without a.drank=1)
    CUST_ID EMP_ID PURCHASE_ DM_ROW_ID DRANK C N
    444 10 11-JAN-11 AAATi2AAGAAAACcAAB 2 Y Y
    444 10 11-JAN-11 AAATi2AAGAAAACcAAA 1 Y Y
    which contains duplicates again.
    So, we need a combination of distinct and dense here.
    btw, Please mark the thread as 'answered', if you feel you got your question answered. This will save the time of others who search for open questions to answer.
    Regards,
    CSM

  • The parameter name [...] in the query's selection criteria does not match..

    Hi all,
    I'm trying to pratice EJB 3 (which I learnt at school), with JSF and JPA, but i'm really stuck with that error :
    Exception [TOPLINK-6094] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.QueryException
    Exception Description: The parameter name [departmentID] in the query's selection criteria does not match any parameter name defined in the query.
    Query: ReadAllQuery(oracle.datamodel.Employees)
    I will try to explain clearly what i'm trying to do :
    In fact, i'm following that tutorial :
    http://www.oracle.com/technology/obe/obe1013jdev/10131/ejb_and_jpa/master-detail_pagewith_ejb.htm
    But, as i didn't have any oracle database, but had a mysql one on my machine, i decided to use that DB instead of the the oracle DB... So i created a set of example data (to replace the oracle example set) ...so i created the tables EMPLOYEE, and DEPARTMENT... with the correct relations (FK) and PK)
    All was ok, i choose my "mysql-connector" (jdbc) instead of the oracle jdbc connector... so i could follow the tutorial.
    My problem appears at the step 12 (of "Creating a Master-Detail JavaServer Faces Page"), when i run the file deptEmployees.jspx.
    The information of the first departement displays correctly :
    departmentID 1
    departmentName ... etc
    but it can't display the employees belonging to that department !
    the error is :
    JBO-29000: Exception Description: The parameter name [departmentID] in the query's selection criteria does not match any parameter name defined in the query. Query: ReadAllQuery(oracle.datamodel.Employees)
    I think i understand what is the problem... I think that the query in charge of gathering the data of a specific departement need a parameter, but couldn't find it. But i don't know why :-/ I have tried many things and read the topics talking about that error... but it didn't solved the problem. I don't know anymore where to investigate.
    I have created a Zip file of my work (it's an EJB/JSF Application.. with jdev 10.1.3.3.0)
    (available here : http://dl.free.fr/mQ5esdQuS/EJB_appli.zip)
    I would be glad if someone could take few minutes to help me.
    Thank you in advance,
    Thomas B (student)

    Hello,
    This is a common mistake. Java string comparisons in TopLink are case sensitive by default, and since column names are uppercase when defaulted, TopLink cannot find the "departmentID" column name. In this case, Departments ID column defaults to "DEPARTMENTID" as required by the JPA specification.
    Either change Departments id annotation to     @Id
        @Column(name="departmentID", nullable = false)
        private Integer departmentID;or change Employees' ManytoOne annotation to:
        @ManyToOne
        @JoinColumn(name = "departmentID", referencedColumnName = "DEPARTMENTID")
        private Departments departments;Best Regards,
    Chris

  • Changing Query Component's criteria items at runtime

    Hi All,
    As per my requirement i am changing query component's criteria items on some user input.
    So initially there were 9 components on query panel form and after user input it will become 7. I programatically used to set this two component's UI Hint as setVisible(false).
    Its working fine but if user input some value in to be removed 2 components it throws an null pointer exception.
    I understood the problem which is:-
    On query form if user input any value it used to persist. for same framework used to store this user entered value somewhere and after refresh it apply this value to the relevant components.
    Since two of the component are missing after refresh. it throws a null pointer exception as it tried to call setValue() method on removed component which is not there.
    After refresh the query panel form is rendered as per defined by QueryDescriptor object.
    Is there any way we can update this QueryDescriptor object with the changes...????

    Hi Simran,
    Yes, it is possible with the help of store procedure. In SQL Server there is a IF-Else Conditional block, which you can use inside store procedure. Create a SP with 2 additional parameter something like FlagReadAgain and KeyField. Pass the flag always as True or False. For the Key field pass the record key which you want to read again if you are passing the Flag as True else pass it as 0 or whatever.
    In the procedure check if the value of flag is True -> If yes, Read the entry with key name specified in where part.
    In the else part put the query which you are using for the normal flow.
    IF (FlagReadAgain) = TRUE
    BEGIN
       SELECT EmpName, EmpAddress
       FROM Employee
       WHERE EmpID = 'E001'
    END
    ELSE
       BEGIN
         SELECT EmpName, EmpAddress
         FROM Employee
         WHERE Status = 'N'
       END
    You may also use the approach which Srini mentioned. Create an application to restore any value to intial stage so that it can be picked up by XI when it poll again.
    Choose any approach which you like.
    Regards,
    Jitender Chauhan

  • What is ranking criteria for top iPhone apps?

    What is the ranking criteria used by iTunes for top iPhone apps -- premium and free? Is it just most downloaded? Also rankings are updated how frequently? Thank you!

    "Top" apps are defined by number of downloads. Seems to be updated "live" (it changes more than once a day sometimes, and since it is based on number of downloads, it's probably an automated process).

  • Analytic query to select next record

    Hi all,
    I would like to query the below two table match to ouput.
    1.dev_wt 2.dev_map 3.Output Result
    To help more clearance please see this image link : http://lh6.ggpht.com/_xL6eBqjW6Yo/TEqnSvlF_FI/AAAAAAAAB0U/i2sclnnaj6g/Untitled-3.jpg
    1. dev_wt
    PMS_COMP     PMS_I       PMS_PERF_D   PMS_WT   PMS_CREATION_D
    BBOARD     GICEQGROSS    04/01/2001     30     04/05/2001
    BBOARD     GICST_B       04/01/2001     5      04/05/2001
    BBOARD     SBGS_B        04/01/2001     65     04/05/2001
    BBOARD     GICEQGROSS    04/11/2001     30     04/15/2001
    BBOARD     GICST_B       04/11/2001     5      04/15/2001
    BBOARD     SBGS_B        04/11/2001     65     04/15/20012. dev_map
    GS_CODE     GS_I_CODE    GS_I_ID  MD_ID   GS_START_DT    GS_END_DT
    GICEQGROSS   CIWL        304       15     01/04/1998     31/03/2004
    GICEQGROSS   CIWL        304       2     01/04/2004      31/03/9998
    GICST_B      GICST_B     3707      15     01/04/2000     31/12/9998
    SBGS_B       SBGS_B      2231      15     01/04/1992     30/09/2003
    SBGS_B       SBGS_B      564       15     01/10/2003     31/12/9998I would like to match PMS_I = GS_CODE to retrieve GS_I_CODE and using analytic
    query to find next record.
    Because I need to select GICEQGROSS record of PMS_PERF_D date and next
    GICEQGROSS record of PMS_PERF_D from dev_wt table and put GS_WT_FR and GS_WT_TO of Output result.
    ***Date is change to YYYYMMDD format
    ***PMS_WT is devided by 100
    *3. Output Result*
    GS_I_ID    PMS_COMP     GS_I_CODE     GS_WT_FR     GS_WT_TO     GS_I_CALC
    304       BBOARD        CIWL          20010401     20010410     0.3
    3707      BBOARD        GICST_B       20010401     20010410     0.05
    5209      BBOARD        SBGS_B        20010401     20010410     0.65PMS_COMP is from dev_wt table
    GS_I_CODE is from dev_map table join with dev_wt
    GS_WT_FR is from dev_wt table of GS_START_DT
    GS_WT_TO is from dev_wt table of next record GS_START_DT where PMS_I ='GICEQGROSS'
    Now my difficulty is to select next record of PMS_PERF_D using analytic query. Below
    is my query...
    SELECT GS_I_ID, PMS_COMP, GS_I_CODE, GS_WT_FR, GS_WT_TO, GS_I_CALC
    FROM dev_wt (
    SELECT lead(PMS_PERF_D) over(partition by PMS_I order by PMS_PERF_D) as GS_WT_TO       
    FROM dev_wt where PMS_I ='GICEQGROSS')
    left join dev_map on PMS_I = GS_CODE ;Thanks
    Edited by: WinZone on Jul 24, 2010 4:46 PM
    Edited by: WinZone on Jul 24, 2010 4:50 PM

    Hi,
    This query should be fine:
    SELECT DISTINCT t2.gs_i_id, pms_comp, t2.gs_i_code,
                    TO_CHAR
                       (MIN (pms_perf_d) OVER (PARTITION BY pms_comp, pms_i),
                        'yyyymmdd'
                       ) gs_wt_fr,
                    TO_CHAR
                       (MAX (pms_perf_d) OVER (PARTITION BY pms_comp, pms_i) - 1,
                        'yyyymmdd'
                       ) gs_wt_to,
                    pms_wt / 100 gs_i_calc
               FROM dev_wt t1, dev_map t2
              WHERE t2.gs_code = t1.pms_iREM Same remark as odie: should be "2231" instead ...

  • Help on Dense Rank Function

    Hello All,
    Below is the sql i am trying to execute and the Dense Rank function is giving same result for all of the rows, could you please help me where i am doing wrong
    SELECT
    AMT,
    DENSE_RANK() OVER (PARTITION BY AMT ORDER BY AMT DESC) AS DENSE_RANK
    FROM
    SELECT DISTINCT
    SUM(NVL(TRUNC(NET_AMT) * NVL(GLOBAL1_EXCHANGE_RATE,1),0))
    OVER (PARTITION BY CUSTOMER_BILL_TO_LOC_WID ORDER BY CUSTOMER_BILL_TO_LOC_WID)
    AS AMT
    FROM
    W_SALES_BOOKING_LINE_F
    WHERE
    SALES_ORDER_NUM IN ('10612426','10612450','10612477','32649203')
    AND
    X_MONTH_WID=TO_CHAR(SYSDATE-1,'YYYYMMDD')
    )--ORDER BY AMT DESC Result Set:
    AMT     DENSE_RANK
    0     1
    2,855     1
    6,706     1
    14,265     1

    you have "broken" up your resultset (from the inline view) by AMT (PARTITION BY AMT)
    and per part, you sort this (one row in each partition, not a whole lot of sorting) ( ORDER BY AMT DESC)
    then you assign a ranking based on the sorting action... which yields 1 (DENSE_RANK)
    Are you looking for this
    SELECT
    AMT,
    DENSE_RANK() OVER (ORDER BY AMT DESC) AS DENSE_RANK
    FROM
    SELECT DISTINCT
    SUM(NVL(TRUNC(NET_AMT) * NVL(GLOBAL1_EXCHANGE_RATE,1),0))
    OVER (PARTITION BY CUSTOMER_BILL_TO_LOC_WID ORDER BY CUSTOMER_BILL_TO_LOC_WID)
    AS AMT
    FROM
    W_SALES_BOOKING_LINE_F
    WHERE
    SALES_ORDER_NUM IN ('10612426','10612450','10612477','32649203')
    AND
    X_MONTH_WID=TO_CHAR(SYSDATE-1,'YYYYMMDD')
    )--ORDER BY AMT DESC

  • Analytic query !!!!

    Hi all,
    I have the following table with the set of data. This is just a short version of the actual table. The actual table has around 13 million records.
    CREATE TABLE MY_TEST_TABLE(ID NUMBER,KEY NUMBER,TYPEOFRECORD VARCHAR2(20BYTE),
    MYDATE DATE);
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values(6366556, 404887, 'GP', TO_DATE('07/23/2004 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values
    (6366516, 404887, 'GP', TO_DATE('07/23/2004 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values
    (6366565, 404887, 'GP', TO_DATE('07/23/2004 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values
    (6366568, 404887, 'GP', TO_DATE('07/23/2004 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values
    (7076940, 404887, 'CE', TO_DATE('11/04/2004 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values
    (18197564, 404887, 'CE', TO_DATE('08/29/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values
    (17561339, 404887, 'CE', TO_DATE('05/05/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values
    (18381063, 404887, 'CE', TO_DATE('05/19/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values
    (18381260, 404887, 'CE', TO_DATE('06/09/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values
    (18386869, 404887, 'CE', TO_DATE('06/10/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values
    (18895620, 404887, 'CE', TO_DATE('06/10/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values
    (17769950, 404887, 'CE', TO_DATE('05/06/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values
    (18096803, 404887, 'CE', TO_DATE('05/19/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values
    (18381262, 404887, 'CE', TO_DATE('06/09/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into MY_TEST_TABLE(ID, KEY, TYPEOFRECORD, MYDATE)
    Values
    (18381270, 404887, 'CE', TO_DATE('06/09/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    COMMIT;
    My requirement is to get the highest ID value, TYPEOFRECORD value for a given key value. So I wrote this query:
    select KEY, max(ID) over (partition by KEY) myid, TYPEOFRECORD
    from MY_TEST_TABLE;
    but this query returns as many number of records as there are records for a particular KEY value.
    But if I write this query it gives the correct result:
    select tt1.key,tt1.id,tt1.MYDATE,tt1.TYPEOFRECORD
    from MY_TEST_TABLE tt1 where (tt1.KEY,tt1.ID) in
    (select tt.KEY, max(tt.ID) myid
    from MY_TEST_TABLE tt
    group by tt.key)
    What wrong I am doing in the analytic query.
    Thanks
    Vinayak

    you should not look for analytic, but for aggregates :
    select KEY, max(ID) id, max(TYPEOFRECORD) keep (dense_rank first order by id) typeofrecord
    from MY_TEST_TABLE
    group by key;
           KEY         ID TYPEOFRECORD
        404887   18895620 GPwith analytics, you can for each line get the max.
    like in :
    select KEY, id, TYPEOFRECORD, max(id) over (partition by key) maxid, 
    max(TYPEOFRECORD) keep (dense_rank first order by id) over (partition by key) maxTYPEOFRECORD
    from MY_TEST_TABLE;
           KEY         ID TYPEOFRECORD              MAXID MAXTYPEOFRECORD
        404887    6366556 GP                     18895620 GP
        404887   18381270 CE                     18895620 GP
        404887    6366565 GP                     18895620 GP
        404887    6366568 GP                     18895620 GP
        404887    7076940 CE                     18895620 GP
        404887   18197564 CE                     18895620 GP
        404887   17561339 CE                     18895620 GP
        404887   18381063 CE                     18895620 GP
        404887   18381260 CE                     18895620 GP
        404887   18386869 CE                     18895620 GP
        404887   18895620 CE                     18895620 GP
        404887   17769950 CE                     18895620 GP
        404887   18096803 CE                     18895620 GP
        404887   18381262 CE                     18895620 GP
        404887    6366516 GP                     18895620 GPok?

  • Looking for hook into a mb method on page load of jsff with auto query on view criteria.

    Hello,
    I have a View Criteria that is set to Query Automatically (showing data to match today's date).  The target table has a detail table and there is a control that shows parsed XML from the current row in the detail table into a table that I build dynamically. The main table and the detail table show the proper data on page load but the table for the parsed XML is empty.  The dynamic table is bound to a managed bean where the parsing is done and data is created.  I have the control refreshing properly on a row change of the main and detail tables and on a queryListener for the view criteria.
    This is for a jsff page. I have been trying a bunch of approaches with no success.  The detail table has a ppr to the main table and the query.  I am looking some event on either the query, the main table or the detail table where I can make a call to my managed bean to parse the XML, build the table and refresh the control.  I have an attribute binding to the XML data (when I placed it in a control as plane XML it refreshed properly).  I only need this on initial page load or first time the tables are populated, I have the other use cases covered.
    Running JDev 11.1.2.4
    Thank you
    Rudy

    ok but where?
    i have read a topic about "setRefreshOption", but i need a component to execute it.
    i have read a topic about a false criteria (1=2), and when i want search, i remove it, but again, i need a component to execute it.
    i have read a topic about ${adfFacesContext.postback == true} to write into iterator proeprty, but i haven't this view into my appmodule.
    i'm really sorry, but please, can you explain me a little ?
    Edited by: bradici on 8 oct. 2009 16:36

  • How to write complex query with jpa criteria builder.

    Hello,
    I want to write a query in jpa criteriaquery. Here is the query:
    SELECT node.category_name, (COUNT(parent.category_name) - 1) AS depth
    FROM category_subcategories AS node,
    category_subcategories AS parent
    WHERE node.lft BETWEEN parent.lft AND parent.rgt
    AND node.category_name = 'PORTABLE ELECTRONICS'
    GROUP BY node.category_name
    ORDER BY node.lft
    Here is the code I come up with:
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<CategorySubcategories> cq = cb.createQuery( CategorySubcategories.class );
    Root<CategorySubcategories> node = cq.from( CategorySubcategories.class );
    Root<CategorySubcategories> parent = cq.from( CategorySubcategories.class );
    Predicate p1 = cb.equal(node.get("categoryName"), categoryName);
    Predicate p2 = cb.between(node.get("lft").as(Integer.class), parent.get("lft").as(Integer.class), parent.get("rgt").as(Integer.class));
    Order nodeLft = cb.asc(node.get("lft"));
    cq.multiselect(node.get("categoryName"), cb.count(parent.get("categoryName")))
    .where(p1, p2)
    .groupBy(node.get("categoryName"))
    .orderBy(nodeLft);
    return em.createQuery(cq).getResultList();
    When I execue the test, it shown the following error:
    Testcase: testDepthOfSubtree(au.com.houseware.server.ejb.entity.facade.CategorySubcategoriesFacadeTest): Caused an ERROR
    org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [au.com.houseware.server.ejb.entity.CategorySubcategories] [select new au.com.houseware.server.ejb.entity.CategorySubcategories(generatedAlias0.categoryName, count(generatedAlias1.categoryName)) from au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias0, au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias1 where ( generatedAlias0.categoryName=:param0 ) and ( generatedAlias0.lft between generatedAlias1.lft and generatedAlias1.rgt ) group by generatedAlias0.categoryName]
    java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [au.com.houseware.server.ejb.entity.CategorySubcategories] [select new au.com.houseware.server.ejb.entity.CategorySubcategories(generatedAlias0.categoryName, count(generatedAlias1.categoryName)) from au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias0, au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias1 where ( generatedAlias0.categoryName=:param0 ) and ( generatedAlias0.lft between generatedAlias1.lft and generatedAlias1.rgt ) group by generatedAlias0.categoryName]
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1201)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:324)
    at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:227)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:441)
    at au.com.houseware.server.ejb.entity.facade.CategorySubcategoriesFacadeMock.findDepthOfSubtreeBy_categoryName(CategorySubcategoriesFacadeMock.java:228)
    at au.com.houseware.server.ejb.entity.facade.CategorySubcategoriesFacadeTest.testDepthOfSubtree(CategorySubcategoriesFacadeTest.java:44)
    Caused by: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [au.com.houseware.server.ejb.entity.CategorySubcategories] [select new au.com.houseware.server.ejb.entity.CategorySubcategories(generatedAlias0.categoryName, count(generatedAlias1.categoryName)) from au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias0, au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias1 where ( generatedAlias0.categoryName=:param0 ) and ( generatedAlias0.lft between generatedAlias1.lft and generatedAlias1.rgt ) group by generatedAlias0.categoryName]
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
    at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
    at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261)
    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
    at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
    at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
    at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
    at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
    at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:306)
    What is wrong with my criteriaQuery?
    Any suggestion is very much appreciated.
    Thanks
    Sam
    Edited by: 785102 on Mar 26, 2011 7:44 PM

    Hello,
    Thank you for your response.
    If I remove CategorySubcateogires, netbeans complained:
    incompatible types
    required: javax.persistence.criteria.CriteriaQuery<au.com.houseware.server.ejb.entity.CategorySubcategories>
    found: javax.persistence.criteria.CriteriaQuery<java.lang.Object>
    When I removed all CategorySubcategories type and replaced it with Object like this:
    public Collection<Object> findDepthOfSubtreeBy_categoryName(String categoryName) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Object> c = cb.createQuery();
    Root<CategorySubcategories> node = c.from( CategorySubcategories.class );
    Root<CategorySubcategories> parent = c.from( CategorySubcategories.class );
    Predicate p1 = cb.equal(node.get("categoryName"), categoryName);
    Order nodeLft = cb.asc(node.get("lft"));
    c.multiselect(node.get("categoryName"), cb.count(parent.get("categoryName")))
    .where(p1)
    .groupBy(node.get("categoryName"))
    .orderBy(nodeLft);
    return em.createQuery(c).getResultList();
    test main():
    Collection<Object> list = ccFacade.findDepthOfSubtreeBy_categoryName("Houseware");
    for (Iterator<Object> iter = list.iterator(); iter.hasNext();) {
    CategorySubcategories cc = (CategorySubcategories) iter.next();
    System.out.println(" name : "+cc.getCategoryName());
    On execution, it thrown exception:
    [Ljava.lang.Object; cannot be cast to au.com.houseware.server.ejb.entity.CategorySubcategories
    Thanks a lot
    Sam                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Query Statement Properties Criteria -- Server "Location"

    When I generally create queries to populate collections [Membership Rules] in SCCM 2012, I use: 
    System Resource.System OU Name is like "[OU location]%"
    However, I recently received a request to create a query collection based on an
    attribute location, instead of OU container.  I am having trouble composing the criteria for this new query.  Does anyone know how to create a query based on attribute location?  For example,
    the server site is "[xxxx]CS" and the attribute location name is
    "A"

    Thank you so much for your response and blog!
    I never knew of the AD attribute discovery feature.  I was confused since my servers were showing up in Assets and Compliance > Devices because I did an adsysdis for the proper domain and OU.
    I made created my query using System Resource.location is like "%A%"
    (after adding location as an AD attribute) all of my collections finally populated.  Thanks again!!

  • Description change in query report selection criteria

    I created a query report with certain criteria but in that i suppose to change the description .
    for example
    Posting date   greater than
    Posting date   lesser than
    but i need this selection criteria
    as
    Posting date  from
    Posting date  to
    regards
    kavitha

    Hi Kavitha,
    Unfortunately, it is not possible to change the system field description.
    Refer to this thread
    Re: Parameter Display Name Reg.
    Regards,
    Vijay Kumar
    SAP Business One Forums Team

  • Hierarchical + Analytical query for organizational unit parameters

    Hello gurus,
    I try for a couples of hour ago to make a query work as I would like.
    Our application need to store some parameters for our organization units. These organization units are typically organized in in an hierarchy manner: one top unit with many level of child units. The parameters are stored into another table with 1:1 relationship.
    For sake of visualisation, here is the data for the organization unit and parameter table in a more visual format:
    SQL> select * from organization_unit;
    UNIT_CODE  UNIT_NAME            PARENT_UNIT_CODE
    00000      Top level
    10         L2 unit #10          00000
    10-01      L3 unit #10-01       10
    10-02      L3 unit #10-02       10
    20         L2 unit #20          00000
    20-01      L3 unit #20-01       20
    20-02      L3 unit #20-02       20
    SQL>  select * from org_unit_parameters;
    UNIT_CODE  PARAM1               PARAM2               PARAM3               PARAM4
    00000      Default value        Default value        Default value        {null}
    10         {null}               Value from 10        Value from 10        {null}
    10-01      {null}               {null}               Value from 10-01     {null}
    10-02      {null}               {null}               {null}               Value from 10-02
    20         Value from 20        Value from 20        Value from 20        {null}
    20-01      {null}               Value from 20-01     {null}               {null}
    20-02      {null}               Value from 20-02     {null}               {null}The application will query the parameter table to get a parameter value for a given unit.
    The parameter resolution algorithm is rather simple: when querying a unit, the applicable parameter is the one defined at the requested level. If the parameter is not defined (null) at the requested level, the parameter value that must be returned is the next defined one in the parent hierarchy. In some rare cases, it can be null if a parameter is not defined anywhere from the requested level to top.
    I've made a query that seems to work when querying for one unit at a time. It use hierarchical operators (start with + connect by) with a bit of analytical functions. Here is a test & raw output example:
    SQL> WITH hierarchy
      2  AS
      3  (
      4    SELECT ou.unit_code,
      5         LEVEL            AS lvl
      6    FROM   organization_unit ou
      7    START WITH
      8      ou.unit_code = '20-01'
      9    CONNECT BY
    10      ou.unit_code = PRIOR ou.parent_unit_code
    11  )
    12  SELECT h.*,
    13       p.param1                                                        AS param1_raw,
    14       LAST_VALUE (p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param1_with_last,
    15       FIRST_VALUE(p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param1_with_first,
    16       p.param2                                                        AS param2_raw,
    17       LAST_VALUE (p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param2_with_last,
    18       FIRST_VALUE(p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param2_with_first,
    19       p.param3                                                        AS param3_raw,
    20       LAST_VALUE (p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param3_with_last,
    21       FIRST_VALUE(p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param3_with_first,
    22       p.param4                                                        AS param4_raw,
    23       LAST_VALUE (p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param4_with_last,
    24       FIRST_VALUE(p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param4_with_first
    25  FROM   hierarchy                                h
    26         LEFT JOIN org_unit_parameters         p
    27         ON h.unit_code = p.unit_code
    28  ORDER BY h.lvl DESC;
    UNIT_CODE   LVL PARAM1_RAW           PARAM1_WITH_LAST     PARAM1_WITH_FIRST    PARAM2_RAW           PARAM2_WITH_LAST     PARAM2_WITH_FIRST    PARAM3_RAW           PARAM3_WITH_LAST     PARAM3_WITH_FIRST    PARAM4_RAW           PARAM4_WITH_LAST     PARAM4_WITH_FIRST
    00000         3 Default value        Default value        Value from 20        Default value        Default value        Value from 20-01     Default value        Default value        Value from 20        {null}               {null}               {null}
    20            2 Value from 20        Value from 20        Value from 20        Value from 20        Value from 20        Value from 20-01     Value from 20        Value from 20        Value from 20        {null}               {null}               {null}
    20-01         1 {null}               Value from 20        {null}               Value from 20-01     Value from 20-01     Value from 20-01     {null}               Value from 20        {null}               {null}               {null}               {null}Seems pretty good, the upper parameters are well «propagated» down with LAST_VALUE function. But, I don't understand why the use of FIRST_VALUE and oppposite ordering doesn't give the same result. A little more playing with the last query for getting the final result for a given unit code:
    SQL> SELECT *
      2  FROM
      3  (
      4     WITH hierarchy
      5     AS
      6     (
      7        SELECT ou.unit_code,
      8               LEVEL            AS lvl
      9        FROM   organization_unit ou
    10        START WITH
    11           ou.unit_code = '20-01'
    12        CONNECT BY
    13           ou.unit_code = PRIOR ou.parent_unit_code
    14     )
    15     SELECT h.*,
    16            LAST_VALUE (p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param1,
    17            LAST_VALUE (p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param2,
    18            LAST_VALUE (p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param3,
    19            LAST_VALUE (p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param4
    20     FROM   hierarchy                                h
    21               LEFT JOIN org_unit_parameters         p
    22               ON h.unit_code = p.unit_code
    23     ORDER BY h.lvl
    24  )
    25  WHERE ROWNUM = 1;
    UNIT_CODE   LVL PARAM1               PARAM2               PARAM3               PARAM4
    20-01         1 Value from 20        Value from 20-01     Value from 20        {null}Works well!
    But, my ultimate goal is to create a view that resolve correctly all these parameters for each level of the organization with proper propagation rather then querying for each unit at a time. I played a bit, but without success. :( My current raw query is this one:
    SQL> WITH hierarchy
      2  AS
      3  (
      4     SELECT ou.unit_code,
      5            LPAD(' ',2*(LEVEL-1)) || ou.unit_code    AS tree,
      6            LEVEL                                    AS lvl
      7     FROM   organization_unit ou
      8     START WITH
      9        parent_unit_code IS NULL
    10     CONNECT BY
    11        PRIOR unit_code =  parent_unit_code
    12  )
    13  SELECT h.*,
    14         p.param1                                                        AS param1_raw,
    15         LAST_VALUE (p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param1_with_last,
    16         FIRST_VALUE(p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param1_with_first,
    17         p.param2                                                        AS param2_raw,
    18         LAST_VALUE (p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param2_with_last,
    19         FIRST_VALUE(p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param2_with_first,
    20         p.param3                                                        AS param3_raw,
    21         LAST_VALUE (p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param3_with_last,
    22         FIRST_VALUE(p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param3_with_first,
    23         p.param4                                                        AS param4_raw,
    24         LAST_VALUE (p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param4_with_last,
    25         FIRST_VALUE(p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param4_with_first
    26  FROM   hierarchy                          h
    27            LEFT JOIN org_unit_parameters   p
    28            ON h.unit_code = p.unit_code
    29  ORDER BY h.unit_code;
    UNIT_CODE  TREE        LVL PARAM1_RAW                PARAM1_WITH_LAST          PARAM1_WITH_FIRST      PARAM2_RAW                   PARAM2_WITH_LAST          PARAM2_WITH_FIRST         PARAM3_RAW                PARAM3_WITH_LAST          PARAM3_WITH_FIRST         PARAM4_RAW                PARAM4_WITH_LAST       PARAM4_WITH_FIRST
    00000      00000         1 Default value             Default value             Default value          Default value                Default value             Default value             Default value             Default value             Default value             {null}                    Value from 10-02       {null}
    10           10          2 {null}                    Value from 20             Default value          Value from 10                Value from 10             Default value             Value from 10             Value from 10             Default value             {null}                    Value from 10-02       {null}
    10-01          10-01     3 {null}                    {null}                    Default value          {null}                       Value from 20-02          Default value             Value from 10-01          Value from 10-01          Default value             {null}                    Value from 10-02       Value from 10-02
    10-02          10-02     3 {null}                    {null}                    Default value          {null}                       Value from 20-02          Default value             {null}                    Value from 10-01          Default value             Value from 10-02          Value from 10-02       Value from 10-02
    20           20          2 Value from 20             Value from 20             Default value          Value from 20                Value from 10             Default value             Value from 20             Value from 10             Default value             {null}                    Value from 10-02       {null}
    20-01          20-01     3 {null}                    {null}                    Default value          Value from 20-01             Value from 20-02          Default value             {null}                    Value from 10-01          Default value             {null}                    Value from 10-02       Value from 10-02
    20-02          20-02     3 {null}                    {null}                    Default value          Value from 20-02             Value from 20-02          Default value             {null}                    Value from 10-01          Default value             {null}                    Value from 10-02       Value from 10-02As you can see, it's not as I expected. I know there's something to do with a PARTITION BY clause, but don't know how.
    Is anyone knows how to solve my problem?
    Thanks
    Bruno
    For reproductibility purposes, here is the code to create sturcture and data:
    Here is the format of my tables and some samble data:
    CREATE TABLE organization_unit (
       unit_code         VARCHAR2(5 CHAR)   NOT NULL PRIMARY KEY,
       unit_name         VARCHAR2(100 CHAR) NOT NULL,
       parent_unit_code  VARCHAR2(5 CHAR)  
    CREATE TABLE org_unit_parameters (
       unit_code         VARCHAR2(5 CHAR)   NOT NULL PRIMARY KEY,
       param1            VARCHAR2(100 CHAR),
       param2            VARCHAR2(100 CHAR),
       param3            VARCHAR2(100 CHAR),
       param4            VARCHAR2(100 CHAR)
    -- Inserting data
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code)
    VALUES ('00000', 'Top level', NULL);
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code)
    VALUES ('10', 'L2 unit #10', '00000');
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code)
    VALUES ('10-01', 'L3 unit #10-01', '10');
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code)
    VALUES ('10-02', 'L3 unit #10-02', '10');
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code)
    VALUES ('20', 'L2 unit #20', '00000');
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code)
    VALUES ('20-01', 'L3 unit #20-01', '20');
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code)
    VALUES ('20-02', 'L3 unit #20-02', '20');
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param1, param2, param3)
    VALUES ('00000', 'Default value', 'Default value', 'Default value');
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param2, param3)
    VALUES ('10', 'Value from 10', 'Value from 10');
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param3)
    VALUES ('10-01', 'Value from 10-01');
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param4)
    VALUES ('10-02', 'Value from 10-02');
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param1, param2, param3)
    VALUES ('20', 'Value from 20', 'Value from 20', 'Value from 20');
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param2)
    VALUES ('20-01', 'Value from 20-01');
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param2)
    VALUES ('20-02', 'Value from 20-02');
    COMMIT;

    Now, I hoppe I got your reqs:
    WITH hierarchy AS (
                       SELECT  ou.unit_code,
                               LPAD(' ',2*(LEVEL-1)) || ou.unit_code    AS tree,
                               LEVEL                                    AS lvl,
                               param1                                   AS param1_raw,
                               param2                                   AS param2_raw,
                               param3                                   AS param3_raw,
                               param4                                   AS param4_raw,
                               SYS_CONNECT_BY_PATH(p.param1,'#') || '#' AS param1_path,
                               SYS_CONNECT_BY_PATH(p.param2,'#') || '#' AS param2_path,
                               SYS_CONNECT_BY_PATH(p.param3,'#') || '#' AS param3_path,
                               SYS_CONNECT_BY_PATH(p.param4,'#') || '#' AS param4_path
                         FROM  organization_unit ou LEFT JOIN org_unit_parameters p
                                 ON ou.unit_code = p.unit_code
                         START WITH parent_unit_code IS NULL
                         CONNECT BY PRIOR ou.unit_code =  parent_unit_code
    SELECT  unit_code,
            tree,
            lvl,
            param1_raw,
            REGEXP_SUBSTR(param1_path,'[^#]+',1,GREATEST(1,REGEXP_COUNT(param1_path,'[^#]+'))) AS param1_with_last,
            REGEXP_SUBSTR(param1_path,'[^#]+')                                                 AS param1_with_first,
            param2_raw,
            REGEXP_SUBSTR(param2_path,'[^#]+',1,GREATEST(1,REGEXP_COUNT(param2_path,'[^#]+'))) AS param2_with_last,
            REGEXP_SUBSTR(param2_path,'[^#]+')                                                 AS param2_with_first,
            param3_raw,
            REGEXP_SUBSTR(param3_path,'[^#]+',1,GREATEST(1,REGEXP_COUNT(param3_path,'[^#]+'))) AS param3_with_last,
            REGEXP_SUBSTR(param3_path,'[^#]+')                                                 AS param3_with_first,
            param4_raw,
            REGEXP_SUBSTR(param4_path,'[^#]+',1,GREATEST(1,REGEXP_COUNT(param4_path,'[^#]+'))) AS param4_with_last,
            REGEXP_SUBSTR(param4_path,'[^#]+')                                                 AS param4_with_first
      FROM  hierarchy
      ORDER BY unit_code
    UNIT_ TREE              LVL PARAM1_RAW       PARAM1_WITH_LAST PARAM1_WITH_FIRS PARAM2_RAW       PARAM2_WITH_LAST PARAM2_WITH_FIRS PARAM3_RAW       PARAM3_WITH_LAST PARAM3_WITH_FIRS PARAM4_RAW       PARAM4_WITH_LAST PARAM4_WITH_FIRS
    00000 00000               1 Default value    Default value    Default value    Default value    Default value    Default value    Default value    Default value    Default value
    10      10                2                  Default value    Default value    Value from 10    Value from 10    Default value    Value from 10    Value from 10    Default value
    10-01     10-01           3                  Default value    Default value                     Value from 10    Default value    Value from 10-01 Value from 10-01 Default value
    10-02     10-02           3                  Default value    Default value                     Value from 10    Default value                     Value from 10    Default value    Value from 10-02 Value from 10-02 Value from 10-02
    20      20                2 Value from 20    Value from 20    Default value    Value from 20    Value from 20    Default value    Value from 20    Value from 20    Default value
    20-01     20-01           3                  Value from 20    Default value    Value from 20-01 Value from 20-01 Default value                     Value from 20    Default value
    20-02     20-02           3                  Value from 20    Default value    Value from 20-02 Value from 20-02 Default value                     Value from 20    Default value
    7 rows selected.
    SQL>  SY.
    Edited by: Solomon Yakobson on Nov 12, 2010 10:09 AM

Maybe you are looking for

  • Issue with XML encoding

    Hi, I am querying an SAP instance for data, and I am getting back the data in an XML document...to which I need apply XSL transformation. The instance is an German one... so I am getting a few strange characters because of which, the parser is uanble

  • Active Directory

    I've several apex applications that use LDAP (Active Directory) authentication. I don't need any bind DN - a generic AD account allowed for querying LDAP information - at all in order to authenticate users. I heard that OBIEE does require a bind DN w

  • Mac Trackpad not working right

    I have the 'Tap to Touch' feature on my trackpad, but every now and then, more often than not, when I bring my computer back up from sleep, the trackpad 'Tap to Touch' feature stops working, and I have to go back into the system preferences, UNCHECK

  • Splitting an A3 page into 2 A4s

    Hi! I'm a journalist and after publication of the magazine, my editor sends me my articles in pdf format to use in my portfolio. The problem is, when the article is longer than one page, they send me the pdfs with 2 pages as one - an A3 instead of tw

  • I had some computer problems and now MainStage is gone. How do i retrieve it?

    I had my computer quite working because it was full . i backed it up and now Main stage is gone. I have gone into apps that I bought and there is nothing in there