Hierarchical sys_connect_by_path query needing to process child results
Application Express 4.0.2.00.06 - DB 10.2
Hello all!
I work for an organization having rooms, each with a defined relationship to some or all of the other rooms (some higher, some lower) which must be observed by personnel moving between them.
I've been tasked with writing an page(extending an existing app in which the relationships are managed) in which if a user provide a list of rooms they wish to visit, a list of hierarchy options will be provided based on the relationship rules between rooms.
It is implied that given a sourcename/destname pair, sourcename can go to destname and the inverse is also true (destname can come/receive from sourcename)
This is my sample data set (heavily filtered from actual data);
SOURCE_ROOMID SOURCENAME DEST_ROOMID DESTNAME
28 Ax1 76 G3A
28 Ax1 27 FGB44
58 MP23 27 FGB44
58 MP23 104 MP22
58 MP23 76 G3A
76 G3A 27 FGB44
104 MP22 76 G3A
104 MP22 58 MP23Using this query, I'm able to build the beginning of my hierarchy.
SELECT DISTINCT source_roomid,
sourcename,
dest_roomid,
destname,
sourcename|| ',' ||REVERSE(sys_connect_by_path(REVERSE(destname),',')) path,
(REVERSE(sys_connect_by_path(REVERSE(sourcename),',')))parents,
(REVERSE(sys_connect_by_path(REVERSE(destname),',')))children
FROM (SELECT source_roomid, A.NAME AS sourcename, dest_roomid, b.NAME AS destname
FROM rm_approved_room_state, rm_room A, rm_room b
WHERE source_roomid IN (27, 28, 58, 76, 104)
AND dest_roomid IN (27, 28, 58, 76, 104)
AND a.roomid = source_roomid
AND b.roomid = dest_roomid)
--START WITH source_roomid IN (27, 28, 58, 76, 104)
CONNECT BY NOCYCLE PRIOR source_roomid = dest_roomid
order by 1And my initial result set is:
SOURCE_ROOMID SOURCENAME DEST_ROOMID DESTNAME PATH PARENTS CHILDREN
28 Ax1 27 FGB44 Ax1,FGB44, Ax1, FGB44,
28 Ax1 76 G3A Ax1,G3A, Ax1, G3A,
28 Ax1 76 G3A Ax1,G3A,FGB44, Ax1,G3A, G3A,FGB44,
58 MP23 27 FGB44 MP23,FGB44, MP23, FGB44,
58 MP23 76 G3A MP23,G3A, MP23, G3A,
58 MP23 76 G3A MP23,G3A,FGB44, MP23,G3A, G3A,FGB44,
58 MP23 104 MP22 MP23,MP22, MP23, MP22,
58 MP23 104 MP22 MP23,MP22,G3A, MP23,MP22, MP22,G3A,
58 MP23 104 MP22 MP23,MP22,G3A,FGB44, MP23,MP22,G3A, MP22,G3A,FGB44,
58 MP23 104 MP22 MP23,MP22,MP23, MP23,MP22, MP22,MP23,
76 G3A 27 FGB44 G3A,FGB44, G3A, FGB44,
104 MP22 58 MP23 MP22,MP23, MP22, MP23,
104 MP22 58 MP23 MP22,MP23,FGB44, MP22,MP23, MP23,FGB44,
104 MP22 58 MP23 MP22,MP23,G3A, MP22,MP23, MP23,G3A,
104 MP22 58 MP23 MP22,MP23,G3A,FGB44, MP22,MP23,G3A, MP23,G3A,FGB44,
104 MP22 58 MP23 MP22,MP23,MP22, MP22,MP23, MP23,MP22,
104 MP22 76 G3A MP22,G3A, MP22, G3A,
104 MP22 76 G3A MP22,G3A,FGB44, MP22,G3A, G3A,FGB44,The challenge for me is that for the hierarchy to be correct, every hierarchy row where level >= 2 needs a check to determine if the latest child can receive from the previous child otherwise filter those lines out. Also, paths where there is duplicated data needs to be removed leaving the longest heirarchy intact.
SOURCE_ROOMID SOURCENAME DEST_ROOMID DESTNAME PATH PARENTS CHILDREN
28 Ax1 27 FGB44 Ax1,FGB44, Ax1, FGB44,
(****THE NEXT LINE IS NOT NECESSARY BECAUSE THE NEXT LINE ALREADY CONTAINS THIS HIERARCHY DATA****)
28 Ax1 76 G3A Ax1,G3A, Ax1, G3A,
28 Ax1 76 G3A Ax1,G3A,FGB44, Ax1,G3A, G3A,FGB44,I also need to pull out instances of where rooms related to each other as in this case.
SOURCE_ROOMID SOURCENAME DEST_ROOMID DESTNAME PATH PARENTS CHILDREN
104 MP22 58 MP23 MP22,MP23,MP22, MP22,MP23, MP23,MP22,Leaving this as the anticipated output.
SOURCE_ROOMID SOURCENAME DEST_ROOMID DESTNAME PATH PARENTS CHILDREN
28 Ax1 27 FGB44 Ax1,FGB44, Ax1, FGB44,
28 Ax1 76 G3A Ax1,G3A,FGB44, Ax1,G3A, G3A,FGB44,
58 MP23 27 FGB44 MP23,FGB44, MP23, FGB44,
58 MP23 76 G3A MP23,G3A,FGB44, MP23,G3A, G3A,FGB44,
58 MP23 104 MP22 MP23,MP22,G3A, MP23,MP22, MP22,G3A,
76 G3A 27 FGB44 G3A,FGB44, G3A, FGB44,
104 MP22 58 MP23 MP22,MP23,G3A, MP22,MP23, MP23,G3A,
104 MP22 76 G3A MP22,G3A, MP22, G3A,Any thoughts on how I might get these last three things done in my hierarchy example?
Many thanks in advance!
Paul
Edited by: pgtaviator on Nov 9, 2011 4:34 PM
Hi, Paul,
Sorry, it's unclear what you want.
pgtaviator wrote:
Application Express 4.0.2.00.06 - DB 10.2
Hello all!
I work for an organization having rooms, each with a defined relationship to some or all of the other rooms (some higher, some lower) which must be observed by personnel moving between them.
I've been tasked with writing an page(extending an existing app in which the relationships are managed) in which if a user provide a list of rooms they wish to visit, a list of hierarchy options will be provided based on the relationship rules between rooms.
It is implied that given a sourcename/destname pair, sourcename can go to destname and the inverse is also true (destname can come/receive from sourcename)If "the inverse is also true", why don't the desired results include any paths such as
G3A,Ax1 or
FGB44,MP23,MP22 ?
This is my sample data set (heavily filtered from actual data);
SOURCE_ROOMID SOURCENAME DEST_ROOMID DESTNAME
28 Ax1 76 G3A
28 Ax1 27 FGB44
58 MP23 27 FGB44
58 MP23 104 MP22
58 MP23 76 G3A
76 G3A 27 FGB44
104 MP22 76 G3A
104 MP22 58 MP23
Please post CREATE TABLE and INSERT statements for the sample data.
Is this de-normalized data? That is, does roomid=28 always correspond to name='Ax1', and name='Ax1' always correspond to roomid=28? If not, include examples in your sample data and results, and explain.
Using this query, I'm able to build the beginning of my hierarchy.
SELECT DISTINCT source_roomid,
sourcename,
dest_roomid,
destname,
sourcename|| ',' ||REVERSE(sys_connect_by_path(REVERSE(destname),',')) path,
(REVERSE(sys_connect_by_path(REVERSE(sourcename),',')))parents,
(REVERSE(sys_connect_by_path(REVERSE(destname),',')))children
FROM (SELECT source_roomid, A.NAME AS sourcename, dest_roomid, b.NAME AS destname
FROM rm_approved_room_state, rm_room A, rm_room b
WHERE source_roomid IN (27, 28, 58, 76, 104)
AND dest_roomid IN (27, 28, 58, 76, 104)
AND a.roomid = source_roomid
AND b.roomid = dest_roomid)
--START WITH source_roomid IN (27, 28, 58, 76, 104)
CONNECT BY NOCYCLE PRIOR source_roomid = dest_roomid
order by 1
Thanks for posting the existing query; that's very helpful.
REVERSE is not a documented Oracle function. Using undocumneted functions isn't a very good idea. In this case, can't you just change the CONNECT BY clause to:
CONNECT BY NOCYCLE source_roomid = PRIOR dest_roomidto get the results you want?
And my initial result set is:
SOURCE_ROOMID SOURCENAME DEST_ROOMID DESTNAME PATH PARENTS CHILDREN
28 Ax1 27 FGB44 Ax1,FGB44, Ax1, FGB44,
28 Ax1 76 G3A Ax1,G3A, Ax1, G3A,
28 Ax1 76 G3A Ax1,G3A,FGB44, Ax1,G3A, G3A,FGB44,
58 MP23 27 FGB44 MP23,FGB44, MP23, FGB44,
58 MP23 76 G3A MP23,G3A, MP23, G3A,
58 MP23 76 G3A MP23,G3A,FGB44, MP23,G3A, G3A,FGB44,
58 MP23 104 MP22 MP23,MP22, MP23, MP22,
58 MP23 104 MP22 MP23,MP22,G3A, MP23,MP22, MP22,G3A,
58 MP23 104 MP22 MP23,MP22,G3A,FGB44, MP23,MP22,G3A, MP22,G3A,FGB44,
58 MP23 104 MP22 MP23,MP22,MP23, MP23,MP22, MP22,MP23,
76 G3A 27 FGB44 G3A,FGB44, G3A, FGB44,
104 MP22 58 MP23 MP22,MP23, MP22, MP23,
104 MP22 58 MP23 MP22,MP23,FGB44, MP22,MP23, MP23,FGB44,
104 MP22 58 MP23 MP22,MP23,G3A, MP22,MP23, MP23,G3A,
104 MP22 58 MP23 MP22,MP23,G3A,FGB44, MP22,MP23,G3A, MP23,G3A,FGB44,
104 MP22 58 MP23 MP22,MP23,MP22, MP22,MP23, MP23,MP22,
104 MP22 76 G3A MP22,G3A, MP22, G3A,
104 MP22 76 G3A MP22,G3A,FGB44, MP22,G3A, G3A,FGB44,The challenge for me is that for the hierarchy to be correct, every hierarchy row where level >= 2 needs a check to determine if the latest child can receive from the previous child otherwise filter those lines out.I don't understand the requirement above at all.
Also, paths where there is duplicated data needs to be removed leaving the longest heirarchy intact.
SOURCE_ROOMID SOURCENAME DEST_ROOMID DESTNAME PATH PARENTS CHILDREN
28 Ax1 27 FGB44 Ax1,FGB44, Ax1, FGB44,
(****THE NEXT LINE IS NOT NECESSARY BECAUSE THE NEXT LINE ALREADY CONTAINS THIS HIERARCHY DATA****)
28 Ax1 76 G3A Ax1,G3A, Ax1, G3A,
28 Ax1 76 G3A Ax1,G3A,FGB44, Ax1,G3A, G3A,FGB44,
Are you using "THE NEXT LINE" to mean 2 different things? Do you mean "The line with Ax1,G3A is not wanted because it is a sub-path of Ax1,G3A,FGB44"?
Why do the desired results include
MP22,G3A (which is a sub-path of MP23.MP22,G3A) and
G3A,FGB44 (which is a sub-path of both Ax1,G3A,FGB44 and MP23,G3A,FGB44)?
I also need to pull out instances of where rooms related to each other as in this case.
SOURCE_ROOMID SOURCENAME DEST_ROOMID DESTNAME PATH PARENTS CHILDREN
104 MP22 58 MP23 MP22,MP23,MP22, MP22,MP23, MP23,MP22,
When you way "rooms related to each other", do you mean "rooms related to themselves"? It looks like you're saying that no room can occur 2 (or more) times in any path.
Leaving this as the anticipated output.
SOURCE_ROOMID SOURCENAME DEST_ROOMID DESTNAME PATH PARENTS CHILDREN
28 Ax1 27 FGB44 Ax1,FGB44, Ax1, FGB44,
28 Ax1 76 G3A Ax1,G3A,FGB44, Ax1,G3A, G3A,FGB44,
58 MP23 27 FGB44 MP23,FGB44, MP23, FGB44,
58 MP23 76 G3A MP23,G3A,FGB44, MP23,G3A, G3A,FGB44,
58 MP23 104 MP22 MP23,MP22,G3A, MP23,MP22, MP22,G3A,
76 G3A 27 FGB44 G3A,FGB44, G3A, FGB44,
104 MP22 58 MP23 MP22,MP23,G3A, MP22,MP23, MP23,G3A,
104 MP22 76 G3A MP22,G3A, MP22, G3A,
Why do 3 of the paths end at G3A? Why don't they continue to FGB44 as 2 of the paths do?
Why is MP23,G3A,FGB44 in the desired output, and not MP22,MP23,G3A,FGB44 (which is longer)?
Why isn't MP22,MP23,FGB44 in the desired results, but its sub-path MP23,FGB44 is?
Try describing what you're trying to show in this query, and what each row of the desired result set represents. As far as possible, avoid repeating the explanation you're already used. (Not that there's anything wrong with what you've said so far; it's just that I need all the help I can get to understand the probhlem.)
Any thoughts on how I might get these last three things done in my hierarchy example?It looks like CONNECT_BY_ISLEAF, and maybe CONNECT_BY_ISCYCLE could help in this problem.
Regular expressions, or perhaps LIKE, might help in detecting if one path contains another.
Many thanks in advance!
Paul
Edited by: pgtaviator on Nov 9, 2011 4:34 PM
Similar Messages
-
We need to ask you to complete a short and brief step to securing and validating your account information.
Click here to complete validation
Failure to complete our validation process will result in a suspension of your Apple ID.You are welcome. The emails are difficult to block effectively, because the spammer/phishers continually fake their sending email address. You can, however forward the email to Apple.
[email protected] -
Monitoring via WMI - query needs a long time to get a result
Hi experts!
I am using Icinga (Nagios Fork) and a plugin called check_wmi_plus.pl (Perl Skript) which uses the wmic linux implementation.
I have now multiple servers which needs very long to answer. I am using exactly the same command on the hosts. I give you an example here:
Server-A: WMI query needs ~70 Seconds, Ping Time is ~0.5-2.0 ms
Server-B: WMI query needs ~9 Seconds, Ping Time is ~90-120 ms
I ran exactly the same command, from the same host, with the same user credentials and they are on the same domain.
This behavior is not by the operting system because I have 2008r2 and 2003 servers which do both, need short and long time. They are all in different locations so there seems not to be a network issue. Hosts that are having the problems are 2008 hyper-v
hosts but also 2003 file servers.. so I dont see any match here.
I dont know how to go ahead, where to start the next troubleshooting steps?
Is there any WMI log on the server I can monitor?
Any help or ideas would be great! Thanks in advance!
cheers, Duffkessthis issue
might related to the network issues, please check the Receive Side Scaling and
the TCP Chimney registry settings. If TCP Chimney was enabled along with the
RSS setting, WMI would fail. <o:p></o:p>
Meanwhile
please test if the local basic WMI query also slow by
Administrator account.<o:p></o:p>
a. Run wbemtest, connect the namespace
root\cimv2<o:p></o:p>
b. Click Query… and enter query as: Select * from
Win32_ComputerSystem. <o:p></o:p>
c. Note down how many seconds does the query take.<o:p></o:p>
Please also test if the remote basic WMI query is slow by
Administrator account.<o:p></o:p>
a. Run wbemtest, connect the namespace
\\machinename\root\cimv2<o:p></o:p>
b. Click Query… and enter query as: Select * from
Win32_ComputerSystem. <o:p></o:p>
c. Note down how many seconds does the query take.<o:p></o:p>
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. -
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 -
Can you run a Query in a Process Chain?
As part of a data validation process chain, I need to run a query and send the results by email. I've created the query (with the exception) and set it up in information broadcaster to be sent by email. I thought that I would be able to just drop in the "Exception Reporting" process into the process chain and be able to select the query to run. Needless to say, it don't work that way.
If anyone has ran a query in a process chain, please let me know how you did it?
Also if someone knows how the "Exception Reporting" process in RSPC works, please share?
ThanksPatel, we may be able to rethink our approach and use the event data change that was mentioned in the document you sent.
I was hoping to be able to do everything from within a process chain. Does anyone know how to use the "Exception Reporting" process that is available in RSPC? Is it a leftover from the 3.X days that can't really be used in 7.0? -
Process the result so that the dates are ordered by date
I am retrieving a query result from a sql database of which
one column contains a string of this format:
09/08/2008
How can I process this result so that the dates are ordered
by date?
Thanks for anu help :)what's your db and version?
pretty much all dbs have built-in string and date functions,
a
combinations of which will let you update your field to be
date/datetime.
you will probably want to create a new field in the table to
store the
converted dates, then check that they all have been converted
correctly,
then delete the current date field and rename the new field
to the old
date field's name.
using your db's string functions you will need to extract
day, month and
year parts of your date text, and pass them to your db's date
creation
function.
if your db is MySQL, it has a very handy STR_TO_DATE(str,
format)
function... check details in mysql ref manual.
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/ -
Function used in SQL query not showing the desired results
I have created a function that gives me the client id but when i am using the function in the query its not giving me any result i.e. 0 rows but if I execute the function sepreatly and put the result of that function in the qurey it is giving me the desired result please have a look on the following and please reply with you expert opinion:
FUNCTION CODE:
create or replace function j2
(usid in varchar2)
return varchar2
is
cidn_in varchar2(4000) := '';
ls_sep varchar2(1) := ',';
cursor predicate_cidn
is
select
logical_schema_id
from
CLIENT_REGISTRY cr,
MEMBER_ROLE_CLIENT_ASSIGNMENT mrca,
MEMBER m
where
mrca.base_client_id = cr.base_client_id and
mrca.member_id = m.member_id and
cr.schema_in_use_in = '1' and
m.active_status_id = 'A' and
upper(mrca.member_id) = upper(usid);
BEGIN
for GET_CIDN in predicate_cidn
loop
cidn_in := cidn_in || ls_sep || '''' || GET_CIDN.logical_schema_id || '''';
end loop;
cidn_in := substr(cidn_in, 2);
cidn_in := '('||cidn_in||')';
--dbms_output.put_line(cidn_in);
return cidn_in;
END ;
SQL> select j2('qaa@adp') from dual;
J2('QAA@ADP')
('BASE18','SDK1TEST','SEETHA1CONFIG','BASE09','KAREN2','SIVACONFIG','BASE19','SD
K1CTEST','VASU1','KAREN5','EVENTS1CTEST','SDK1','ADA1CONFIG','BASE10','VRB1CONFI
G','CRU2CONFIG','BASE20','SIVATEST','PCOMCONFIG','KP1CONFIG','KAREN4CONFIG','EVE
NTS1TEST','SUZ3CONFIG','DONG2CONFIG','ED2CONFIG','SIVACTEST','APDCONFIG','EVENTS
1CONFIG','ESSCONFIG','SIVA','SDK2CONFIG','ED3CONFIG','RAJ4CONFIG','CBRCONFIG','N
AMRATA2CONFIG','EMIL1','NAMRATA1CONFIG','SDK2CTEST','BVT2CONFIG','MURUGAN1CONFIG
','COB1CONFIG','GABY1TEST','CHR1CONFIG','ED4CONFIG','USE1CONFIG','SDK2TEST','DEM
O1CONFIG','BERNIE1CONFIG','XA1','CAR2TEST','SDK2','ED5CONFIG','PAY1TEST','PAYXCO
NFIG','KP1TEST','SEAN1CONFIG','CAR2CTEST','VASU1CONFIG','SEAN2CONFIG','KP1CTEST'
,'MAU1CONFIG','CONWCONFIG','PAN1CONFIG','MERAJ2','PRA3CONFIG','SEAN5CONFIG','KP1
','PRA4CONFIG','CAR2CONFIG','PRA2CONFIG','SEAN6CONFIG','PRA3TEST','RPT','GABY1CT
EST','SDK3CONFIG','PRA2TEST','SEAN9CONFIG','CAR2','LV1CONFIG','PRA3CTEST','DONG1
CONFIG','TE1CONFIG','MERAJ2CONFIG','VIV1CONFIG','GABY1','SEAN2','PRA2CTEST','PRA
3','RPTCONFIG','PRA4CTEST','SEAN3','MITA1CONFIG','PRA2','RPTCTEST','PCOM1CONFIG'
,'SS2CONFIG','PAY1CONFIG','SEAN7','ANNCONFIG','BASE11','BASE02','LV2CONFIG','RPT
TEST','IMPECONFIG','SUR1CONFIG','SREEK2CONFIG','BASE03','SRINU3CONFIG','BDCONFIG
','JAY1CONFIG','AMMAN1','PRA1TEST','WPGCONFIG','BASE12','MP5CONFIG','MERAJ1','SR
INU2CONFIG','XA1CONFIG','RAJ1CONFIG','WPGCTEST','BASE04','CHRIS','RAJSCONFIG','P
ANKAJ','BASE13','WPGTEST','RAJ3CONFIG','WPG','BASE14','VASU2CONFIG','SRINU1CONFI
G','BASE05','PRA4TEST','VASU1TEST','PRA5CONFIG','NISH1CONFIG','CHRISCONFIG','SDK
3TEST','RAJ3TEST','KP2CONFIG','BASE06','DEFPCONFIG','NISH2CONFIG','CHRISCTEST','
WPSCONFIG','VASU2TEST','BASE15','GABY1CONFIG','PRA5TEST','MITA2CONFIG','BASE07',
'VASU1CTEST','KP2TEST','VASU2CTEST','LAURA3CONFIG','BASE16','CHRISTEST','WPSTEST
','VASU2','KP2CTEST','EVENTS1','BASE17','RAJ2CONFIG','WPSCTEST','BASE08','SREEK1
CONFIG','ADVE','PRA4','SDK1CONFIG','KP2','KAREN1','CRU1CONFIG','WPS')
Now if i put the results (cut and paste )in the query it gives me the results
SQL> select count(*) from baseclient.address_detail where cidn in ('BASE18','SDK1TEST','SEETHA1CONFIG','BASE09','KAREN2','SIVACONFIG','BASE19','SD
2 K1CTEST','VASU1','KAREN5','EVENTS1CTEST','SDK1','ADA1CONFIG','BASE10','VRB1CONFI
3 G','CRU2CONFIG','BASE20','SIVATEST','PCOMCONFIG','KP1CONFIG','KAREN4CONFIG','EVE
4 NTS1TEST','SUZ3CONFIG','DONG2CONFIG','ED2CONFIG','SIVACTEST','APDCONFIG','EVENTS
5 1CONFIG','ESSCONFIG','SIVA','SDK2CONFIG','ED3CONFIG','RAJ4CONFIG','CBRCONFIG','N
6 AMRATA2CONFIG','EMIL1','NAMRATA1CONFIG','SDK2CTEST','BVT2CONFIG','MURUGAN1CONFIG
7 ','COB1CONFIG','GABY1TEST','CHR1CONFIG','ED4CONFIG','USE1CONFIG','SDK2TEST','DEM
O1CONFIG','BERNIE1CONFIG','XA1','CAR2TEST','SDK2','ED5CONFIG','PAY1TEST','PAYXCO
8 9 NFIG','KP1TEST','SEAN1CONFIG','CAR2CTEST','VASU1CONFIG','SEAN2CONFIG','KP1CTEST'
10 ,'MAU1CONFIG','CONWCONFIG','PAN1CONFIG','MERAJ2','PRA3CONFIG','SEAN5CONFIG','KP1
11 ','PRA4CONFIG','CAR2CONFIG','PRA2CONFIG','SEAN6CONFIG','PRA3TEST','RPT','GABY1CT
12 EST','SDK3CONFIG','PRA2TEST','SEAN9CONFIG','CAR2','LV1CONFIG','PRA3CTEST','DONG1
13 CONFIG','TE1CONFIG','MERAJ2CONFIG','VIV1CONFIG','GABY1','SEAN2','PRA2CTEST','PRA
14 3','RPTCONFIG','PRA4CTEST','SEAN3','MITA1CONFIG','PRA2','RPTCTEST','PCOM1CONFIG'
15 ,'SS2CONFIG','PAY1CONFIG','SEAN7','ANNCONFIG','BASE11','BASE02','LV2CONFIG','RPT
16 TEST','IMPECONFIG','SUR1CONFIG','SREEK2CONFIG','BASE03','SRINU3CONFIG','BDCONFIG
17 ','JAY1CONFIG','AMMAN1','PRA1TEST','WPGCONFIG','BASE12','MP5CONFIG','MERAJ1','SR
18 INU2CONFIG','XA1CONFIG','RAJ1CONFIG','WPGCTEST','BASE04','CHRIS','RAJSCONFIG','P
19 ANKAJ','BASE13','WPGTEST','RAJ3CONFIG','WPG','BASE14','VASU2CONFIG','SRINU1CONFI
20 G','BASE05','PRA4TEST','VASU1TEST','PRA5CONFIG','NISH1CONFIG','CHRISCONFIG','SDK
21 3TEST','RAJ3TEST','KP2CONFIG','BASE06','DEFPCONFIG','NISH2CONFIG','CHRISCTEST','
22 WPSCONFIG','VASU2TEST','BASE15','GABY1CONFIG','PRA5TEST','MITA2CONFIG','BASE07',
23 'VASU1CTEST','KP2TEST','VASU2CTEST','LAURA3CONFIG','BASE16','CHRISTEST','WPSTEST
24 ','VASU2','KP2CTEST','EVENTS1','BASE17','RAJ2CONFIG','WPSCTEST','BASE08','SREEK1
25 CONFIG','ADVE','PRA4','SDK1CONFIG','KP2','KAREN1','CRU1CONFIG','WPS');
COUNT(*)
228
BUT if I user the function it gives me no results
0 rows selected and its taking a loon time to reurnThis appears to be a duplicate of the question in this thread
Re: VPD issue Need Assistance ASAP
where I wrote
"Your function returns a single string that happens to have a bunch of commas and quotes in it. An IN list generally requires a list of strings, which your function doesn't return.
You could rewrite the function to be a pipelined table function and then do
select count(*)
from baseclient.address_detail
where cidn in (SELECT cidn
FROM TABLE(<<your pipelined table function>>))
However, I would expect it to be easier not to wrap all this into a function and just have your IN clause be the logic in your predicate_cidn cursor.
Justin
" -
Reg: SQL select Query in BPEL process flow
<p>
Hi,
I am suppose to execute a SQL select query (in BPEL Process flow) as mention below in JDeveloper using Database adapter.
</p>
<p>
SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
</p>
<p>
LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
</p>
<p>
FROM CUBE
</p>
<p>
WHERE ITEM= <xyz>
</p>
<p>
AND OBJECT= (SELECT CASE_NAME FROM CUBE_SUPPLIER WHERE ITEM=<xyz> AND SUPP_IND = ‘Y')
<strong>Now my question is:
1.</strong> What does this "*" refer to in the query and how can I retrieve the value of LENGTH*WIDTH* HEIGHT from the query where LENGTH,WIDTH and HEIGHT are the individual field in the table.
2.What does this " AS" refer to? If " ITEM_CUBE " is the alies for the table name "ITEM" to retrieve the value, then query shoud be evaluated as
</p>
<p>
SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
</p>
<p>
LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
</p>
<p>
FROM CUBE
</p>
<p>
WHERE <strong>ITEM_CUBE.ITEM</strong>= <xyz>
</p>
<p>
AND <strong>ITEM_CUBE.OBJECT</strong>= (SELECT CASE_NAME FROM CUBE_SUPPLIER WHERE ITEM=<xyz> AND SUPP_IND = ‘Y')
Is my assumption correct?
Please suggest asap.
Thanks...
</p>
<p>
</p>Hi
Thank for your reply!
I have a nested select query which performs on two different table as shown below:
<p>
SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
</p>
<p>
LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
</p>
<p>
FROM CUBE
</p>
<p>
WHERE ITEM= <abc>
</p>
<p>
AND OBJECT= (SELECT NAME FROM SUPPLIER WHERE ITEM=<Item> AND SUPP_IND = ‘Y')
I am using DB adapter of Oracle JDeveloper in BPEL process flow, where I can able to select only one master table in DB adapter say SUPPLIER and its attributes at a time.But as per my requirment I need to select both the table (CUBE and SUPPLIER) in a single adapter to execute my query.
It can be achievable by using two DB adapter , One to execute the nested query and another to execute the main qyery considering value of nested query as a parameter.But I want to achieve it by using a single one.
Am I correct with my concept?
Please suggest how to get it ?
</p>
Edited by: user10259700 on Oct 23, 2008 12:17 AM -
Executing Abap Queries in Abap Code and processing the result
Hi,
I want to execute ABAP Queries (designed by sq01) in an abap report and processing the result in an internal table.
How could it be work?
Thanks a lot for your responses,
with kind Regards
Reinhold StroblHello,
GO to SQ01 and select your query. Go to Menu QUERY-->More Functions->Display Report Name.
You can then take that report name and go to SE38. Copy the code before END-OF_SELECTION and then modify as per your own requirements.
Regrads
Saket Sharma -
BW Authorizations - Query variable with processing mode as "customer exit"
Hi,
Iam new to BW authorizations and have not yet worked on customer exit before. I was going through the documentation at various sites but I could not get the end to end description on how the query process( when using a variable for an InfoObject) works in case of customer exit.
Let's assume that I am using a query variable with processing mode as "customer exit" and at the exit I write some code to extract user's authorizations from a z table. if this is the case, then when an end user runs a query,how will the the system know what value needs to be filled in the variable for the requesting user. Are the user details also sent to the code along with the query variable? If so how. If I mis-understood the process then forgive me and let me know the correct process.Hi!
welcome to SDN!
customer exit variables need programing by user. so if you create a customer exit variable, you got to right a program which extracts values into this variable. we can do what ever we want in program, SAP will not deal anything ´with customer exits.
with regards
ashwin
PS n: Assigning point to the helpful answers is the way of saying thanks in SDN. you can assign points by clicking on the appropriate radio button displayed next to the answers for your question. yellow for 2, green for 6 points(2)and blue for 10 points and to close the question and marked as problem solved. closing the threads which has a solution will help the members to deal with open issues with out wasting time on problems which has a solution and also to the people who encounter the same porblem in future. This is just to give you information as you are a new user. -
Execute the same query twice, get two different results
I have a query that returns two different results:
Oracle Version : 10.2.0.1.0
I am running the following query on the Oracle server in SQL*Plus Worksheet.
SELECT COUNT(*)
FROM AEJOURNAL_S1
WHERE CHAR_TIME BETWEEN TO_DATE('12-AUG-10 01:17:39 PM','DD-MON-YY HH:MI:SS AM') AND
TO_DATE('13-AUG-10 14:17:34','DD-MON-YY HH24:MI:SS')
AND DESC2 LIKE '%'
AND DESC1 LIKE '%'
AND DESC2 LIKE '%'
AND ETYPE LIKE '%'
AND MODULE LIKE '%'
AND LEVELL = '11-WARNING'
ORDER BY ORDD DESC;
The very first time the query is run, it will return a count of 259. The next time the query is run, lets say, 10 seconds later, it will return a count of 260. The above query is exemplary of the kind of thing I'm trying to do. It seems like the more fields filtered against '%', the more random the count return becomes. Sometime you have to execute the query three or four times before it levels out to a consistent number.
I'm using '%' as the default for various fields, because this was the easiest thing to do to support a data-driven Web interface. Maybe I have to 'dynamically' build the entire where clause, instead of just parameterizing the elements and having default '%'. Anyway, to eliminate the web interface for the purpose of troubleshooting the above query was run directly on the Oracle server.
This query runs against a view. The view does a transpose of data from a table.
Below is the view AEJOURNAL_S1
SELECT
CHAR_TIME,
CHAR_INST,
BATCH_ID,
MIN(DECODE(CHAR_ID,6543,CHAR_VALUE)) AS ORDD,
MIN(DECODE(CHAR_ID,6528,CHAR_VALUE)) AS AREAA,
MIN(DECODE(CHAR_ID,6529,CHAR_VALUE)) AS ATT,
COALESCE(MIN(DECODE(CHAR_ID,6534,CHAR_VALUE)),'N/A') AS CATAGORY,
MIN(DECODE(CHAR_ID,6535,CHAR_VALUE)) AS DESC1,
MIN(DECODE(CHAR_ID,6536,CHAR_VALUE)) AS DESC2,
MIN(DECODE(CHAR_ID,6537,CHAR_VALUE)) AS ETYPE,
MIN(DECODE(CHAR_ID,6538,CHAR_VALUE)) AS LEVELL,
MIN(DECODE(CHAR_ID,6539,CHAR_VALUE)) AS MODULE,
MIN(DECODE(CHAR_ID,6540,CHAR_VALUE)) AS MODULE_DESCRIPTION,
MIN(DECODE(CHAR_ID,6541,CHAR_VALUE)) AS NODE,
MIN(DECODE(CHAR_ID,6542,CHAR_VALUE)) AS STATE,
MIN(DECODE(CHAR_ID,6533,CHAR_VALUE)) AS UNIT
FROM CHAR_BATCH_DATA
WHERE subbatch_id = 1774
GROUP BY CHAR_TIME, CHAR_INST, BATCH_ID
So... why does the query omit rows on the first execution? Is this some sort of optimizer issue. Do I need to rebuild indexes? I looked at the indexes, they are all valid.
Thanks for looking,
Danuser2188367 wrote:
I have a query that returns two different results:
Oracle Version : 10.2.0.1.0
I am running the following query on the Oracle server in SQL*Plus Worksheet.
SELECT COUNT(*)
FROM AEJOURNAL_S1
WHERE CHAR_TIME BETWEEN TO_DATE('12-AUG-10 01:17:39 PM','DD-MON-YY HH:MI:SS AM') AND
TO_DATE('13-AUG-10 14:17:34','DD-MON-YY HH24:MI:SS')
AND DESC2 LIKE '%'
AND DESC1 LIKE '%'
AND DESC2 LIKE '%'
AND ETYPE LIKE '%'
AND MODULE LIKE '%'
AND LEVELL = '11-WARNING'
ORDER BY ORDD DESC;
The very first time the query is run, it will return a count of 259. The next time the query is run, lets say, 10 seconds later, it will return a count of 260. The above query is exemplary of the kind of thing I'm trying to do. It seems like the more fields filtered against '%', the more random the count return becomes. Sometime you have to execute the query three or four times before it levels out to a consistent number.
I'm using '%' as the default for various fields, because this was the easiest thing to do to support a data-driven Web interface. Maybe I have to 'dynamically' build the entire where clause, instead of just parameterizing the elements and having default '%'. Anyway, to eliminate the web interface for the purpose of troubleshooting the above query was run directly on the Oracle server.
This query runs against a view. The view does a transpose of data from a table.
Below is the view AEJOURNAL_S1
SELECT
CHAR_TIME,
CHAR_INST,
BATCH_ID,
MIN(DECODE(CHAR_ID,6543,CHAR_VALUE)) AS ORDD,
MIN(DECODE(CHAR_ID,6528,CHAR_VALUE)) AS AREAA,
MIN(DECODE(CHAR_ID,6529,CHAR_VALUE)) AS ATT,
COALESCE(MIN(DECODE(CHAR_ID,6534,CHAR_VALUE)),'N/A') AS CATAGORY,
MIN(DECODE(CHAR_ID,6535,CHAR_VALUE)) AS DESC1,
MIN(DECODE(CHAR_ID,6536,CHAR_VALUE)) AS DESC2,
MIN(DECODE(CHAR_ID,6537,CHAR_VALUE)) AS ETYPE,
MIN(DECODE(CHAR_ID,6538,CHAR_VALUE)) AS LEVELL,
MIN(DECODE(CHAR_ID,6539,CHAR_VALUE)) AS MODULE,
MIN(DECODE(CHAR_ID,6540,CHAR_VALUE)) AS MODULE_DESCRIPTION,
MIN(DECODE(CHAR_ID,6541,CHAR_VALUE)) AS NODE,
MIN(DECODE(CHAR_ID,6542,CHAR_VALUE)) AS STATE,
MIN(DECODE(CHAR_ID,6533,CHAR_VALUE)) AS UNIT
FROM CHAR_BATCH_DATA
WHERE subbatch_id = 1774
GROUP BY CHAR_TIME, CHAR_INST, BATCH_ID
So... why does the query omit rows on the first execution? Is this some sort of optimizer issue. Do I need to rebuild indexes? I looked at the indexes, they are all valid.
Thanks for looking,
DanIn fact you the first time you ran the query the data has been retrived from disk to memory , in the second time the data is already in memory so the respnse time should be faster ,but if you chagne any condition or column or letter case the optimizer will do the first step (data will be retrived from disk to memory ) -
How much UNDO does a query need?
It seems that due to a gigantic delete, I am running out of UNDO. How can I see exactly how much undo a query needs?
Searching on the web, I found this:
select sq.sql_text sql_text, t.USED_UREC Records, t.USED_UBLK Blocks, (t.USED_UBLK*8192/1024) KBytes from v$transaction t,
v$session s,
v$sql sq
where t.addr = s.taddr
and s.sql_id = sq.sql_id
and s.username = 'blah'
, which is fine, but it seems to be returning results for only running queries. In other words, when the delete query I am investigating is executed, the above select returns no rows. Is there a way to modify it to return also queries that have been executed?
Any help is welcome.
Message was edited by:
user622271Hi,
It seems that you need to make an outer join between v$sql and v$session views [s.sql_id = sq.sql_id(+)] ... For more information is if this [url http://forums.oracle.com/forums/thread.jspa?messageID=1756927�]thread can help you.
Cheers
Legatti -
Query with a condition - Overall results row displays incorrect value
Hi All,
I have a bw query with top 40 conditions. However, The Overall Result Row Figures Do Not Equal The Sum of the Column Rows.
Although the top condition is activated, the overall result still displays the overall result of the whole report.
I have 3 columns in the report
Selected Period
Prior Period and
Variance
The formula for variance is (Selected Period/Prior Period)-1.
Does anyone have an idea to fix this?
Thank you so much in advance.
Have a great day!Hi Gaurav,
Thank you so much for your reply, however this does not solve fully the issue.
Changing the properties to "Summation" will indeed provide me with the correct sum for the "selected period" and "Prior Period." However what I need in the Overall Result Row for the "Variance" column is not the total but instead the value when the total of Selected Period is divided by Prior Period then minus 1.
Overall Variance = (Overall Selected Period/Overall Prior Period)-1
Do you know a way to make this possible.
Thank you so much. -
Trying to form complex query - need help
I have a fairly complex query that I need to join the results of to show actual and goal by day. The actuals are an aggregation of records that get put in every day, while the targets are a single entry in range format indicating an active range for which the target applies. I'm working on a query that will put things together by month and I'm running into a snag. Can someone please point out where appropriate naming needs to go to get this to come together?
This one works:
(select DATE_INDEX, SUM(LDS) as TTLLDS, SUM(TONS) as TTLTONS from
(select DATE_INDEX, VEH_LOC, SUM(LDS) as LDS, SUM(WT) as TONS from
(select c.DATE_INDEX, c.VEH_LOC, COUNT(j.LOAD_JOB_ID) as LDS,
CASE WHEN SUM(w.SPOT_WEIGHT) = 0 THEN SUM(j.MAN_SPOT_WT)
ELSE SUM(w.SPOT_WEIGHT)
END as WT
from TC c, TC_LOAD_JOBS j, LOAD_RATES r, SPOT_WEIGHTS w
where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
and c.DATE_INDEX = w.DATE_INDEX and j.LOAD_RATE_ID = w.LOAD_RATE_ID
and c.VEH_LOC in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
group by c.DATE_INDEX, c.VEH_LOC
union
select c.DATE_INDEX, c.VEH_LOC, COUNT(j.JOB_ID) as LDS,
DECODE(SUM(j.AVG_SPOT_WEIGHT),0,SUM(r.BID_TONS),SUM(j.AVG_SPOT_WEIGHT)) as WT
from TC_3RDPARTY c, TC_3RDPARTY_JOBS j, LOAD_RATES r
where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
and j.FACTORY_ID in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
group by c.DATE_INDEX, c.VEH_LOC)
group by DATE_INDEX, VEH_LOC)
group by DATE_INDEX)Now I need to add in the following query:
select (u.MACH_TPH_D+u.MACH_TPH_N)/2 as MTPH_TGT, (u.LABOR_TPH_D+u.LABOR_TPH_N)/2 as LTPH_TGT
from UTIL_TARGET_LOADERS u
where u.ORG_ID in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)The join needs to be based on VEH_LOC and DAY in the form:
... WHERE u.ORG_ID = x.VEH_LOC
AND x.DATE_INDEX between u.START_DATE and NVL(u.END_DATE,sysdate)I had one that worked just fine when only one entity was involved; the complication arises in that this is a division-level report so I have to individually resolve the subordinates and their goals before I can aggregate. This is one of two queries I need to tie together using a WITH clause so I can pivot the whole thing and present it in month-by-month fashion. When I try to tie it together like the query below, I get: invalid relational operator.
select ttls.DATE_INDEX, SUM(ttls.LDS) as TTLLDS, SUM(ttls.TONS) as TTLTONS, u.TARGET_LTPH, u.TARGET_MTPH
from UTIL_TARGET_LOADERS u,
(select DATE_INDEX, VEH_LOC, SUM(LDS) as LDS, SUM(WT) as TONS from
(select c.DATE_INDEX, c.VEH_LOC, COUNT(j.LOAD_JOB_ID) as LDS,
CASE WHEN SUM(w.SPOT_WEIGHT) = 0 THEN SUM(j.MAN_SPOT_WT)
ELSE SUM(w.SPOT_WEIGHT)
END as WT
from TC c, TC_LOAD_JOBS j, LOAD_RATES r, SPOT_WEIGHTS w
where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
and c.DATE_INDEX = w.DATE_INDEX and j.LOAD_RATE_ID = w.LOAD_RATE_ID
and c.VEH_LOC in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
group by c.DATE_INDEX, c.VEH_LOC
union
select c.DATE_INDEX, c.VEH_LOC, COUNT(j.JOB_ID) as LDS,
DECODE(SUM(j.AVG_SPOT_WEIGHT),0,SUM(r.BID_TONS),SUM(j.AVG_SPOT_WEIGHT)) as WT
from TC_3RDPARTY c, TC_3RDPARTY_JOBS j, LOAD_RATES r
where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
and j.FACTORY_ID in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
group by c.DATE_INDEX, c.VEH_LOC)
group by DATE_INDEX, VEH_LOC) ttls
where ttls.DATE_INDEX beween u.START_DATE and NVL(u.END_DATE,sysdate)
and ttls.VEH_LOC = u.ORG_ID
group by ttls.DATE_INDEXI know this is a nested mess, as it has to grab the production from two tables for a range of VEH_LOC values and sum and aggregate by day and VEH_LOC, then I have to try and match that to the targets based on VEH_LOC and day. My final query is to aggregate the whole mess of sums and averages by month.
I'd appreciate it if someone can point me in the right direction.Figured it out.
select ttl.DATE_INDEX, SUM(ttl.LDS) as TTLLDS, SUM(ttl.TONS) as TTLTONS,
AVG((u.MACH_TPH_D+u.MACH_TPH_N)/2) as MTPH_TGT,
AVG((u.LABOR_TPH_D+u.LABOR_TPH_N)/2) as LTPH_TGT
from
(select DATE_INDEX, VEH_LOC, SUM(LDS) as LDS, SUM(WT) as TONS from
(select c.DATE_INDEX, c.VEH_LOC, COUNT(j.LOAD_JOB_ID) as LDS,
CASE WHEN SUM(w.SPOT_WEIGHT) = 0 THEN SUM(j.MAN_SPOT_WT)
ELSE SUM(w.SPOT_WEIGHT)
END as WT
from TC c, TC_LOAD_JOBS j, LOAD_RATES r, SPOT_WEIGHTS w
where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
and c.DATE_INDEX = w.DATE_INDEX and j.LOAD_RATE_ID = w.LOAD_RATE_ID
and c.VEH_LOC in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
group by c.DATE_INDEX, c.VEH_LOC
union
select c.DATE_INDEX, c.VEH_LOC, COUNT(j.JOB_ID) as LDS,
DECODE(SUM(j.AVG_SPOT_WEIGHT),0,SUM(r.BID_TONS),SUM(j.AVG_SPOT_WEIGHT)) as WT
from TC_3RDPARTY c, TC_3RDPARTY_JOBS j, LOAD_RATES r
where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
and j.FACTORY_ID in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
group by c.DATE_INDEX, c.VEH_LOC)
group by DATE_INDEX, VEH_LOC) ttl, UTIL_TARGET_LOADERS u
where u.ORG_ID = ttl.VEH_LOC
and ttl.DATE_INDEX between u.START_DATE and NVL(U.END_DATE,sysdate)
group by ttl.DATE_INDEX, (u.LABOR_TPH_D+u.LABOR_TPH_N)/2 -
How to add process model results to the sequence file results?
After my sequence file runs, I would like to add some additional results using the process model. I need to log my equipment list which is obtained by the process model. Alternatively, I could add a sub-sequence to the end of each of my sequence files for doing this, but that would create maintenance problems if I ever needed to change the way equipment is logged. Does anyone know a way to (1) append process model results to the sequence file results or (2) force each client sequence file to call a sub-sequence before returning to the process model.
Mark -
The report and database process model routines expect a single subsequence step result that invoked MainSequence. This result contains the results from the sequence call.
In TestStand after the process model root sequence call to MainSequence is performed, the property Locals.ResultList[0] is the MainSequence result. The subproperty Locals.ResultList[0].TS.SequenceCall.ResultList contains the results from the steps in MainSequence.
One option is to create a subsequence call in the process model that logs the equipment info in the results for its steps. The call to the subsequence should not be checked to record results.
This subsequence would have a parameter called ResultList. The Result type does not exist in the Insert menu, so you can only create the parameter by copying the empty Locals.ResultList and pasting it in the parameters. Then change its type from By Value to By Reference.
In the setup of the subsequence, add the following steps which do not record results. These steps rename the Locals.ResultList parameter to ResultListOrig, and then create a new Locals.ResultList alias property that really references Parameters.ResultList. This way any additions to the Locals.ResultList really append to the Parameter.ResultList.
Setup
Step: "Rename Locals.ResultList"
StepType, Adapter: Action, Active-X
Description:
Action, Set PropertyObject.Name = "ResultListORIG"
Record Results: False
Step: "Create Alias in Locals"
StepType, Adapter: Actioin, Active-X
Description:
Action, Call PropertyObject.SetPropertyObject ("ResultList",
0x201 ' Not Owning and Create, Parameters.ResultList)
Record Results: False
In the Main steps, you add your equipment info steps which record results.
In the Cleanup steps you undo the steps performed in Setup.
Cleanup
Step: "Delete Alias in Locals"
StepType, Adapter: Action, Active-X
Description:
Action, Call PropertyObject.DeleteSubProperty ("ResultList",
0x400 ' Refer to Alias)
Record Results: False
Step: "Rename Locals.ResultListORIG"
StepType, Adapter: Action, Active-X
Description:
Action, Set PropertyObject.Name = "ResultList"
Record Results: False
I have attached a TS 2.0 version of SequentialModel.Seq that has a AppendResults subsequence in it and this is invoked after MainSequence in Single Pass entry point.
Hope this helps...
Scott Richardson (NI)
Scott Richardson
National Instruments
Attachments:
SequentialModel.Seq 174 KB
Maybe you are looking for
-
What is a .pkf and why can't I open it?
Newb here, I am working in Audition for the first time (by employer's request). I was given session files as .pkf files from work but have no idea how to open them at home. I have searched through all of the previous forum entries, help folders and
-
Problem after creating a costumer view
hi guys, i just created a new view from a costumer table. the problem is that when i access the view from sm30, i click on add new entries, and some fields have label and some has only the +, symbol, i dont now why! something like this: begda________
-
Midi ok on macbook but not on macbook pro...
Hello, I have been using my Yamaha P100 as a midi keyboard with my old Macbook with Reason and Garageband. I recently bought a Macbook Pro and using the same setup it recognices the midicable (CME U2midi cable) but will not recognice while I play on
-
on an image of the product with a micro usb in to itunes. I understand this means that an update didn't work but I don't own a micro usb or have itunes on this laptop. Is there any way of fixing this without itunes or a micro usb?
-
I'm trying to open sound effects from the recource page and there's no waveform
I'm trying to open sound effects from the recource page and there's no waveform