Order Siblings By
Hi,
I'm having this trouble with order siblings by. I'm using Report 6i Patch 16 on XP and running 10g DB on HP-UX. My query is
select child_account, accountdesc, accounttype
from account_table
connect by prior child_account = parent_account
start with child_account in (select child_account
from account_table
where parent_account is null)
order siblings by accounttype, child_account
When use above query in SQL in the Data Model, it runs fine. But when I use the same query as a cursor in Before Report Trigger, it causing error. The cursor is
cursor account_cur is select child_account, accountdesc, accounttype
from account_table
connect by prior child_account = parent_account
start with child_account in (select child_account
from account_table
where parent_account is null)
order siblings by accounttype, child_account;
The error generated was
"Error 103
Encountered the symbol “SIBLINGS” when expecting one on the following:
By
The symbol “SIBLINGS” was ignored."
Any idea why it runs fine as SQL in Data Model, but not as cursor in Before Report Trigger ?
Thanks
Yopie
Message was edited by:
Yopie
Why I can't use "wrap" utility for packages, which contain "siblings" word in it ?? Why can't you start a new thread for a completely unrelated topic?
Regards, APC
Similar Messages
-
ORDER SIBLINGS not working in Forms
This code run fine in Toad BUT giving me error in forms.
SELECT
LEVEL LOC_NAME,
LOCATION_NAME LOC_ID,
LOCATION_ID HLOC_ID,
HEAD_LOC_ID MUDRA
FROM AS_LOCATION_HDR
CONNECT BY PRIOR LOCATION_ID = HEAD_LOC_ID
START WITH HEAD_LOC_ID is null
ORDER SIBLINGS BY LOC_IDThe error is:
"Encountered sysbol "SIBLINGS" when expecting one of the following:
by
The symbol "by inserted before the "SIBLINGS" to continue.Is the SIBLINGS keyword not acepted in forms? What would be the alternative?
I am using oracle forms 10G (10.1.2.0.2)hi
Oracle's START WITH and CONNECT BY clauses in the
SELECT statement automatically traverse a hierarchy.
Without this feature, a complex self-join would be required to identify
which rows are logically related to others.
The START WITH clause identifies the row or rows to be considered
the starting points, or "roots," of the hierarchy.
The CONNECT BY PRIOR clause
then indicates how to identify which rows are related to each other.
example, the query in Listing A produces a "Reports To" listing from the EMPLOYEES table in the HR sample schema provided by Oracle.
The LEVEL pseudocolumn indicates how deeply the report is currently nested; here,
I use it to LPAD the employee names to indent them.
The START WITH condition states that only employees 101 and 102 are to be considered as starting points.
The CONNECT BY PRIOR clause then links the employee_id
column in one row to the manager_id column in the next, to indicate who reports to whom.
If you run this query in the HR schema,
you'll notice that the last names are not sorted within the listing for a specific manager;
they are listed in the order Oracle encountered them in processing the hierarchy.
If you want the subordinates in alphabetical order,
you might try to ORDER BY the original last_name column.
However, this would break up the hierarchy, and turn it back into a flat list of names.
You might also try to ORDER BY the pseudocolumn LEVEL first,
which tells how deep a specific row is in the hierarchy. This, too,
breaks up the hierarchy—all the managers will be listed first, followed by people who report to any of them.
In Oracle 10g (both releases),
it's now easy to do this: You can use the new SIBLINGS keyword to create the correct ordering. The syntax is:
ORDER SIBLINGS BY <expression>So adding the clause:
ORDER SIBLINGS BY last_nameto the end of the query will preserve
the hierarchy and also alphabetize the last names within each level.
Note that the original last_name was used not the alias "Reports To."
The extra space padding in "Reports To" would affect the sort, so the original must be used.
Listing B shows the output, both before and after adding ORDER SIBLINGS BY.
The ORDER SIBLINGS BY clause is valid only in a hierarchical query. The optional SIBLINGS keyword specifies an order that first sorts the parent rows, and then sorts the child rows of each parent for every level within the hierarchy.
Rows that have duplicate lists of values in the columns specified after the SIBLINGS BY keywords are arbitrarily ordered among the rows with the same list of values and the same parent. If a hierarchical query includes the ORDER BY clause without the SIBLINGS keyword, rows are ordered according to the sort specifications that follow the ORDER BY keywords. Neither the ORDER BY clause nor the ORDER SIBLINGS BY option to the ORDER BY clause is required in hierarchical queries.
The hierarchical query in the following example returns the subset of rows in the hierarchical data set whose root is Goyal, as listed in the topic Hierarchical Clause. This query includes the ORDER SIBLINGS BY clause to sort by name the employees who report to the same manager:
SELECT empid, name, mgrid, LEVEL
FROM employee
START WITH name = 'Goyal'
CONNECT BY PRIOR empid = mgrid
ORDER SIBLINGS BY name;The rows returned by this query are sorted in the following order:
empid name mgrid level
16 Goyal 17 1
12 Henry 16 2
7 O'Neil 12 3
9 Shoeman 12 3
8 Smith 12 3
14 Scott 16 2
11 Zander 16 2
6 Barnes 11 3
5 McKeough 11 3
9 row(s) retrieved.Here the START WITH clause returned the Goyal row at the root of this hierarchy. Two subsequent CONNECT BY steps (marked as 2 and 3 in the level pseudocolumn) returned three sets of sibling rows:
Henry, Scott, and Zander are siblings whose parent is Goyal;
O'Neil, Shoeman, and Smith are siblings whose parent is Henry;
Barnes and McKeough are siblings whose parent is Zander.
The next CONNECT BY step returned no rows, because the rows for which level = 3 are leaf nodes within this hierarchy. At this point in the execution of the query, the ORDER SIBLINGS BY clause was applied to the result set, sorting the rows in the order shown above.
Because the sort key, name, is a VARCHAR column, the returned rows within each set of siblings are in the ASCII order of their employee.name values. Only the sets of siblings that are leaf nodes in the hierarchy of returned rows appear consecutively in the sorted result set, because the managers are immediately followed by the employees who report to them, rather than by their siblings. An exception in this example is Scott, whose child nodes form an empty set.
The SIBLINGS keyword in the ORDER BY clause is an extension to the ISO standard syntax for the SQL language. The SELECT statement fails with an error if you include the SIBLINGS keyword in the ORDER BY clause of a query or subquery that does not include a valid CONNECT BY clause. hope this helps u.
sarah -
ORACLE 9I의 HIERARCHICAL QUERY의 ORDER SIBLINGS BY CLAUSE
제품 : ORACLE SERVER
작성날짜 : 2003-10-22
(V9I) Oracle 9i의 Hierarchical query의 ORDER SIBLINGS BY CLAUSE
===============================================================
PURPOSE
이 문서는 Oracle 9i의 new feature인 ORDER SIBLINGS BY 절을
Hierarchical query에 사용하는 예를 통하여 특정 컬럼을 기준으로
Ordering된 형태로 display하는 방법을 보여준다.
Explanation & Example
Hierarchical query를 구현할 때 ORDER BY 절을 사용하는 것은
Oracle 7.1 버젼부터 가능한 것이었다.
그러나, 순서대로 ordering되지 않고 특정 컬럼(emp table의 ename)을
기준으로 ordering하기를 원한다면 <Bulletin:10373>처럼 procedure를
작성하여야만 하였다.
그러나, Oracle 9i 에서는 ORDER BY 절 대신에 ORDER SIBLINGS BY 절을
사용할 수 있어 user-defined stored procedure를 만들 필요가 없게 되었다.
1) Ordering 하기 전의 emp table의 Hierarchical query
SQL> @a
ename EMPNO MGR JOB
KING 7839 PRESIDENT
JONES 7566 7839 MANAGER
SCOTT 7788 7566 ANALYST
ADAMS 7876 7788 CLERK
FORD 7902 7566 ANALYST
SMITH 7369 7902 CLERK
BLAKE 7698 7839 MANAGER
ALLEN 7499 7698 SALESMAN
WARD 7521 7698 SALESMAN
MARTIN 7654 7698 SALESMAN
TURNER 7844 7698 SALESMAN
ename EMPNO MGR JOB
JAMES 7900 7698 CLERK
CLARK 7782 7839 MANAGER
MILLER 7934 7782 CLERK
14 rows selected.
Ordering 하기 전의 a.sql 은 다음과 같다.
col ename format a25
col empno format 99999
col mgr format 99999
col job format a15
select rpad(' ', LEVEL*5) || ename "ename", empno, mgr, job
from emp
start with job='PRESIDENT'
connect by prior empno=mgr;
2) 9i의 new feature인 Hierarchical query를 사용하여 Ordering한 경우
SQL> @new_a
ename EMPNO MGR JOB
KING 7839 PRESIDENT
BLAKE 7698 7839 MANAGER
ALLEN 7499 7698 SALESMAN
JAMES 7900 7698 CLERK
MARTIN 7654 7698 SALESMAN
TURNER 7844 7698 SALESMAN
WARD 7521 7698 SALESMAN
CLARK 7782 7839 MANAGER
MILLER 7934 7782 CLERK
JONES 7566 7839 MANAGER
FORD 7902 7566 ANALYST
ename EMPNO MGR JOB
SMITH 7369 7902 CLERK
SCOTT 7788 7566 ANALYST
ADAMS 7876 7788 CLERK
14 rows selected.
Ordering하기 위해 사용한 new_a.sql 은 다음과 같다.
col ename format a25
col empno format 99999
col mgr format 99999
col job format a15
select rpad(' ', LEVEL*5) || ename "ename", empno, mgr, job
from emp
start with job='PRESIDENT'
connect by prior empno=mgr
order siblings by ename;
Reference Documents
<Bulletin:10373>Thanks to Kendenny, Boneist and Odie.
Got the point that "Order Siblings by clause" cannot be used with connect by query with analytical function, Thanks Kendenny.
Yes, I now use main query and subquery, however the subquery be just "connect by" and have the all html tags added in the main query.
The below query is working now.
SELECT
CASE WHEN LAG(mylevel,1,0) OVER (ORDER BY myrownum) >= mylevel THEN '<li>'
ELSE
CASE LEAD(mylevel) OVER (ORDER BY myrownum)
WHEN mylevel THEN
CASE WHEN myrownum = 1 THEN '<ul id="sidebarmenu1" '
ELSE '<ul'
END ||'><li>'
ELSE
CASE WHEN myrownum =1 THEN '<ul id="sidebarmenu1"'
ELSE '<ul '
END ||' ><li>'
END
END ||'<a href="'||
CASE WHEN link_url IS NOT NULL THEN
link_url||'title="'||menu_item||'"'
ELSE '#"' END ||
'><span>'||short_menu_item||'</span></a>'||
CASE mylevel - LEAD(mylevel,1,1) OVER (ORDER BY myrownum)
WHEN -1 THEN NULL
WHEN 0 THEN '</li>'
ELSE REPLACE(LPAD('*', myleveL-LEAD(mylevel,1,1) OVER (ORDER BY myrownum),'*'), '*','</li></ul></li>')
END ||
CASE WHEN LEAD(mylevel,1,0) OVER (ORDER BY myrownum) = 0 THEN '</ul>'
ELSE NULL END unordered_List,
menu_item, menu_id,
above_menu_id
FROM (
SELECT LEVEL mylevel, ROWNUM myrownum,daevmt.*
FROM dae_vs_my_tasks daevmt
CONNECT BY PRIOR daevmt.menu_id = daevmt.above_menu_id
START WITH daevmt.above_menu_id = 'TOPMENU'
ORDER SIBLINGS BY display_order
) t;
Odie, I tried altering the session for the flag, still the first query was not working.
Thanks again all for your great time in answering me. -
[10g] Need help with order by clause in hierarchical query
I have the following sample data:
CREATE TABLE bill_test1
( parent_part CHAR(25)
, child_part CHAR(25)
, line_nbr NUMBER(5)
, qty_per NUMBER(9,5)
INSERT INTO bill_test1 VALUES ('ABC-1','ABC-10',100,1);
INSERT INTO bill_test1 VALUES ('ABC-1','ABC-20',200,2);
INSERT INTO bill_test1 VALUES ('ABC-1','ABC-30',300,3);
INSERT INTO bill_test1 VALUES ('ABC-1','HARDWARE-1',401,10);
INSERT INTO bill_test1 VALUES ('ABC-1','HARDWARE-2',402,5);
INSERT INTO bill_test1 VALUES ('ABC-10','ABC-155',100,2);
INSERT INTO bill_test1 VALUES ('ABC-10','HARDWARE-1',200,1);
INSERT INTO bill_test1 VALUES ('ABC-155','RAW-2',100,4.8);
INSERT INTO bill_test1 VALUES ('ABC-155','HARDWARE-3',200,3);
INSERT INTO bill_test1 VALUES ('ABC-20','RAW-1',100,10.2);
INSERT INTO bill_test1 VALUES ('ABC-30','RAW-3',100,3);And the query below gives me exactly what I want, in the order I want it. However, I am wondering if there is a way to get this order without creating the SEQ column, since I don't need it in my results
SELECT part_nbr
, parent_part
, child_part
FROM (
SELECT CONNECT_BY_ROOT b.parent_part AS part_nbr
, b.parent_part
, b.child_part
, SYS_CONNECT_BY_PATH(b.line_nbr,' ') AS seq
FROM bill_test1 b
, dual
CONNECT BY parent_part = PRIOR child_part
WHERE part_nbr = 'ABC-1'
ORDER BY seq
Results of above query, except with SEQ included in SELECT (just to show what I'm sorting off of):
PART_NBR PARENT_PART CHILD_PART SEQ
ABC-1 ABC-1 ABC-10 100
ABC-1 ABC-10 ABC-155 100 100
ABC-1 ABC-155 RAW-2 100 100 100
ABC-1 ABC-155 HARDWARE-3 100 100 200
ABC-1 ABC-10 HARDWARE-1 100 200
ABC-1 ABC-1 ABC-20 200
ABC-1 ABC-20 RAW-1 200 100
ABC-1 ABC-1 ABC-30 300
ABC-1 ABC-30 RAW-3 300 100
ABC-1 ABC-1 HARDWARE-1 401
ABC-1 ABC-1 HARDWARE-2 402Hi,
As long as there's only one root, you can say ORDER SIBLINGS BY, but you can't do that in a sub-query (well, you can, but usually there's no point in doing it in a sub-query). If the CONNECT BY is being done in a sub-query, there is no guarantee that the main query will preserve the hierarchical order that the sub-query provides.
The query you posted doesn't require a suib-query, so you can say:
SELECT CONNECT_BY_ROOT b.parent_part AS part_nbr
, b.parent_part
, b.child_part
--, SYS_CONNECT_BY_PATH(b.line_nbr,' ') AS seq
FROM bill_test1 b
WHERE CONNECT_BY_ROOT b.parent_part = 'ABC-1'
CONNECT BY parent_part = PRIOR child_part
ORDER SIBLINGS BY b.line_nbr
;I said the query you posted doesn't require a sub-query. It also doesn't require dual, so I suspect what you posted is a simplification of what you're really doing, and that may need a sub-query. In particular, if you intend to GROUP BY part_nbr, then you need the sub-query. We can repeat the CONNECT_BY_ROOT expression in the WHERE clause (or, now that I think about it, use a START WITH clause instead of WHERE), but, for some reason, we can't use CONNECT_BY_ROOT in a GROUP BY clause; we need to compute CONNECT_BY_ROOT in a sub-query, give it a name (like part_nbr), and GROUP BY that column in a super-query.
This assumes that there is only one root node. ORDER SIBLINGS BY means just that: children of a common parent will appear in order, but the root nodes, who have no parents, will not necessarily be in order.
Here's what I meant by using START WITH instead of WHERE:
SELECT CONNECT_BY_ROOT b.parent_part AS part_nbr
, b.parent_part
, b.child_part
--, SYS_CONNECT_BY_PATH(b.line_nbr,' ') AS seq
FROM bill_test1 b
START WITH b.parent_part = 'ABC-1'
CONNECT BY parent_part = PRIOR child_part
ORDER SIBLINGS BY b.line_nbr
;This should be much more efficient, because it narrows down the results before you waste time getting their descendants.
Using a START WITH clause here is analagous to me sending you an e-mail, saying "Come to a meeting a my office at 3:00."
Using a WHERE clause here is analagous to me sending an e-mail to everyone in the company, saying "Come to a meeting a my office at 3:00", and then, as people get here, telling everyone except you that they can go back.
ORDER SIBLINGS BY was introduced in Oracle 9.
Edited by: Frank Kulash on Dec 9, 2010 2:39 PM
Added version with START WITH clause -
Connect by prior problem with order by
Hi,
I and using connect by prior within a query on Oracle 8 and would like to order the results within the parent levels.
All the documentation that I have read shows that in Oracle 9i there is an option to say order siblings by which looks like what I need, but this does not work on Oracle 8.
Can anyone tell me how I can order the children within the parents without changing the tree structure?
I have also tried SYS_CONNECT_BY_PATH and I just get an error saying that it is an invalid column name,Karen, see here for a dicussion on how to order the siblings in a pre-9i environment:
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:9212348049 -
Connect by prior by speific order problem.
Oracle: 10.2.0.4
I have a table containing events backup.
i want to list the hierarchy within that backup oreder by the time_stamp for all levels.
create table BCK_EVENTS
bck_backup_id NUMBER(9) default 0 not null,
event_id NUMBER(15) default 0 not null,
event_name NVARCHAR2(100) default ' ' not null
time_stamp NUMBER(9) default 0 not null,
parent_event NUMBER(15) default 0 not null,
add constraint BCK_EVENTS_PK primary key (BCK_EVENT_ID, EVENT_ID); // event_id is not unique can be under one or more backup id'sthis is not a tree with one root, there is more than one event in the root level (level 1).
example:
Event Name Time level <- time is numeric but for easier reading.
*Event A 10:00 1
*Event C 10:30 2
*Event B 11:17 3
*Event H 12:10 1
*Event J 12:10 2
*Event M 12:21 2
*Event Z 15:33 1
*Event R 16:56 2
*Event M 16:57 3
*Event G 20:20 2What i tried was :
select lpad( '*', level*2 ) || event_id,event_name,time_stamp,parent_event,level from bck_events
where bck_event_id=100031
start with parent_event is null
connect by prior event_id = parent_eventand there are two problems with it.
1. it's not ordered even when i added an Index (parent_event,time_stamp) and try to hint it.
2. it returns loads of multiple rows.
hope it's clear enough. I thank for any help.
Edited by: 973065 on Nov 25, 2012 8:04 AM
Edited by: 973065 on Nov 25, 2012 9:23 AM
Edited by: 973065 on Nov 25, 2012 9:29 AM
Edited by: 973065 on Nov 25, 2012 9:31 AMHi,
973065 wrote:
Oracle: 10.2
I have a table containing events backup.
i want to list the hierarchy within that backup oreder by the time_stamp for all levels.
create table BCK_EVENTS
bck_backup_id NUMBER(9) default 0 not null,
event_id NUMBER(15) default 0 not null,
event_name NVARCHAR2(100) default ' ' not null
time_stamp NUMBER(9) default 0 not null,
parent_event NUMBER(15) default 0 not null,
Thanks for posting the version number and the CREATE TABLE statement. Don't forget to post INSERT statements for your sample data.
add constraint BCK_EVENTS_PK primary key (BCK_EVENT_ID, EVENT_ID); // event_id is not unique can be under one or more backup id's
this is not a tree with one root, there is more than one event in the root level (level 1).Is it a forest, that is, a set of trees?
example:
Event Name Time level <- time is numeric but for easier reading.
*Event A 10:00 1
*Event C 10:30 2
*Event B 11:17 3
*Event H 12:10 1
*Event J 12:10 2
*Event M 12:21 2
*Event Z 15:33 1
*Event R 16:56 2
*Event M 16:57 3
*Event G 20:20 2
That seems to be a forest, that is, every row has 0 or 1 parent, and no row is its own ancestor.
What i tried was :
select lpad( '*', level*2 ) || event_id,event_name,time_stamp,parent_event,level from bck_events
where bck_event_id=100031
start with parent_event is null
connect by prior event_id = parent_event
and there are two problems with it.
1. it's not ordered even when i added an Index (parent_event,time_stamp) and try to hint it.Depending on your data, you may just need to add
ORDER SIBLINGS BY time_stampat the end, after the CONNECT BY clause.
If you need rows sorted by time_stamp under their roots, but otherwise without regard to the hierarchy, then use CONNECT_BY_ROOT.
2. it returns loads of multiple rows.Again, it depends on your data. I'll bet you need something more in the CONNECT BY clause, but I can't tell what without some sample data and an exxplanation of how you gett the results you posted from that data. The fact that bck_event_id is part of the primary key makes me suspect that maybe bck_event_id needs to be somewhere in the CONNECT BY clause, but that's just a wild guess.
hope it's clear enough. I thank for any help.As mentioned before, see the forum FAQ {message:id=9360002} -
CONNECT BY PRIOR - ORDERING ROWS
Hi all,
I am working on database server - oracle 10g enterprise edition R2,
forms - Oracle forms 10G -Version 10.1.2.0.2 on windows 2000 professional.
I have a table ACCOUNT_GROUP_MASTER with the following structure.
DESC ACCOUNT_GROUP_MASTER
Name Null? Type
ACCOUNT_GROUP_CODE NOT NULL NCHAR(6)
ACCOUNT_GROUP_NAME NOT NULL NVARCHAR2(40)
ACCOUNT_GROUP_TYPE CHAR(1)
GROUP_DISP_ORDER NUMBER(3)
MAIN_GROUP_CODE NCHAR(6)
Account_group_code is the primary key
and Main_group_code is the foreign key(self referencing) referring Account_group_code of the same table.
My query and the returned data are given below.
SELECT
level, account_group_code act, GROUP_DISP_ORDER ord
FROM ACCOUNT_GROUP_MASTER
CONNECT BY PRIOR ACCOUNT_GROUP_CODE=MAIN_GROUP_CODE
START WITH main_GROUP_code is null
order by account_group_code
LEVEL ACT ORD
1 4000 1
2 4100
2 4200 3
2 4300 1
1 2000 2
2 2100 2
2 2200 1
My task is to sort the output in the order of
First sort column is "level" and within the "level", data should be sorted by the
group_disp_order column.
That is the above output should come as given below.
LEVEL ACT ORD
1 4000 1
2 4100
2 4300 1
2 4200 3
1 2000 2
2 2200 1
2 2100 2
Can anybody help me please.
Thanks in advance.
Regards
MohanHi All
The solution to the above problem is solved by the following query.
SELECT 1,level, account_group_code|| account_group_NAME,NULL,
account_group_code
FROM ACCOUNT_GROUP_MASTER
CONNECT BY PRIOR ACCOUNT_GROUP_CODE=MAIN_GROUP_CODE
START WITH main_GROUP_code is null
order siblings by group_disp_order
Regards
Mohan -
I have a query to get all child records from table lm and in the order they stored in a table s
do you see in problem with the below query
select distinct s.id
from s, (select p.id from p
start with p.child_id= 10
connect by prior p.id = p.child_id) lm
where s.id= lm.id and s.skgid = 1
order by s.seq
ThanksA bit add to remarkable blushadow's comments.
You really don't need order by in hierarchical queries - results will be sorted in accordance with hierarchy graf order. You may use ORDER SIBLINGS BY clause
to sort hierarchy by something without violation of parent-child ordering:
SQL> select level, ename from emp start with mgr is null connect by mgr = prior empno;
LEVEL ENAME
1 KING
2 JONES
3 SCOTT
4 ADAMS
3 FORD
4 SMITH
2 BLAKE
3 ALLEN
3 WARD
3 MARTIN
3 TURNER
3 JAMES
2 CLARK
3 MILLER
14 rows selected.
SQL> select level, ename from emp start with mgr is null connect by mgr = prior empno
2 order siblings by ename;
LEVEL ENAME
1 KING
2 BLAKE
3 ALLEN
3 JAMES
3 MARTIN
3 TURNER
3 WARD
2 CLARK
3 MILLER
2 JONES
3 FORD
4 SMITH
3 SCOTT
4 ADAMS
14 rows selected.Rgds. -
Tree Issue--Data out of order?
All,
I suspect this is more of a generic SQL question, but, anyhow, I'm trying to create a tree report of the items in our bills of materials. When I run the page, the tree is empty (not even a root). Trying to figure out what the problem is, I've copied the SQL into Toad and run it; the results seem to be scrambled, which I suspect is why the tree is failing. Here's the query:
select case when connect_by_isleaf = 1 then 0
when level = 1 then 1
else -1
end as status,
level,
comp_item_number as title,
null as icon,
comp_inventory_item_id as value,
null as tooltip,
null as link
from apex.bom_tree_v
where organization_id = 126
start with comp_item_number = 'C70-1039'
connect by prior comp_inventory_item_id = parent_item_id
order siblings by comp_item_numberThe query returns 64 rows for my test item, which is correct, but the top-level item (level = 1) is returned as the 10th row (consistently), rather than the first. All of the documentation I've been able to find indicates that the rows should be returned in hierarchical order.
Anyone have any idea what I'm missing?
-DavidGood afternoon David,
Trees in APEX are not even closely populated the same as in Forms. What I did was this:
<li>Query the top of your tree...
<li>Do a UNION ALL SELECT for the next level of your tree
<li> and repeat the UNION ALL SELECT for each indented level of your tree.
Mine looks something like this:
select 'A' id,
null as pid,
'Table Of Contents' name,
NULL link,
'f?p=&APP_ID.:1:&APP_SESSION.:CONTRACT,A' A1,
'f?p=&APP_ID.:1:&APP_SESSION.:EXPAND,A' A2
from dual
union all
select ltrim(rtrim(to_char(toc_seq_id))) id,
'A' pid,
toc_description name,
'f?p=&APP_ID.:1:&APP_SESSION.:::RP:TOCP:' || toc_seq_id link,
'f?p=&APP_ID.:1:&APP_SESSION.:CONTRACT,' || TO_CHAR(toc_seq_id) ||'::RP:TOCP:' || TO_CHAR(toc_seq_id) A1,
'f?p=&APP_ID.:1:&APP_SESSION.:EXPAND,' || TO_CHAR(toc_seq_id) ||'::RP:TOCP:' || TO_CHAR(toc_seq_id) A2
from my_toc
where state_id = :P1_STATE
and toc_level = 1
and (toc_seq_id < 9
or (toc_seq_id < 10 and :P1_User_Type = 2)
or (toc_seq_id < 10 and :P1_CUSTOM_USER = 'Y')
or (toc_seq_id < 15 and :P1_User_Type > 2 and :P1_CUSTOM_USER != 'Y'))
union all
select ltrim(rtrim(toc_seq_id)) id,
ltrim(rtrim(toc_parent)) pid,
toc_description name,
'f?p=&APP_ID.:' || ltrim(rtrim(to_char((toc_parent+2)))) || ':&APP_SESSION.:::RP:P1_ENTRY_ID:' || toc_entry_id link,
null a1,
null a2
from my_toc
where state_id = :P1_STATE
and toc_level = 2
and (toc_parent < 9
or (toc_parent = 9 and :P1_User_Type = 2)
or (toc_seq_id < 10 and :P1_CUSTOM_USER = 'Y')
or (toc_seq_id < 15 and :P1_User_Type > 2 and :P1_CUSTOM_USER != 'Y'))
order by 3,1The code that looks like this:
'f?p=&APP_ID.:' || ltrim(rtrim(to_char((toc_parent+2)))) || ':&APP_SESSION.:::RP:P1_ENTRY_ID:' || toc_entry_id link,is building a link to a page based on the value of the entry (:P1_ENTRY_ID) so the user can click on an entry and jump to that item.
My tree looks like this: (I can't paste an image, so I'll wing it with text - notice my tree started out with
entry zero [0] because I had to add it after the tree was built)
- Table of Contents
+ 0. First branch of my tree
+ 1. Second branch of my tree
- 2. Third branch - expanded
+ Entry 1 for third level
+ Entry 2 for third level
+ 3. Fourth branch of my tree
+ 4. Fifth branch of my treeIt took me awhile to figure all of this out, but once I did, it began to make sense.
The whole idea is that each SELECT will select the next indented level in the tree. Then in the end, use ORDER BY 3,1 to order your tree properly by the parent and then the child within the parent.
I hope this makes sense and that it helps.
Good luck,
Don.
REWARDS: Please remember to mark helpful or correct posts on the forum, not just for my answers but for everyone! :) -
How to use order by with hierarchical query
I have a hierarchical query basically it brings back an organization chart. We start with a manager's id, get all that person's employees. If any of the employees is also a manager I want to get that person's employees and return them right after that person. I won't bother with the whole query but relevant part is:
START WITH em.mgr_id = pi_mgr_id
CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id;Where pi_mgr_id is a parameter passed to the procedure and em is the alias for the emp_mgr_relationship table which contains emp_id and mgr_id. This works fine. What I want now is for the employees who work for the same manager to appear in name order. The table which contains the employee names is aliased as pe and the name column is called name1. I added the following:
START WITH em.mgr_id = pi_mgr_id
CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id
order by pe.name1;But that put the entire list in name order. What I want is for employees who work for the same manager to be in name order. Let's the manager whose organization I want is named Frank. What I'd like to get is this
EMP_NAME MGR_NAME
Allen Frank
Beth Frank
Alex Beth
Charles Beth
Ed Beth
Dean Frank
George Frank
Benny George
David George
Sam George
Dan Sam
Harry Sam
John Sam
Terry George
James Frank
Ken Frank
Mike Ken
Warren KenHow do I get the list in this order?
Edited by: kendenny on Jul 28, 2010 7:31 AMMake use of ORDER SIBLINGS clause in hierarchial queries to set the order by child columns.
START WITH em.mgr_id = pi_mgr_id
CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id
*order siblings by name1;* -
Sort siblings of a hierarchial query in oracle8i
Hi,
I have a basic hierarchial query like the following:
select *
from users_table
start with userid = user
connect by manager = prior userid
I would like to sort the employees by name under their manager. Is there an easy way to do this in Oracle8i. I cannot use the ORDER SIBLINGS BY clause until Oracle9i. Thanks for your help.http://www.quest-pipelines.com/pipelines/plsql/archives.htm#code16
-
Ordering with Subquery Factoring
Can I be assured that the results of this query will be ordered as defined by the 'order siblings by' clause?
with hier as
select ...
from ...
start with ...
connect by ...
order siblings by ...
select ...
from hier
;How about this one?
with hier as
select ...
from ...
start with ...
connect by ...
order siblings by ...
subqry as
select ...
from ...
where ...
select ...
from
hier
inner join subqry using ...
;I'm thinking I need something like this to ensure the proper order.
with hier as
select
rownum rnum
from ...
start with ...
connect by ...
order siblings by ...
select ...
from hier
order by rnum
;If not needed for the first query, is the above technique needed for the second?
Thanks.It is true, the plan is changing but it is not really needed.
Take a look at my queries and execution plans using the sample schema HR:
with h as (
select employee_id, first_name, last_name, department_id, manager_id
from hr.employees
start with manager_id is null
connect by manager_id = prior employee_id
order siblings by last_name
select h.employee_id, h.first_name, h.last_name, h.department_id, h.manager_id, d.department_name
from h join hr.departments d on d.department_id = h.department_id;
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 20 | 1900 | 4 (25)| 00:00:01 |
| 1 | NESTED LOOPS | | | | | |
| 2 | NESTED LOOPS | | 20 | 1900 | 4 (25)| 00:00:01 |
| 3 | VIEW | | 20 | 1300 | 4 (25)| 00:00:01 |
|* 4 | CONNECT BY NO FILTERING WITH START-WITH| | | | | |
| 5 | TABLE ACCESS FULL | EMPLOYEES | 20 | 1300 | 3 (0)| 00:00:01 |
|* 6 | INDEX UNIQUE SCAN | DEPT_ID_PK | 1 | | 0 (0)| 00:00:01 |
| 7 | TABLE ACCESS BY INDEX ROWID | DEPARTMENTS | 1 | 30 | 0 (0)| 00:00:01 |
with h as (
select employee_id, first_name, last_name, department_id, manager_id, rownum
from hr.employees
start with manager_id is null
connect by manager_id = prior employee_id
order siblings by last_name
select h.employee_id, h.first_name, h.last_name, h.department_id, h.manager_id, d.department_name
from h join hr.departments d on d.department_id = h.department_id
order by rownum;
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 20 | 1900 | 5 (40)| 00:00:01 |
| 1 | SORT ORDER BY | | 20 | 1900 | 5 (40)| 00:00:01 |
| 2 | COUNT | | | | | |
| 3 | NESTED LOOPS | | | | | |
| 4 | NESTED LOOPS | | 20 | 1900 | 4 (25)| 00:00:01 |
| 5 | VIEW | | 20 | 1300 | 4 (25)| 00:00:01 |
| 6 | COUNT | | | | | |
|* 7 | CONNECT BY NO FILTERING WITH START-WITH| | | | | |
| 8 | TABLE ACCESS FULL | EMPLOYEES | 20 | 1300 | 3 (0)| 00:00:01 |
|* 9 | INDEX UNIQUE SCAN | DEPT_ID_PK | 1 | | 0 (0)| 00:00:01 |
| 10 | TABLE ACCESS BY INDEX ROWID | DEPARTMENTS | 1 | 30 | 0 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------------- -
Is 'SIBLINGS' keyword allowed to use in Form 9i?
I cannot compile the following pl/sql in forms 9i builder (ver 9.0.4.0.19) with the compilation error ocurrs as follows:
Compilation Error
=================
Encountered the symbol "SIBLINGS" when expecting one of the following: by
The symbol "SILBLINGS" was ignored.
PL/SQL sample
=============
cursor c_rec is
select node_id, rownum
from mis_tree_hierarchy
start with tree_id = :bk_tree.tree_id
and version_code = :bk_tree.version_code
and parent_node_id is null
connect by prior tree_id = tree_id
and prior version_code = version_code
and prior node_id = parent_node_id
order siblings by header_name;
Can anyone tell me if the keyword 'SIBLINGS' is not allowed to use in Forms 9i. Is there any workaround?Thanks for the reply.
It seems quite strange to me that there is no problem to use "order siblings by" in the Data Query of Hierarchical Tree item in Forms 9i. The form can be compiled successfully and the ordering sequence of the hierarchical tree is the same as what I want.
However, I'm wondering why "order siblings by" can't be used in Forms 9i PL/SQL editor.
Best regards,
Twiggie -
What can I do to make this query run faster
Hi All,
The below query is taking a long time. Is there any thing that I can do to shorten its time.
SELECT C.FOLIO_NO, C.CO_TRANS_NO TRANS_NO, to_char(C.CREATED_DATE, 'dd/mm/yyyy') DOC_DATE, DECODE(PP.NAME, NULL, D.EMP_NAME, PP.NAME) LODGED_BY, decode(sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID), Null, '-', sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID)) DATE_CHANGE, P.RECEIPT_NO, decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id) TRANS_ID,(case when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR20' then 1 when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR03' then 2 end) TRANS_TYPE FROM CO_TRANS_MASTER C, PAYMENT_DETAIL P, PEOPLE_PROFILE PP, SC_AGENT_EMP D, M_CAA_TRANS E where '1' <> TRIM(UPPER('S0750070Z')) and (C.CO_TRANS_ID in TRIM(UPPER('AR20')) OR C.CO_TRANS_ID in TRIM(UPPER('AR03'))OR c.co_trans_id IN TRIM (UPPER ('A020')))and C.CO_TRANS_NO = P.TRANS_NO and (C.VOID_IND = 'N' or C.VOID_IND is Null) and C.CREATED_BY = PP.PP_ID(+) and C.PROF_NO = D.PROF_NO(+) and C.CREATED_BY = D.EMP_ID (+) and TRIM(UPPER(C.CO_NO)) = TRIM(UPPER('200101586W')) and c.co_trans_id = e.trans_id (+) order by FOLIO_NO;
SQL>
SQL> show parameter user_dump_dest
NAME TYPE VALUE
user_dump_dest string /u01/app/oracle/diag/rdbms/ebi
zfile/EBIZFILE1/trace
SQL> show parameter optimizer
NAME TYPE VALUE
optimizer_capture_sql_plan_baselines boolean FALSE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 11.2.0.2
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
optimizer_use_invisible_indexes boolean FALSE
optimizer_use_pending_statistics boolean FALSE
optimizer_use_sql_plan_baselines boolean TRUE
SQL> show parameter db_file_multi
NAME TYPE VALUE
db_file_multiblock_read_count integer 128
SQL> show parameter db_block_size
NAME TYPE VALUE
db_block_size integer 8192
SQL> show parameter cursor_sharing
NAME TYPE VALUE
cursor_sharing string EXACT
SQL>
SQL> column sname format a20
SQL> column pname format a20
SQL> column pval2 format a20
SQL>
SQL> select
2 sname, pname, pval1, pval2
3 from
4 sys.aux_stats$;
SNAME PNAME PVAL1 PVAL2
SYSSTATS_INFO STATUS COMPLETED
SYSSTATS_INFO DSTART 09-11-2010 14:25
SYSSTATS_INFO DSTOP 09-11-2010 14:25
SYSSTATS_INFO FLAGS 1
SYSSTATS_MAIN CPUSPEEDNW 739.734748
SYSSTATS_MAIN IOSEEKTIM 10
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM
SYSSTATS_MAIN MREADTIM
SYSSTATS_MAIN CPUSPEED
SYSSTATS_MAIN MBRC
SYSSTATS_MAIN MAXTHR
SYSSTATS_MAIN SLAVETHR
13 rows selected.
Elapsed: 00:00:00.06
SQL>
SQL> explain plan for
2 SELECT C.FOLIO_NO, C.CO_TRANS_NO TRANS_NO, to_char(C.CREATED_DATE, 'dd/mm/yyyy') DOC_DATE, DECODE(PP.NAME, NULL, D.EMP_NAME, PP.NAME) LODGED_BY, decode(sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID), Null, '-', sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID)) DATE_CHANGE, P.RECEIPT_NO, decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id) TRANS_ID,(case when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR20' then 1 when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR03' then 2 end) TRANS_TYPE FROM CO_TRANS_MASTER C, PAYMENT_DETAIL P, PEOPLE_PROFILE PP, SC_AGENT_EMP D, M_CAA_TRANS E where '1' <> TRIM(UPPER('S0750070Z')) and (C.CO_TRANS_ID in TRIM(UPPER('AR20')) OR C.CO_TRANS_ID in TRIM(UPPER('AR03'))OR c.co_trans_id IN TRIM (UPPER ('A020')))and C.CO_TRANS_NO = P.TRANS_NO and (C.VOID_IND = 'N' or C.VOID_IND is Null) and C.CREATED_BY = PP.PP_ID(+) and C.PROF_NO = D.PROF_NO(+) and C.CREATED_BY = D.EMP_ID (+) and TRIM(UPPER(C.CO_NO)) = TRIM(UPPER('200101586W')) and c.co_trans_id = e.trans_id (+) order by FOLIO_NO;
Explained.
Elapsed: 00:00:00.09
SQL>
SQL> set pagesize 1000;
SQL> set linesize 170;
SQL> @/u01/app/oracle/product/11.2.0/rdbms/admin/utlxpls.sql
SQL> Rem
SQL> Rem $Header: utlxpls.sql 26-feb-2002.19:49:37 bdagevil Exp $
SQL> Rem
SQL> Rem utlxpls.sql
SQL> Rem
SQL> Rem Copyright (c) 1998, 2002, Oracle Corporation. All rights reserved.
SQL> Rem
SQL> Rem NAME
SQL> Rem utlxpls.sql - UTiLity eXPLain Serial plans
SQL> Rem
SQL> Rem DESCRIPTION
SQL> Rem script utility to display the explain plan of the last explain plan
SQL> Rem command. Do not display information related to Parallel Query
SQL> Rem
SQL> Rem NOTES
SQL> Rem Assume that the PLAN_TABLE table has been created. The script
SQL> Rem utlxplan.sql should be used to create that table
SQL> Rem
SQL> Rem With SQL*plus, it is recomended to set linesize and pagesize before
SQL> Rem running this script. For example:
SQL> Rem set linesize 100
SQL> Rem set pagesize 0
SQL> Rem
SQL> Rem MODIFIED (MM/DD/YY)
SQL> Rem bdagevil 02/26/02 - cast arguments
SQL> Rem bdagevil 01/23/02 - rewrite with new dbms_xplan package
SQL> Rem bdagevil 04/05/01 - include CPU cost
SQL> Rem bdagevil 02/27/01 - increase Name column
SQL> Rem jihuang 06/14/00 - change order by to order siblings by.
SQL> Rem jihuang 05/10/00 - include plan info for recursive SQL in LE row source
SQL> Rem bdagevil 01/05/00 - add order-by to make it deterministic
SQL> Rem kquinn 06/28/99 - 901272: Add missing semicolon
SQL> Rem bdagevil 05/07/98 - Explain plan script for serial plans
SQL> Rem bdagevil 05/07/98 - Created
SQL> Rem
SQL>
SQL> set markup html preformat on
SQL>
SQL> Rem
SQL> Rem Use the display table function from the dbms_xplan package to display the last
SQL> Rem explain plan. Force serial option for backward compatibility
SQL> Rem
SQL> select plan_table_output from table(dbms_xplan.display('plan_table',null,'serial'));
PLAN_TABLE_OUTPUT
Plan hash value: 2520189693
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 592 | 85248 | 16573 (1)| 00:03:19 |
| 1 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 6 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 7 | SORT ORDER BY | | 592 | 85248 | 16573 (1)| 00:03:19 |
| 8 | NESTED LOOPS | | | | | |
| 9 | NESTED LOOPS | | 592 | 85248 | 16572 (1)| 00:03:19 |
| 10 | NESTED LOOPS OUTER | | 477 | 54855 | 15329 (1)| 00:03:04 |
| 11 | NESTED LOOPS OUTER | | 477 | 41499 | 14374 (1)| 00:02:53 |
| 12 | INLIST ITERATOR | | | | | |
|* 13 | TABLE ACCESS BY INDEX ROWID| CO_TRANS_MASTER | 477 | 22896 | 14367 (1)| 00:02:53 |
|* 14 | INDEX RANGE SCAN | IDX_CO_TRANS_ID | 67751 | | 150 (1)| 00:00:02 |
| 15 | TABLE ACCESS BY INDEX ROWID | SC_AGENT_EMP | 1 | 39 | 1 (0)| 00:00:01 |
|* 16 | INDEX UNIQUE SCAN | PK_SC_AGENT_EMP | 1 | | 0 (0)| 00:00:01 |
| 17 | TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE | 1 | 28 | 2 (0)| 00:00:01 |
|* 18 | INDEX UNIQUE SCAN | SYS_C0063100 | 1 | | 1 (0)| 00:00:01 |
|* 19 | INDEX RANGE SCAN | IDX_PAY_DETAIL_TRANS_NO | 1 | | 2 (0)| 00:00:01 |
| 20 | TABLE ACCESS BY INDEX ROWID | PAYMENT_DETAIL | 1 | 29 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("F"."CO_TRANS_NO"=:B1)
4 - access("F"."CO_TRANS_NO"=:B1)
6 - access("F"."CO_TRANS_NO"=:B1)
13 - filter(TRIM(UPPER("SYS_ALIAS_3"."CO_NO"))='200101586W' AND ("SYS_ALIAS_3"."VOID_IND" IS NULL
OR "SYS_ALIAS_3"."VOID_IND"='N'))
14 - access("SYS_ALIAS_3"."CO_TRANS_ID"='A020' OR "SYS_ALIAS_3"."CO_TRANS_ID"='AR03' OR
"SYS_ALIAS_3"."CO_TRANS_ID"='AR20')
16 - access("SYS_ALIAS_3"."PROF_NO"="D"."PROF_NO"(+) AND
"SYS_ALIAS_3"."CREATED_BY"="D"."EMP_ID"(+))
18 - access("SYS_ALIAS_3"."CREATED_BY"="PP"."PP_ID"(+))
19 - access("SYS_ALIAS_3"."CO_TRANS_NO"="P"."TRANS_NO")
42 rows selected.
Elapsed: 00:00:00.53
SQL>
SQL>
SQL>
SQL> rollback;
Rollback complete.
Elapsed: 00:00:00.01
SQL>
SQL> rem Set the ARRAYSIZE according to your application
SQL> set autotrace traceonly arraysize 100
SQL>
SQL> alter session set tracefile_identifier = 'mytrace1';
Session altered.
Elapsed: 00:00:00.00
SQL>
SQL> rem if you're using bind variables
SQL> rem define them here
SQL>
SQL> rem variable b_var1 number
SQL> rem variable b_var2 varchar2(20)
SQL>
SQL> rem and initialize them
SQL>
SQL> rem exec :b_var1 := 1
SQL> rem exec :b_var2 := 'DIAG'
SQL> set pagesize 1000;
SQL> set linesize 170;
SQL> alter session set events '10046 trace name context forever, level 8';
Session altered.
Elapsed: 00:00:00.01
SQL> SELECT C.FOLIO_NO, C.CO_TRANS_NO TRANS_NO, to_char(C.CREATED_DATE, 'dd/mm/yyyy') DOC_DATE, DECODE(PP.NAME, NULL, D.EMP_NAME, PP.NAME) LODGED_BY, decode(sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID), Null, '-', sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID)) DATE_CHANGE, P.RECEIPT_NO, decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id) TRANS_ID,(case when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR20' then 1 when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR03' then 2 end) TRANS_TYPE FROM CO_TRANS_MASTER C, PAYMENT_DETAIL P, PEOPLE_PROFILE PP, SC_AGENT_EMP D, M_CAA_TRANS E where '1' <> TRIM(UPPER('S0750070Z')) and (C.CO_TRANS_ID in TRIM(UPPER('AR20')) OR C.CO_TRANS_ID in TRIM(UPPER('AR03'))OR c.co_trans_id IN TRIM (UPPER ('A020')))and C.CO_TRANS_NO = P.TRANS_NO and (C.VOID_IND = 'N' or C.VOID_IND is Null) and C.CREATED_BY = PP.PP_ID(+) and C.PROF_NO = D.PROF_NO(+) and C.CREATED_BY = D.EMP_ID (+) and TRIM(UPPER(C.CO_NO)) = TRIM(UPPER('200101586W')) and c.co_trans_id = e.trans_id (+) order by FOLIO_NO;
10 rows selected.
Elapsed: 00:03:42.27
Execution Plan
Plan hash value: 2520189693
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 592 | 85248 | 16573 (1)| 00:03:19 |
| 1 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 6 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 7 | SORT ORDER BY | | 592 | 85248 | 16573 (1)| 00:03:19 |
| 8 | NESTED LOOPS | | | | | |
| 9 | NESTED LOOPS | | 592 | 85248 | 16572 (1)| 00:03:19 |
| 10 | NESTED LOOPS OUTER | | 477 | 54855 | 15329 (1)| 00:03:04 |
| 11 | NESTED LOOPS OUTER | | 477 | 41499 | 14374 (1)| 00:02:53 |
| 12 | INLIST ITERATOR | | | | | |
|* 13 | TABLE ACCESS BY INDEX ROWID| CO_TRANS_MASTER | 477 | 22896 | 14367 (1)| 00:02:53 |
|* 14 | INDEX RANGE SCAN | IDX_CO_TRANS_ID | 67751 | | 150 (1)| 00:00:02 |
| 15 | TABLE ACCESS BY INDEX ROWID | SC_AGENT_EMP | 1 | 39 | 1 (0)| 00:00:01 |
|* 16 | INDEX UNIQUE SCAN | PK_SC_AGENT_EMP | 1 | | 0 (0)| 00:00:01 |
| 17 | TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE | 1 | 28 | 2 (0)| 00:00:01 |
|* 18 | INDEX UNIQUE SCAN | SYS_C0063100 | 1 | | 1 (0)| 00:00:01 |
|* 19 | INDEX RANGE SCAN | IDX_PAY_DETAIL_TRANS_NO | 1 | | 2 (0)| 00:00:01 |
| 20 | TABLE ACCESS BY INDEX ROWID | PAYMENT_DETAIL | 1 | 29 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("F"."CO_TRANS_NO"=:B1)
4 - access("F"."CO_TRANS_NO"=:B1)
6 - access("F"."CO_TRANS_NO"=:B1)
13 - filter(TRIM(UPPER("SYS_ALIAS_3"."CO_NO"))='200101586W' AND ("SYS_ALIAS_3"."VOID_IND" IS NULL
OR "SYS_ALIAS_3"."VOID_IND"='N'))
14 - access("SYS_ALIAS_3"."CO_TRANS_ID"='A020' OR "SYS_ALIAS_3"."CO_TRANS_ID"='AR03' OR
"SYS_ALIAS_3"."CO_TRANS_ID"='AR20')
16 - access("SYS_ALIAS_3"."PROF_NO"="D"."PROF_NO"(+) AND
"SYS_ALIAS_3"."CREATED_BY"="D"."EMP_ID"(+))
18 - access("SYS_ALIAS_3"."CREATED_BY"="PP"."PP_ID"(+))
19 - access("SYS_ALIAS_3"."CO_TRANS_NO"="P"."TRANS_NO")
Statistics
51 recursive calls
0 db block gets
651812 consistent gets
92202 physical reads
0 redo size
1594 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
10 rows processed
SQL>
SQL> disconnect
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> Thanks in advance!Hi Raj,
I have given the output below as you requested....
QL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID 0taz7ckjm41yv, child number 1
SELECT C.FOLIO_NO, C.CO_TRANS_NO TRANS_NO, to_char(C.CREATED_DATE,
'dd/mm/yyyy') DOC_DATE, DECODE(PP.NAME, NULL, D.EMP_NAME, PP.NAME)
LODGED_BY, decode(sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID),
Null, '-', sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID))
DATE_CHANGE, P.RECEIPT_NO, decode(c.co_trans_id,'A020',(select
nvl(base_trans_id,co_trans_id) from co_form5a_trans f where
f.co_trans_no=c.co_trans_no),c.co_trans_id) TRANS_ID,(case when
decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from
co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR2
0' then 1 when decode(c.co_trans_id,'A020',(select
nvl(base_trans_id,co_trans_id) from co_form5a_trans f where
f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR03' then 2 end)
TRANS_TYPE FROM CO_TRANS_MASTER C, PAYMENT_DETAIL P, PEOPLE_PROFILE PP,
SC_AGENT_EMP D, M_CAA_TRANS E where '1' <> TRIM(UPPER('S0750070Z')) and
(C.CO_TRANS_ID in TRIM(UPPER('AR20')) OR C.CO_TRANS_ID in
TRIM(UPPER('AR03'))OR c.co
Plan hash value: 4175354585
| Id | Operation | Name | E-Rows | OMem | 1Mem | Used-Mem |
| 0 | SELECT STATEMENT | | | | | |
| 1 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | | | |
|* 2 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | | |
| 3 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | | | |
|* 4 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | | |
| 5 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | | | |
|* 6 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | | |
| 7 | SORT ORDER BY | | 12 | 2048 | 2048 | 2048 (0)|
| 8 | NESTED LOOPS | | | | | |
| 9 | NESTED LOOPS | | 12 | | | |
| 10 | NESTED LOOPS OUTER | | 10 | | | |
| 11 | NESTED LOOPS OUTER | | 10 | | | |
|* 12 | TABLE ACCESS FULL | CO_TRANS_MASTER | 10 | | | |
| 13 | TABLE ACCESS BY INDEX ROWID| SC_AGENT_EMP | 1 | | | |
|* 14 | INDEX UNIQUE SCAN | PK_SC_AGENT_EMP | 1 | | | |
| 15 | TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE | 1 | | | |
|* 16 | INDEX UNIQUE SCAN | SYS_C0063100 | 1 | | | |
|* 17 | INDEX RANGE SCAN | IDX_PAY_DETAIL_TRANS_NO | 1 | | | |
| 18 | TABLE ACCESS BY INDEX ROWID | PAYMENT_DETAIL | 1 | | | |
Predicate Information (identified by operation id):
2 - access("F"."CO_TRANS_NO"=:B1)
4 - access("F"."CO_TRANS_NO"=:B1)
6 - access("F"."CO_TRANS_NO"=:B1)
12 - filter((INTERNAL_FUNCTION("SYS_ALIAS_3"."CO_TRANS_ID") AND
TRIM(UPPER("SYS_ALIAS_3"."CO_NO"))='200101586W' AND ("SYS_ALIAS_3"."VOID_IND" IS NULL OR
"SYS_ALIAS_3"."VOID_IND"='N')))
14 - access("SYS_ALIAS_3"."PROF_NO"="D"."PROF_NO" AND "SYS_ALIAS_3"."CREATED_BY"="D"."EMP_ID")
16 - access("SYS_ALIAS_3"."CREATED_BY"="PP"."PP_ID")
17 - access("SYS_ALIAS_3"."CO_TRANS_NO"="P"."TRANS_NO")
Note
- cardinality feedback used for this statement
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
65 rows selected. -
How do i add a root node to a XMLType
Hi all
I have a problem inserting a root node in a xml document generated by DBMS_XMLGEN.newcontextfromhierarchy. The function get_site_map_nodes generates a document like this:
<?xml version="1.0"?>
<siteMapNode f_page_id="1" title="rot" PATH="1">
<siteMapNode f_page_id="2" title="1.1" PATH="1.1">
<siteMapNode f_page_id="4" title="1.1.1" PATH="1.1.1"/>
</siteMapNode>
<siteMapNode f_page_id="3" title="1.2" PATH="1.2"/>
<siteMap/>
</siteMapNode>
This is correct but i want to add a root node so the result shows as below:
<?xml version="1.0"?>
<siteMap>
<siteMapNode f_page_id="1" title="rot" PATH="1">
<siteMapNode f_page_id="2" title="1.1" PATH="1.1">
<siteMapNode f_page_id="4" title="1.1.1" PATH="1.1.1"/>
</siteMapNode>
<siteMapNode f_page_id="3" title="1.2" PATH="1.2"/>
<siteMap/>
</siteMapNode>
</siteMap>
The problem is that i have no clue how to accomplish this.
Best regards
Daniel Carlsson
PACKAGE BODY PKG_PAGE_STRUCTURE
IS
FUNCTION get_level_path (in_page_id IN page_structure.f_page_id%TYPE)
RETURN VARCHAR2
IS
l_path VARCHAR2 (4000) := '';
BEGIN
SELECT MAX (SYS_CONNECT_BY_PATH (f_show_order, '.'))
INTO l_path
FROM page_structure
START WITH f_page_id = in_page_id
CONNECT BY PRIOR f_parent_page = f_page_id;
l_path := RTRIM (l_path, '.');
RETURN l_path;
END get_level_path;
FUNCTION get_site_map_nodes (in_page_id IN page_structure.f_page_id%TYPE)
RETURN XMLTYPE
IS
qryctx DBMS_XMLGEN.ctxhandle;
l_xml XMLTYPE;
BEGIN
qryctx :=
DBMS_XMLGEN.newcontextfromhierarchy
('select level, xmlelement("siteMapNode", XMLAttributes(f_page_id as "f_page_id",
f_title_phrase as "title", pkg_page_structure.get_level_path(f_page_id) as path))
FROM PAGE_STRUCTURE
START WITH f_page_id = :in_page_id
connect by f_parent_page = prior f_page_id
ORDER siblings BY f_show_order'
DBMS_XMLGEN.setbindvalue (qryctx, 'in_page_id', TO_CHAR (in_page_id));
l_xml := DBMS_XMLGEN.getxmltype (qryctx);
DBMS_XMLGEN.closecontext (qryctx);
RETURN l_xml;
END get_site_map_nodes;
END PKG_PAGE_STRUCTURE;
CREATE TABLE page_structure
(f_page_id NUMBER(10,0) NOT NULL,
f_parent_page NUMBER(10,0),
f_show_order NUMBER(10,0),
f_title_phrase VARCHAR2(20),
f_created_by NUMBER(10,0),
f_created_date DATE,
f_updated_by NUMBER(10,0),
f_updated_date DATE)
INSERT INTO page_structure
(F_PAGE_ID,F_PARENT_PAGE,F_SHOW_ORDER,F_TITLE_PHRASE,F_CREATED_BY,F_CREATED_DATE,F_UPDATED_BY,F_UPDATED_DATE)
VALUES
(1,NULL,1,'rot',1,'30-MAR-2006',NULL,NULL)
INSERT INTO page_structure
(F_PAGE_ID,F_PARENT_PAGE,F_SHOW_ORDER,F_TITLE_PHRASE,F_CREATED_BY,F_CREATED_DATE,F_UPDATED_BY,F_UPDATED_DATE)
VALUES
(2,1,1,'1.1',1,'30-MAR-2006',NULL,NULL)
INSERT INTO page_structure
(F_PAGE_ID,F_PARENT_PAGE,F_SHOW_ORDER,F_TITLE_PHRASE,F_CREATED_BY,F_CREATED_DATE,F_UPDATED_BY,F_UPDATED_DATE)
VALUES
(3,1,2,'1.2',1,'30-MAR-2006',NULL,NULL)
INSERT INTO page_structure
(F_PAGE_ID,F_PARENT_PAGE,F_SHOW_ORDER,F_TITLE_PHRASE,F_CREATED_BY,F_CREATED_DATE,F_UPDATED_BY,F_UPDATED_DATE)
VALUES
(4,2,1,'1.1.1',1,'30-MAR-2006',NULL,NULL)
/Please try below steps.
1. Complete Prerequisite for adding cluster node
2. Verify the node is accessible to all other nodes in the cluster. Run the following command from the existing node in the cluster.
cluvfy stage -pre crsinst -n newNode
3. Run cluvfy from any existing node
cluvfy stage -pre nodeadd -n <New Node>
Note : If cluvfy in above step shows any errors fix those and then proceed with this step
4. Change Directory to Clusterware Home and execute addNode scripts from any existing node.
cd $CRS_HOME/oui/bin
./addNode.sh -silent "CLUSTER_NEW_NODES={ <NewNode > } CLUSTER_NEW_PRIVATE_NODE_NAMES={ <Interconnect >} CLUSTER_NEW_VIRTUAL_HOSTNAMES={ < Virtual Host Name >}"
At the end of addNode, script will prompt to run for root.sh on newly added node.
5. Verify Node is successfully added
cluvfy stage -post nodeadd -n <NewNode >
6. Verify CRS Stack is running on the new Node.
$CRS_HOME/bin/crs_stat -t
7. To extend the Oracle RAC Installation to include the new Node, run addNode from $ORACLE_HOME/oui/bin from existing node in the cluster
cd $CRS_HOME/oui/bin
./addNode.sh
When OUI displays the Specify Cluster Nodes to Add to Installation window, select the node to be added, then click Next .
Verify the summary and run root.sh on new node when it prompts.
8. Adding New Instance on the New Node
$CRS_HOME/bin/lsnrctl status
9.Run $ORACLE_HOME/bin/dbca from any of the existing RAC Instances Oracle Home.
Select Oracle Real Application Clusters database , and then click Next .
Select Instance Management , and then click Next .
Select Add an Instance , then click Next .
Click Next to accept default instance name or it can be changed.
Check the summary window.
Note: Please check these steps in test environment first.
HTH
Maybe you are looking for
-
Reporting Services Error after Interactive sorting and drill down in pps
Hi i have a report that has a drill down option that shows all workgroups within a specific parent group and an interactive sorting ass well on both columns parent group & workgroup This is displayed in pps combined with a SharePoint ---the pr
-
PlayReady failure with specific OS version of Windows 8.1 Update
Hello, I'm observing a failure in my app during Smooth Streaming video playback using PlayReady DRM. The app is a WinJS Universal App solution for Windows Store and Windows Phone, using the latest updates for Visual Studio 2013, Update 4. So far, the
-
HttpSession getAttribute() generics
Hi, I am trying to get a List<String> from an HttpSession List<String> titles = (ArrayList<String>) thisSession.getAttribute("titles"); I am getting a compiler warning, unchecked cast. I found the following method that solves the warning: private sta
-
How export my vector flash to illustrator?
Hi, In all software adobe CC the .fxg extenxtion has remove (she is abandoned), Now how can I export my vector illustrations to Illustrator?
-
Grant Permission in BPEL Domain
I, i need the execute the command to grant permission in domain BPEL: java -Xbootclasspath/a:/home/oc4j/bpel/lib/orabpel-boot.jar -jar jazn.jar -shell -grantperm jazn.com -role BPMsoaAdminDomainAdmin com.collaxa.security.DomainPermission soaAdmin all