Oracle Tree Hierarchy Query
Hi,
Hoping someone can assist with this query:
I am currently using this query to construct a tree hierarchy, i.e.
SELECT "EMP"."MGR" as "MGR",
"EMP"."EMPNO" as "EMPNO",
"EMP"."ENAME" as "ENAME" ,
(select count(*) from "EMP" "EMP2" where "EMP2"."MGR" = "EMP"."EMPNO") BranchCount
from
"EMP" "EMP"
where
"EMP"."MGR" = :BRANCH_IDUsing this query, I also need to retrieve the LEVEL pseudo-column as well for each record retrieved as I need the LEVEL info for trying to determine at what level of the tree I am at.
I would actually like to incorporate the LEVEL column into the above query - is this possible?
Thanks.
Tony.
SQL> desc test
Name Null? Type
COLUMN1 VARCHAR2(10)
COLUMN2 VARCHAR2(10)
MGR VARCHAR2(10)
SQL> select * from test
2 /
COLUMN1 COLUMN2 MGR
1 a 33
3 i 33
2 g 33
4 b 33
5 c 44
6 d 44
22 e
33 f 22
44 h 22
9 rows selected.
SQL> select column1, column2, mgr, level
2 from test
3 start with mgr = '22'
4 connect by prior column1 = mgr
5 order by level
6 /
COLUMN1 COLUMN2 MGR LEVEL
33 f 22 1
44 h 22 1
6 d 44 2
4 b 33 2
5 c 44 2
3 i 33 2
1 a 33 2
2 g 33 2
8 rows selected.
Similar Messages
-
Get only last level in SQL Hierarchy Query
Hi,
How to get only the last level in Oracle SQL Hierarchy Query?
ThanksHi,
1007372 wrote:
Hi,
How to get only the last level in Oracle SQL Hierarchy Query?Depending on your requirements:
WHERE CONNECT_BY_ISLEAF = 1
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
If you can show what you want to do using commonly available tables (such as scott.emp, which contains a hierarchy), then you don't need to post any sample data; just the results and the explanation.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0). This is always important, but especially so with CONNECT BY queries, because every version since Oracle 7 has had significant improvements in this area.
See the forum FAQ {message:id=9360002} -
Hierarchy Query For Full Tree ?
Hi Everyone,
I want to write a hierarchy query which should give me the whole path starting from root node to each individual nodes by passing value of any individual tree member. below is the sample data and the output what i am expecting. and also the output what i am getting right now from my query.
CREATE TABLE RELATION (PARENT VARCHAR2(1),CHILD VARCHAR2(1) PRIMARY KEY);
--Data for the tree which starts from the root 'A'
Insert into RELATION (PARENT, CHILD) Values (NULL,'A');
Insert into RELATION (PARENT, CHILD) Values ('A', 'B');
Insert into RELATION (PARENT, CHILD) Values ('A', 'C');
Insert into RELATION (PARENT, CHILD) Values ('B', 'D');
Insert into RELATION (PARENT, CHILD) Values ('B', 'E');
Insert into RELATION (PARENT, CHILD) Values ('D', 'F');
Insert into RELATION (PARENT, CHILD) Values ('C', 'G');
--Data for the tree which starts from the root 'H'
Insert into RELATION (PARENT, CHILD) Values (NULL,'H');
Insert into RELATION (PARENT, CHILD) Values ('H', 'I');
Insert into RELATION (PARENT, CHILD) Values ('H', 'J');
Expected Output by passing values as 'C' which gives the whole tree where the node C is present:
A
A->B
A->C
A->B->D
A->B->E
A->C->G
A->B->D->F
My Query:
select
sys_connect_by_path(child,'->') tree
from
relation
--where (parent ='C' or child='C')
start with
parent is null
connect by
prior child = parent
order by tree;
Output of my query:
->A
->A->B
->A->B->D
->A->B->D->F
->A->B->E
->A->C
->A->C->G
->H
->H->I
->H->J
I am not able to add the condition for the query so that i can get only rows of the tree where the nod 'C' is present. i am just getting whole data from the table with all the unwanted trees.
Can anyone please help me in getting the correct output.
Thank you in advance.odie_63 wrote:
Another solution, involving analytics : Hierarchical queries and analytic functions do not mix well together in 10g:
SQL> select * from v$version
2 /
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for 32-bit Windows: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL> SELECT tree
2 FROM (
3 select sys_connect_by_path(child,'->') tree,
4 max(case when child = 'C' then connect_by_root(child) end) over() root1,
5 connect_by_root(child) root2
6 from relation
7 start with parent is null
8 connect by prior child = parent
9 )
10 WHERE root1 = root2
11 ;
from relation
ERROR at line 6:
ORA-00600: internal error code, arguments: [qctcte1], [0], [], [], [], [], [], []
SQL> Although it is much better in 11g:
SQL> select * from v$version
2 /
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> SELECT tree
2 FROM (
3 select sys_connect_by_path(child,'->') tree,
4 max(case when child = 'C' then connect_by_root(child) end) over() root1,
5 connect_by_root(child) root2
6 from relation
7 start with parent is null
8 connect by prior child = parent
9 )
10 WHERE root1 = root2
11 ;
TREE
->A
->A->B
->A->B->D
->A->B->D->F
->A->B->E
->A->C
->A->C->G
7 rows selected.
SQL> SY. -
BW Tree Hierarchy-multiple selection for query possible?
Hello,
I have a question in regards to BW Tree Hierarchies and its usage in Bex Reporting:
Is it possible to select multible Tree Hierarchy (based on the same characteristic) when executing a query in Bex Analyzer. If yes, how?
I tried to configure this by making use of a hierarchy variable on the characteristics, but it does only allow me to select one hierarchy.
Thanks for your help,
ElisabethElisabeth,
Your query can only assign one hierarchy per characteristic.
If you need multiple ones - I'd suggest you make a query per hierarchy and you can user Query Views in the WAD to let the user select the View (i.e.. the Hierarchy) they wise.
Regards
Gill -
Oracle HRMS Organization Hierarchy query
Dear All,
Could any one provide me Oracle HRMS Organization Hierarchy query, please find the attachment of navigation.
and please find the following query i developed, here i am getting all hierarchies as per attachment.
SELECT distinct pose.D_PARENT_NAME , pose.org_structure_version_id,pose.organization_id_parent,
haou2.ORGANIZATION_ID PARENT_ID_ORG,
pose.D_CHILD_NAME
FROM apps.per_organization_structures_v pos
, apps.per_org_structure_versions posv
, apps.per_org_structure_elements_v pose
, apps.hr_all_organization_units haou2
WHERE pos.name = 'PIC HR ORGANIZATION HIERARCHY'
AND pose.D_PARENT_NAME='CHAIRMAN'
AND pose.org_structure_version_id = posv.org_structure_version_id
AND posv.organization_structure_id = pos.organization_structure_id
AND haou2.organization_id = pose.organization_id_child
and pose.D_PARENT_NAME=nvl(:P_PARENT_NAME,pose.D_PARENT_NAME)
and pose.D_CHILD_NAME=nvl(:P_CHILD_NAME,pose.D_CHILD_NAME)
and sysdate between posv.DATE_FROM and nvl(posv.DATE_TO,sysdate)
CONNECT BY PRIOR pose.organization_id_parent = pose.organization_id_child
can any one help me on this??
Thanks in advance..
Best RegardsHi,
Try the following query and adapt as required for your instance (I've used Vision instance):
SELECT DISTINCT pose.d_parent_name,
pose.organization_id_parent,
pose.d_child_name,
pose.organization_id_child
FROM
per_org_structure_elements_v pose,
per_org_structure_versions posv,
per_organization_structures pos
WHERE pos.name = 'Primary Reporting Hierarchy'
AND posv.version_number = 1
AND pos.business_group_id = 202
AND posv.organization_structure_id = pos.organization_structure_id
AND pose.org_structure_version_id = posv.org_structure_version_id
AND pose.business_group_id = pos.business_group_id
AND posv.business_group_id = pose.business_group_id
START WITH pose.d_parent_name = 'Vision Operations'
CONNECT BY NOCYCLE PRIOR pose.organization_id_child = pose.organization_id_parent
ORDER BY pose.organization_id_parent, pose.organization_id_child
HTH,
Regards,
Rajen.
P.S: Please mark response as Helpful/Correct (Answered) if it resolves or helps to resolve your issue. Thks. -
Cosider the following record set from the emp table.
empno ename mgr
7839 KING
7566 SCOTT 7839
7566 BLAKE 7839
7782 CLARK 7839
If I use the following hierarchial query to populate a tree in Oracle forms
I will get the result as shown below.
Query
=====
select -1, level, ename, null, ename
from emp
where empno in (7839,7566,7698,7782)
start with ename = 'KING'
connect by mgr = prior empno;
Result
======
KING
JONES
BLAKE
CLARK
Here is my problem. Though diffrent employees can work under a manager,
we have some internal rules that assigns an order to each employee who
works under a manager. This helps us in identifying who should take
charge in the absence of a manager.
I have added one column to the emp table, in order to store the order in
which the employee reports to the manager.
Now the record set becomes
empno ename mgr emp_order
7839 KING 0
7566 SCOTT 7839 1
7566 BLAKE 7839 3
7782 CLARK 7839 2
Now I want the forms tree to be displayed as shown below.
KING
JONES
CLARK
BLAKE
(In short, I want the records in a particular level to be displayed
according to a pre-defined order, rather than getting them displayed
randomly).
Which query can I use for this purpose ?
Please help....
ShibuHi Guys,
Thanks a lot for your suggestions.
It really works great in SQL Plus.
I am familiar with Oracle Forms and I know how to use it if I want to build a tree in Forms.
Here is my requirement. I want to build the application using Oracle Portal. I know that there is something called 'Hierarchy' available in Portal. I don't know up to what extend it gives flexibility in programatically populating the tree.
Here is the scenario. I will use the hierarchial query with CONNECT SIBLINGS BY clause to populate the a tree which will show me employees in a department hierarchially.
Eg:
KING
SCOTT
BLAKE
SMITH
Now I like to show the projects assigned to each employee, which itself can be considered as another hierarchy.
Eg of Projects hierarchy.
Projects
Development
Oracle Applications
HRMS
Support
Intranet Applications
Suppose SCOTT is working in HRMS project, the tree should show as,
KING
SCOTT
Projects
Development
Oracle Applications
HRMS
BLAKE
SMITH
I can color code the node which will distinguish between an employee and his assignments.
Is there a way to achieve it in Oracle Portal using the 'Hierarchy' or what may be the best way to go (Applet etc...) ???
Thanks in advance for your help.
Shibu -
Hierarchy Query to get parent nodes?
Hi Everyone,
I want to write a hierarchy query which should give me the path starting from given node to its parents(Grand parents). below is the sample data and the output what i am expecting. and also the output what i am getting right now from my query.
CREATE TABLE RELATION (PARENT VARCHAR2(5),CHILD VARCHAR2(5) PRIMARY KEY);
--Data for the tree which starts from the root 'A'
Insert into RELATION (PARENT, CHILD) Values (NULL,'A');
Insert into RELATION (PARENT, CHILD) Values ('A', 'B');
Insert into RELATION (PARENT, CHILD) Values ('A', 'C');
Insert into RELATION (PARENT, CHILD) Values ('B', 'D');
Insert into RELATION (PARENT, CHILD) Values ('B', 'E');
Insert into RELATION (PARENT, CHILD) Values ('D', 'F');
Insert into RELATION (PARENT, CHILD) Values ('C', 'G');
--Data for the tree which starts from the root 'H'
Insert into RELATION (PARENT, CHILD) Values (NULL,'H');
Insert into RELATION (PARENT, CHILD) Values ('H', 'I');
Insert into RELATION (PARENT, CHILD) Values ('H', 'J');
Expected Output by passing values as 'F' which gives the path from bottom to up.
A<-B<-D<-F
My Query:
SELECT substr(sys_connect_by_path(child,'<-'),3)
FROM relation
WHERE connect_by_isleaf = 1
START WITH child = 'F'
CONNECT BY PRIOR parent = child
ORDER BY child;
Output of my query:
F<-D<-B<-A
I am getting the output in reverse order. i can use the reverse string function to reverse the string but the problem is the node can also contain the values like 'AC' 'BA'.. in future.
Can anyone please help me in getting the correct output.
Thank you in advance.I like ListAgg :D
with RELATION(PARENT,CHILD) as(
select NULL,'A' from dual union all
select 'A', 'B' from dual union all
select 'A', 'C' from dual union all
select 'B', 'D' from dual union all
select 'B', 'E' from dual union all
select 'D', 'F' from dual union all
select 'C', 'G' from dual union all
select NULL,'H' from dual union all
select 'H', 'I' from dual union all
select 'H', 'J' from dual)
SELECT ListAgg(child,'<-')
within group(order by Level desc) as revPath
FROM relation
START WITH child = 'F'
CONNECT BY PRIOR parent = child;
revPath
A<-B<-D<-F -
How to save the tree hierarchy into an excel
Is there any untility avaliable in Application express to save the tree hierarchy into an excel, when shown in a page.
Using this example, you may export any query:
http://spendolini.blogspot.com/2006/04/custom-export-to-csv.html
Denes Kubicek -
Hi All,
I need supervisor assignment hierarchy query(HRMS), for generating report.
can someone help me on this??
Any help is greately appreciated.
Regards
GopiHello everyone
When i am trying to execute following query, i am getting an error like
ORA-01473
Cannot Have Sub Queries in Connect By Clause
It display the hierarchy starting from our board of directors in a descending manner
SELECT LPAD ('->', 8 * (LEVEL - 1))
|| (SELECT DISTINCT full_name
FROM per_all_people_f
WHERE person_id = paf.person_id
AND PERSON_TYPE_ID '1123' -- 1123 = 'Ex-Employee'
AND SYSDATE BETWEEN effective_start_date
AND effective_end_date)
TREE
FROM per_all_assignments_f paf
WHERE SYSDATE BETWEEN paf.effective_start_date
AND paf.effective_end_date
AND paf.primary_flag = 'Y'
and paf.person_id in
(select pf.person_id from per_all_people_f pf where pf.PERSON_TYPE_ID '1123' and paf.person_id = pf.person_id
AND SYSDATE BETWEEN pf.effective_start_date
AND pf.effective_end_date
START WITH paf.person_id = (select person_id from per_all_people_f where last_name ='Board of') -- Board of Directors
CONNECT BY PRIOR paf.person_id = paf.supervisor_id
AND paf.primary_flag = 'Y'
AND paf.person_id in (select person_id from per_all_people_f pf where paf.person_id = pf.person_id and pf.PERSON_TYPE_ID'1123')
AND SYSDATE BETWEEN paf.effective_start_date
AND paf.effective_end_date
Could anyone help me on this??
Regards
Gopi -
How can I create a tree hierarchy in Adobe Flash with WD Java?
Hello!
I've started to learning RIAs based on WD Java and Adobe Flash. Now I need to create application with tree hierarchy. Nodes of hierarchy must be able to collapse and expand. Hierarchy must looks like in https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/a0c91fc0-932d-2c10-4ca7-f5774950c8e3 (first section)
Does anybody know where I can get a tutorial for such hierarhies or which control element I have use?
regards, Levwell, Network UI should be used.
-
Hello All,
I have searched OTN and AskTom and saw many articles on hierarchial query but I just cannot seem to figure out how to apply it to my situation. Based on what I have read I do not believe CUBE or ROLLUP is the answer for this (maybe wrong..).
This data is only a small part of a much larger query used for auditing purposes, so i would need to incorporate the solution for this into the larger query.
Part of my problem is how to actual present this data in a format that would make sense to the end user, when included in a tabular (Excel) report.
I am trying to devise a way to verify that monthly payment is received for each product. In this case, some of the products are "created" under another product and then billed under a 3rd product.
To explain the table
Prod_1 - list all products
Prod_2 - lists only those products that are the parent of an item in the Prod_1 column.
Prod_3 - shows there is a relationship between an item in Prod_1 that is not in Prod_2.
There may be items in Prod_1 that have no relationship to Prod_2 or Prod_3 are those are just billed or *not getting billed BAD*
There are other cases where there is a item in Prod_2 that is the parent of one or more items in Prod_1 but not related to Prod_3 and those are billed.
There are other cases where there is a item in Prod_2 that is the parent of one or more items in Prod_1 but not related to Prod_3 and *not getting billed BAD*
For example:
+1-abcd-efgh, 3-qrst-uvwx and 5-ghij-klmn+ under Prod_1 is created under Prod_2 +1234-2f-maker-taker+ but billed under Prod_3 +87-test-789101+ at $139.11 MONTH_CHARGE.
CREATE TABLE PRODT ( design_id VARCHAR2(50), Prod_1 VARCHAR2(50), Prod_2 VARCHAR2(50), Prod_3 VARCHAR2(50), Month_Charge NUMBER );
INSERT INTO PRODT VALUES ( '8568','1-abcd-efgh', '1234-2f-maker-taker','', 0 );
INSERT INTO PRODT VALUES ( '8569','2-ijkl-mnop', '5678-3f-maker-taker','', 0 );
INSERT INTO PRODT VALUES ( '8570','3-qrst-uvwx', '1234-2f-maker-taker','', 0 );
INSERT INTO PRODT VALUES ( '8571','4-yzab-cdef', '5678-3f-maker-taker','', 0 );
INSERT INTO PRODT VALUES ( '8572','5-ghij-klmn', '1234-2f-maker-taker','', 0 );
INSERT INTO PRODT VALUES ( '9421','1234-2f-maker-taker','','87-test-789101', 0 );
INSERT INTO PRODT VALUES ( '9588','5678-3f-maker-taker','','88-test-123456', 0 );
INSERT INTO PRODT VALUES ( '2531','87-test-789101', '', '1234-2f-maker-taker',139.11 );
INSERT INTO PRODT VALUES ( '2532','88-test-123456', '','5678-3f-maker-taker', 159.45 );
INSERT INTO PRODT VALUES ( '4531','76-test-101568', '', '',145.00 );
INSERT INTO PRODT VALUES ( '3528','6-abcd-efgh', '2234-1f-maker-taker','', 0 );
INSERT INTO PRODT VALUES ( '3529','7-ijkl-mnop', '2234-1f-maker-taker','', 0 );
INSERT INTO PRODT VALUES ( '6261','2234-1f-maker-taker','','', 0 );
COMMIT; Desired Result:
Honestly - I am not sure of the best way to present it - definetly open for suggestions!
The table shows there is a relationship by Product Number, but the table does not make it clear that as in the example above that
all of the underlying products are being billed under +87-test-789101+ at $139.11 per month.
I must still show all of the Prod columns - so for my understanding Cube or Rollup is not a good fit(?).
That is what I am trying to accomplish - in other words I am getting paid for everything or not?
In my mind I see it something like this perhaps:
DESIGN_ID PROD_1 PROD_2 PROD_3 MONTH_CHARGE BILL_INDICATOR
8569 2-ijkl-mnop 5678-3f-maker-taker NULL 0 ? (Not sure how to indicate
8571 4-yzab-cdef 5678-3f-maker-taker NULL 0 what should be displayed
9588 5678-3f-maker-taker NULL 88-test-123456 0 in this new column to make
2532 88-test-123456 NULL 5678-3f-maker-taker 159.45 the Audit process simple *Help Needed*)Thanks for looking!
G
Edited by: GMoney on Aug 22, 2012 12:54 PM
Edited by: GMoney on Aug 22, 2012 12:57 PMFrank,
I was hoping you would cross paths with this post.
I am building on a TOP N query you helped me with in another post.
As I mentioned in my an initial post, I have products that may be in a hierarchical order (or stand alone) could be billed as primary or with secondary or tertiary products that are billed under the primary. Meaning the primary would have a dollar figure associated, and may or may not have secondary or tertiary products related to it.
To explain the table
Prod_1 - list all products
Prod_2 - lists only those products that are the parent of an item in the Prod_1 column.
Prod_3 - shows there is a relationship between an item in Prod_1 that is not in Prod_2.
There may be items in Prod_1 that have no relationship to Prod_2 or Prod_3 are those are just billed or not getting billed BAD
There are other cases where there is a item in Prod_2 that is the parent of one or more items in Prod_1 but not related to Prod_3 and those are billed.
There are other cases where there is a item in Prod_2 that is the parent of one or more items in Prod_1 but not related to Prod_3 and not getting billed BAD
My business requirement is to present all of the results from the initial query as well as adding in the dollar figures from an addition query against another financial table. I need to be able to make it perfectly clear to an end user auditor that each and every product is being billed, and clearly identify the secondary or tertiary items if there are any that fall under that primary product.
My real hung up here is the presentation of the data. I can easily see the correlation between them but it is not likely an end user would.
DESIGN_ID PROD_1 PROD_2 PROD_3 MONTH_CHARGE BILL_INDICATOR
8569 2-ijkl-mnop 5678-3f-maker-taker NULL 0 ? (Not sure how to indicate
8571 4-yzab-cdef 5678-3f-maker-taker NULL 0 what should be displayed
9588 5678-3f-maker-taker NULL 88-test-123456 0 in this new column to make
2532 88-test-123456 NULL 5678-3f-maker-taker 159.45 ; the Audit process simple *Help Needed*) Thanks for looking,
Greg -
Hi All..
I have a hierarchy query with description as below
SQL> desc manager_entity;
Name Null? Type
MANAGER_ENTITY_ID NOT NULL NUMBER
MANAGER_ENTITY_TYPE_ID NOT NULL NUMBER
MANAGER_ENTITY_PARENT_ID NUMBER
CREATE_USER NOT NULL VARCHAR2(50)
CREATE_DATETIME NOT NULL DATE
LAST_UPDATE_USER NOT NULL VARCHAR2(50)
LAST_UPDATE_DATETIME NOT NULL DATE
MANAGER_ENTITY_LINK_ID NOT NULL NUMBERI got the correct relation between the parent and child using the below query
select me.manager_entity_id
, me.manager_entity_type_id
, me.manager_entity_parent_id
, me.manager_entity_link_id
, level
from manager_entity me
start with me.manager_entity_id=:p_id
connect by prior me.manager_entity_id=me.manager_entity_parent_idWhen I try to join this table with other 3 tables I’m unable to retrieve data. Description of the other 3 tables
SQL> desc manager_product;
Name Null? Type
MANAGER_PRODUCT_ID NOT NULL NUMBER
MANAGER_PRODUCT_NAME NOT NULL VARCHAR2(50)
MANAGER_ROOF_ID NOT NULL NUMBER
ACT_STRATEGY VARCHAR2(50)
ACT_SUB_STRATEGY VARCHAR2(50)
ACT_DATE_ENTERED DATE
ACT_INCEPTION_DATE DATE
ACT_PEER_GROUP VARCHAR2(50)
BACK_OFFICE_RISK_ID NUMBER
AREA_ID NUMBER
ACT_CREATE_DATE DATE
PROCESS_STOP_DATE DATE
TARGET_COMPLETION_DATE DATE
REVISIT_DATE DATE
CREATE_USER VARCHAR2(50)
CREATE_DATETIME DATE
LAST_UPDATE_USER VARCHAR2(50)
LAST_UPDATE_DATETIME DATE
SQL> desc manager_roof;
Name Null? Type
MANAGER_ROOF_ID NOT NULL NUMBER
MANAGER_ROOF_NAME NOT NULL VARCHAR2(50)
ROOF_COMPANY_ID NOT NULL NUMBER
CREATE_USER VARCHAR2(50)
CREATE_DATETIME DATE
LAST_UPDATE_USER VARCHAR2(50)
LAST_UPDATE_DATETIME DATE
SQL> desc investment_vehicle;
Name Null? Type
INVESTMENT_VEHICLE_ID NOT NULL NUMBER
INVESTMENT_VEHICLE_NAME NOT NULL VARCHAR2(255)
INVESTMENT_VEHICLE_ARRT_NAME VARCHAR2(255)
INVESTIER_SYSID NUMBER
INVESTIER_ID VARCHAR2(100)
MANAGER_PRODUCT_ID NUMBER
TRADING_STRUCTURE_TYPE_ID NUMBER
LEGAL_DESIGNATION_ID NUMBER
ADDITIONAL_INVEST_FORM_TYPE_ID NUMBER
INVESTMENT_VEH_CLASS_TYPE_ID NUMBER
ERISA_PLAN_ASSET_CATEGORY_ID NUMBER
SIDE_LETTER_FLAG CHAR(1)
INCEPTION_DATE DATE
ALLOW_ERISA_FLAG CHAR(1)
ALLOW_PLAN_ASSET_FLAG CHAR(1)
ALLOW_US_TAXABLE_INVESTOR_FLAG CHAR(1)
ALLOW_OFFSHORE_INVESTOR_FLAG CHAR(1)
SUB_DOC_DEADLINE NUMBER
WIRE_DEADLINE NUMBER
DOMICILE_COUNTRY_ID NUMBER
CREATE_USER VARCHAR2(50)
CREATE_DATETIME DATE
LAST_UPDATE_USER VARCHAR2(50)
LAST_UPDATE_DATETIME DATE
PERTRAC_DATA_VENDOR_ID VARCHAR2(255)
PERTRAC_DATA_VENDOR_NAME VARCHAR2(255)
FTS_NAME VARCHAR2(255)
MATLAB_MANAGER_NAME VARCHAR2(255)
ACT_CO_FUND_NAME VARCHAR2(255)
ACT_INVESTMENT_VEHICLE_NAME VARCHAR2(255)
SIDE_POCKET_PCT NUMBER
MAX_ILLIQUID_PCT NUMBER
CONTRIBUTION_OPENING_ID NUMBER
MANAGEMENT_FEE_PCT NUMBER
INCENTIVE_FEE_PCT NUMBER
SIDE_POCKET_NOTE VARCHAR2(4000)
FTS_ID NUMBERI was trying to join the other 3 tables with the main query as below..
select me.manager_entity_id
, me.manager_entity_type_id
, me.manager_entity_parent_id
, me.manager_entity_link_id
, level
from manager_entity me
, manager_roof mr
, manager_product mp
, investment_vehicle iv
where me.manager_entity_link_id= mr.manager_roof_id
and mr.manager_roof_id= mp.manager_roof_id
and mp.manager_product_id= iv.manager_product_id
start with me.manager_entity_id=:p_id
connect by prior me.manager_entity_id=me.manager_entity_parent_idHere manager_entity_link_id of manager_entity table represents(or has) the primary key of all the other 3 table..like
Enter value for p_id: 1
old 7: start with me.manager_entity_id=&p_id
new 7: start with me.manager_entity_id=1
MANAGER_ENTITY_ID MANAGER_ENTITY_TYPE_ID MANAGER_ENTITY_PARENT_ID
MANAGER_ENTITY_LINK_ID LEVEL
1 1008
14793 1
263 1009 1
19695 2
803 1010 263
7031783 3
MANAGER_ENTITY_ID MANAGER_ENTITY_TYPE_ID MANAGER_ENTITY_PARENT_ID
MANAGER_ENTITY_LINK_ID LEVEL
804 1010 263
7031782 3
805 1010 263
7031781 3The above is the output for the hierarchy query
Here the MANAGER_ENTITY_LINK_ID has values (14793, 19695, 7031783 , 7031782 , 7031781)
Where 14793 is the manager_roof_id in manager_roof_table
19695 is the manager_product_id in the manager_product table
7031783 , 7031782 , 7031781 are the investment_vehicle_id’s in the investment_vehicle table…
In the output I need to retrieve manager_roof_name, manager_product_name, investment_vehicle_name..
Thanks in advance
HTH
Edited by: user10280715 on Dec 3, 2008 11:55 AMThe reason result show as no rows selected is your first insert. If fails since column list has 3 columns while values list has 4 values. You probably missed "ORA-00913: too many values" error:
SQL> drop table manager_entity
2 /
Table dropped.
SQL> create table manager_entity(manager_entity_id number,manager_entity_type_id number,manager_entity_parent_id number,manager_entity_link_id number)
2 /
Table created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_link_id)
2 values(1,1008,null,14793)
3 /
insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_link_id)
ERROR at line 1:
ORA-00913: too many values
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(263, 1009, 1, 19695)
3 /
1 row created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(803, 1010, 263, 7031783)
3 /
1 row created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(804, 1010, 263, 7031782)
3 /
1 row created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(805, 1010, 263, 7031781)
3 /
1 row created.
SQL> drop table manager_roof
2 /
Table dropped.
SQL> create table manager_roof(manager_roof_id number,manager_roof_name varchar2(20))
2 /
Table created.
SQL> insert into manager_roof(manager_roof_id,manager_roof_name)
2 values(14793,'roof')
3 /
1 row created.
SQL> drop table manager_product
2 /
Table dropped.
SQL> create table manager_product(manager_product_id number,manager_product_name varchar2(20),manager_roof_id number)
2 /
Table created.
SQL> Insert into manager_product(manager_product_id,manager_product_name,manager_roof_id)
2 Values(19695,'product1', 14793)
3 /
1 row created.
SQL> drop table investment_vehicle
2 /
Table dropped.
SQL> create table investment_vehicle(investment_vehicle_id number,manager_product_id number,investment_vehicle_name varchar2(20))
2 /
Table created.
SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
2 Values(7031781,19695,'inv1')
3 /
1 row created.
SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
2 Values(7031782,19695,'inv3')
3 /
1 row created.
SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
2 Values(7031783,19695,'inv3')
3 /
1 row created.
SQL> COMMIT
2 /
Commit complete.
SQL>
SQL> select me.manager_entity_id
2 , me.manager_entity_type_id
3 , me.manager_entity_parent_id
4 , me.manager_entity_link_id
5 , level
6 from manager_entity me
7 start with me.manager_entity_id=&p_id
8 connect by prior me.manager_entity_id=me.manager_entity_parent_id
9
SQL> /
Enter value for p_id: 1
old 7: start with me.manager_entity_id=&p_id
new 7: start with me.manager_entity_id=1
no rows selectedAs soon as you fix the error:
SQL> drop table manager_entity
2 /
Table dropped.
SQL> create table manager_entity(manager_entity_id number,manager_entity_type_id number,manager_entity_parent_id number,manager_entity_link_id number)
2 /
Table created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(1,1008,null,14793)
3 /
1 row created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(263, 1009, 1, 19695)
3 /
1 row created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(803, 1010, 263, 7031783)
3 /
1 row created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(804, 1010, 263, 7031782)
3 /
1 row created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(805, 1010, 263, 7031781)
3 /
1 row created.
SQL> drop table manager_roof
2 /
Table dropped.
SQL> create table manager_roof(manager_roof_id number,manager_roof_name varchar2(20))
2 /
Table created.
SQL> insert into manager_roof(manager_roof_id,manager_roof_name)
2 values(14793,'roof')
3 /
1 row created.
SQL> drop table manager_product
2 /
Table dropped.
SQL> create table manager_product(manager_product_id number,manager_product_name varchar2(20),manager_roof_id number)
2 /
Table created.
SQL> Insert into manager_product(manager_product_id,manager_product_name,manager_roof_id)
2 Values(19695,'product1', 14793)
3 /
1 row created.
SQL> drop table investment_vehicle
2 /
Table dropped.
SQL> create table investment_vehicle(investment_vehicle_id number,manager_product_id number,investment_vehicle_name varchar2(20))
2 /
Table created.
SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
2 Values(7031781,19695,'inv1')
3 /
1 row created.
SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
2 Values(7031782,19695,'inv3')
3 /
1 row created.
SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
2 Values(7031783,19695,'inv3')
3 /
1 row created.
SQL> COMMIT
2 /
Commit complete.
SQL>
SQL> select me.manager_entity_id
2 , me.manager_entity_type_id
3 , me.manager_entity_parent_id
4 , me.manager_entity_link_id
5 , level
6 from manager_entity me
7 start with me.manager_entity_id=&p_id
8 connect by prior me.manager_entity_id=me.manager_entity_parent_id
9
SQL> /
Enter value for p_id: 1
old 7: start with me.manager_entity_id=&p_id
new 7: start with me.manager_entity_id=1
MANAGER_ENTITY_ID MANAGER_ENTITY_TYPE_ID MANAGER_ENTITY_PARENT_ID MANAGER_ENTITY_LINK_ID LEVEL
1 1008 14793 1
263 1009 1 19695 2
803 1010 263 7031783 3
804 1010 263 7031782 3
805 1010 263 7031781 3
SQL> SY. -
Oracle Text contain query limit with 9i
The Oracle Text contain query is defined as this:
CONTAINS(
[schema.]column,
text_query VARCHAR2
[,label NUMBER])
RETURN NUMBER;
Is the size limit of text_query 4000 bytes with 9i? Is it increased with 10g or is it accepting CLOB in 10g?
I always got the error: "ORA-01460: unimplemented or unreasonable conversion requested" when I do the following where p_var was dynamically passed with size of more than 4000 bytes:
p_statement varchar2(20000);
p_var varchar2(8000);
p_statement := select count(*) from dewey_table where contains(concat, :x)>0;
open m_cursor for p_statement using p_var;
Thanks very much,
KevinThe limit is definitely 4000 characters in 9i and the 10g documentation shows no change in the calling spec for that parameter.
-
Oracle date parameter query not working?
http://stackoverflow.com/questions/14539489/oracle-date-parameter-query-not-working
Trying to run the below query, but always fails even though the parameter values matches. I'm thinking there is a precision issue for :xRowVersion_prev parameter. I want too keep as much precision as possible.
Delete
from CONCURRENCYTESTITEMS
where ITEMID = :xItemId
and ROWVERSION = :xRowVersion_prev
The Oracle Rowversion is a TimestampLTZ and so is the oracle parameter type.
The same code & query works in Sql Server, but not Oracle.
Public Function CreateConnection() As IDbConnection
Dim sl As New SettingsLoader
Dim cs As String = sl.ObtainConnectionString
Dim cn As OracleConnection = New OracleConnection(cs)
cn.Open()
Return cn
End Function
Public Function CreateCommand(connection As IDbConnection) As IDbCommand
Dim cmd As OracleCommand = DirectCast(connection.CreateCommand, OracleCommand)
cmd.BindByName = True
Return cmd
End Function
<TestMethod()>
<TestCategory("Oracle")> _
Public Sub Test_POC_Delete()
Dim connection As IDbConnection = CreateConnection()
Dim rowver As DateTime = DateTime.Now
Dim id As Decimal
Using cmd As IDbCommand = CreateCommand(connection)
cmd.CommandText = "insert into CONCURRENCYTESTITEMS values(SEQ_CONCURRENCYTESTITEMS.nextval,'bla bla bla',:xRowVersion) returning ITEMID into :myOutputParameter"
Dim p As OracleParameter = New OracleParameter
p.Direction = ParameterDirection.ReturnValue
p.DbType = DbType.Decimal
p.ParameterName = "myOutputParameter"
cmd.Parameters.Add(p)
Dim v As OracleParameter = New OracleParameter
v.Direction = ParameterDirection.Input
v.OracleDbType = OracleDbType.TimeStampLTZ
v.ParameterName = "xRowVersion"
v.Value = rowver
cmd.Parameters.Add(v)
cmd.ExecuteNonQuery()
id = CType(p.Value, Decimal)
End Using
Using cmd As IDbCommand = m_DBTypesFactory.CreateCommand(connection)
cmd.CommandText = " Delete from CONCURRENCYTESTITEMS where ITEMID = :xItemId and ROWVERSION = :xRowVersion_prev"
Dim p As OracleParameter = New OracleParameter
p.Direction = ParameterDirection.Input
p.DbType = DbType.Decimal
p.ParameterName = "xItemId"
p.Value = id
cmd.Parameters.Add(p)
Dim v As OracleParameter = New OracleParameter
v.Direction = ParameterDirection.Input
v.OracleDbType = OracleDbType.TimeStampLTZ
v.ParameterName = "xRowVersion_prev"
v.Value = rowver
v.Precision = 6 '????
cmd.Parameters.Add(v)
Dim cnt As Integer = cmd.ExecuteNonQuery()
If cnt = 0 Then Assert.Fail() 'should delete
End Using
connection.Close()
End Sub
Schema:
-- ****** Object: Table SYSTEM.CONCURRENCYTESTITEMS Script Date: 1/26/2013 11:56:50 AM ******
CREATE TABLE "CONCURRENCYTESTITEMS" (
"ITEMID" NUMBER(19,0) NOT NULL,
"NOTES" NCHAR(200) NOT NULL,
"ROWVERSION" TIMESTAMP(6) WITH LOCAL TIME ZONE NOT NULL)
STORAGE (
NEXT 1048576 )
Sequence:
-- ****** Object: Sequence SYSTEM.SEQ_CONCURRENCYTESTITEMS Script Date: 1/26/2013 12:12:48 PM ******
CREATE SEQUENCE "SEQ_CONCURRENCYTESTITEMS"
START WITH 1
CACHE 20
MAXVALUE 9999999999999999999999999999still not comming...
i have one table each entry is having only one fromdata and one todate only
i am running below in sql it is showing two rows. ok.
select t1.U_frmdate,t1.U_todate ,ISNULL(t2.firstName,'')+ ',' +ISNULL(t2.middleName ,'')+','+ISNULL(t2.lastName,'') AS NAME, T2.empID AS EMPID, T2.U_emp AS Empticket,t2.U_PFAcc,t0.U_pf
from [@PR_PRCSAL1] t0 inner join [@PR_OPRCSAL] t1
on t0.DocEntry = t1.DocEntry
inner join ohem t2
on t2.empID = t0.U_empid where t0.U_empid between '830' and '850' and t1.U_frmdate ='20160801' and t1.u_todate='20160830'
in commond promt
select t1.U_frmdate,t1.U_todate ,ISNULL(t2.firstName,'')+ ',' +ISNULL(t2.middleName ,'')+','+ISNULL(t2.lastName,'') AS NAME, T2.empID AS EMPID, T2.U_emp AS Empticket,t2.U_PFAcc,t0.U_pf
from [@PR_PRCSAL1] t0 inner join [@PR_OPRCSAL] t1
on t0.DocEntry = t1.DocEntry
inner join ohem t2
on t2.empID = t0.U_empid where t0.U_empid between {?FromEmid} and {?ToEmid} and t1.U_frmdate ={?FDate} and t1.u_todate={?TDate}
still not showing any results.. -
How to tune the performance of Oracle SQL/XML query?
Hi all,
I am running Oracle 9i and like to run the following Oracle SQL/XML query. It takes about 3+ hour and still not finish. If I get rid all the XML stuffs it only take minutes to run. Does anybody know how to what's the reason of this slow and how to tune it?
SELECT XMLElement("CUSTOMER",
XMLForest(C_CUSTKEY "C_CUSTKEY", C_NAME "C_NAME", C_ADDRESS "C_ADDRESS", C_PHONE "C_PHONE", C_MKTSEGMENT "C_MKTSEGMENT", C_COMMENT "C_COMMENT"),
(SELECT XMLAgg(XMLElement("ORDERS",
XMLForest(O_ORDERKEY "O_ORDERKEY", O_CUSTKEY "O_CUSTKEY", O_ORDERSTATUS "O_ORDERSTATUS", O_ORDERPRIORITY "O_ORDERPRIORITY", O_CLERK "O_CLERK", O_COMMENT "O_COMMENT"),
(SELECT XMLAgg(XMLElement("LINEITEM",
XMLForest(L_ORDERKEY "L_ORDERKEY", L_RETURNFLAG "L_RETURNFLAG", L_LINESTATUS "L_LINESTATUS", L_SHIPINSTRUCT "L_SHIPINSTRUCT", L_SHIPMODE "L_SHIPMODE", L_COMMENT "L_COMMENT")
FROM LINEITEM
WHERE LINEITEM.L_ORDERKEY = ORDERS.O_ORDERKEY)
FROM ORDERS
WHERE ORDERS.O_CUSTKEY = CUSTOMER.C_CUSTKEY)
FROM CUSTOMER ;
Thanks very much in advance for your time,
Jinghao Liuajallen wrote:
Why not something more like
SELECT *
FROM fact1 l,
FULL OUTER JOIN fact1 d
ON l.company = d.company
AND l.transactiontypeid = 1
AND d.transactiontypeid = 2;
Because this is not an equivalent of the original query.
drop table t1 cascade constraints purge;
drop table t2 cascade constraints purge;
create table t1 as select rownum t1_id from dual connect by level <= 5;
create table t2 as select rownum+2 t2_id from dual connect by level <= 5;
select * from (select * from t1 where t1_id > 2) t1 full outer join t2 on (t1_id = t2_id);
select * from t1 full outer join t2 on (t1_id = t2_id and t1_id > 2);
T1_ID T2_ID
3 3
4 4
5 5
6
7
T1_ID T2_ID
1
2
3 3
4 4
5 5
6
7
Maybe you are looking for
-
I want to migrate from older macbook to macbook with firewire. which connections do i use
I have a two year old macbook and I have a new macbook with a firewire connection. My older macbook doesnt have a firewire connection. Which connection do i buy to use the migration assistant.
-
my mac pro mid of 2010 restarts autumaticaly and i see through discustion that mac repair this problem for free when i went for local apple kuwait they want to charge me 800 us dollars what shall i do?
-
Examples for JMS Error Queue implementation in BPEL
Hi , Please anyone provide me examples for JMS error queue implementaion in BPEL. Regards Narsi p
-
I'm attempting to setup SSL connectivity to a test database (10.2.0.1 on AIX 5.3), but I keep getting an error on the client (10.2.0.3 on Windows XP): ORA-28860: Fatal SSL error. I've checked the sqlnet.ora files to make sure they match, and I've che
-
Error 1065 The database specified does not exist
Hi All, When I am trying the start the Concurrent Manager [[From Services.msc]] I am getting this error. Error 1065 The database specified does not exist I am also not able to connect through SQL* Plus. Thanks --Anil