Parent..child clas type casting???
Hi All,
I have a query, please have a look:
I have a parent class :: parent (getting compiled well , it's a simple class only)
I have a child class :: child
please see the code for child class below:
public class child extends parent
public static void main(String args[])
//child c = new mainClass(); //STATEMENT1. This gives comiplation error for incompatible types.
child c = (child) new mainClass(); //STATEMENT2. this statement works fine
}Is there any reason why typecasting does not occur in statement 1 where as it is working fine in statement 2?
I am intending to do the same thing in both statement 1 and 2.
Any specific reason why implicit type casting does not work?
Please comment.
TIA
Ayusman
If mainclass is not a subclass of child, then you can't assign it as in #1.
#2 will work at compile time if the compiler cannot be sure that a reference to a mainclas is cannot be a reference to a child.
If #1 fails and #2 compiles, than I can only assume that child extends mainClass. In both cases, all the compiler knows about the new is that is returns a reference to a mainClass.
#1 is allowed only if all mainClasses are childs--that is, if mainClass extends child.
#2 is allowed at compile time if and only if a reference to a mainClass could be a reference to child. In this case that would have to mean that child extends mainClass. The compiler doesn't know that you're pointing at an object that is only a mainClass. All it knows is that it's a mainClass or one of it's subclasses. However, since it is in fact only a mainClass and not a child, you will get a ClassCastException at runtime.
Similar Messages
-
Rollup calculations in Account hierarchy (parent-child type)
Hi,
I want to create a parent-child relationship type Account hierarchy using Universe. The hierarchy has to support different set of calculations for roll ups action for different branches in the same level.
Eg.
Balance Sheet
(+)Assets
(-)Liabilities and Owners Equity
Net Income
(+)Operating Profit
(+)Other Income and Expenses
(-)Taxes
Balance Sheet = Assets -Liabilities and Owners Equity
Net Income = Operating Profit + Other Income and Expenses - Taxes
Regards, SujeevMeasures automatically roll up.
Whether you define your measure with an aggregate or not, if the projection is set to Sum, it will roll up.
Measures that are to be summed should have Sum() wrapped round them at the universe level though.
What you may have is a lot of positive values in your database and no negatives.
If that's the case, you will need to use a case statement to determine the sign of the value.
E.g.
Sum(CASE WHEN Type='Asset' THEN table.value WHEN Type='Liability' THEN -1*table.value ELSE 0 END) -
Parent/Child Master Data Type
I recently created a new master data type in my model, which included one attribute with the 'parent' check box checked - to signify that it was to be used as the parent.
Upon activating the master data type - the system auto generated several other attributes within the master data type. My question is, what is the purpose of these additional attributes and how are they to be used?
Before Activation:
Attribute
Description
Notes
ID
ID
<< marked as key and as required
DESCR
Description
<< no special check boxes checked
PID
Parent ID
<< marked with parent check box
After activation:
Attribute
Description
Notes
ID
ID
<< marked as key and as required
DESCR
Description
<< no special check boxes checked
PID
Parent ID
<< marked with parent check box
IDA
Ancestor: ID
<< auto added after activation
IDL
Level: ID
<< auto added after activation
IDLA
Ancestor: Level: ID
<< auto added after activation
IDPTH
Path: ID
<< auto added after activation
IDPTHA
Ancestor: Path: ID
<< auto added after activation
DEACRA
Ancestor: Description
<< auto added after activation
PIDA
Ancestor: Parent ID
<< auto added after activationhttps://share.sap.com/a:r2l29c/MyAttachments/38b00c31-a7f4-404c-8247-1a99ef4b0509/
Hey JJ,
The purpose of these attributes is for parent-child hierachy relationship.
In addition to above mentioned attributes, you should also notice (via HANA studio), that another Planning object gets generated automatically. The new planning object should be the name of your parent-child object plus "_ANC" prefix at the end.
If you take a look at this planning object, you will notice that the object contains all the generated attributes (your attriubute plus "A" prefix at the end) in the definition.
Once you load data into your parent-child hiearchy object the "_ANC" object will automatically get populated with parent-child node relationship.
"A-prefix" attriubutes essentially represents the attributes of ancestor in this case.
In addition, in order to do Ancestor rolllup in your calculation you will also need to create an ancestor planning level which contains all the attriubutes of your base planning level as well as these "A-Prefix" attributes.
Please take a look at the document we created for "How to configure Parent-Child Hiearchy" from the share link
It has more detailed information.
Thanks.
Daniel. -
Parent Child Hierarchy for Type 2
I have read the articles on Parent Child hierarchy setup in OBIEE 11g, however, most are based on what seems to be a current snapshot of the Employee-Manager relationship. Has anyone tried to build out a Parent-Child hierarchy/table off a Type 2 dimension. Being able to navigate what the hierarchy may have been on a specific date.
I would welcome any feedback, thanks.Hi,
Thanks for the reply, I'm actually using snapshots. But even with the Type 2 Dim I don't think it will work.
When OBIEE generates the very first sql against the Parent-Child table the fact table is not included in the query. It seems to create 2 queries - one to find the top level parent (ancestor key is null) and then one to find all the leaf nodes.
It does not have any join to the fact table when it does this. So if you have multiple rows in the table (with date stamps) for a single row (person in this case) - it picks up both rows. Therefore, when you have a person who was, say, promoted to manager, and WAS a leaf node, and is now a manager, they show up in the leaf query and don't display in the hierarchy as a manager.
Once it has the leaf nodes and it joins to the fact table everything works (ie the surrogate key join).
I'm trying to figure out if there is any way to influence those initial queries against the parent-child table.
Hopefully that made sense.
Thanks,
Tori -
Custom IDoc Type missing segment parent/child relationships
Hi.
I copied the standard ORDERS05 IDoc type to a custom type and cut out quite a few segments. My new IDoc type is setup with parent/child segment relationships, similar to many of the original relationships in ORDERS05.
When I use the standard FM IDOC_OUTPUT_ORDRSP to generate an IDoc, it's not creating with parent/child segment relationships. It's placing the children at the same level as the parent.
Anyone know what I'm doing wrong?
Thanks!
Calfigured out the problem. was missing a required segment used to establish the parent/child relationship.
-
Create Individual Idocs Based on Parent and Child Segment type
Hi Experts,
I have a scenario IDOC to FILE , Split Single IDOC into Multiple IDOC's based on parent and child Segment Type
For example If 3 child segments are same and 1 segment is different under parent segment then 3 same child segments are clubbed and create single idoc under parent segments and 1 different child should create in individual idoc under parent segment.
Note : Same logic should work for N number of Parent Segments and Child Segments.
Outbound:
ZIdocName
Control Record
Data Record
Parent Segment A
Child Segment 1
Child Segment 1
Child Segment 1
Child Segment 2
Parent segment B
Child Segment 3
Status Record
I should get output like below
Inbound:
ZIdocName
Control Record
Data Record
Parent segment A
Child Segment 1
Child Segment 1
Child Segment 1
Status Record
ZIdocName
Control Record
Data Record
Parent segment A
Child Segment 2
Status Record
ZIdocName
Control Record
Data Record
Parent Segment B
Child Segment 3
Status Record
Please suggest me step by step process to achieve this task.
Thanks.
RamHello,
Segment won't hold any value, so filter criteria should be there on some field wich exist in Parent node and chile node?
Paste ur XML?
Try this(Assuming u have some fields in parent/child segment on which u want to define filter criteria):
Parent Field--UseOneAsMany----RC----
------------------Concat ----splitbyvalue(value change)--collapse context --- ZIdoc
Child field-- RC----------
Child field--RC--splitbyvalue(valuechange)--CC -Splitbyvalue(each value) -- ParentSegment
Child field--RC--splitbyvalue(valuechange)--- ChildSegment
RC -> Remove Context
CC - Collapse Context
Note - i haven't tested ur mapping, so make sure to adjust context in mapping
Thanks
Amit Srivastava
Message was edited by: Amit Srivastava -
Parent/Child BC4J Entity Object Sequence # Generation
If anyone can help us in this we greatly appreciate it. We are using DBSequence data type to poplulate the parent entity with the sequence #; however, we need to populate the child entity with the same sequence #.
We have a DB Trigger for every insert of the parent's key and it's working great but what do we need to do for populating the child record.
Is there a way to get the sequence # as a part of the this code for the child entity object.
protected void create(AttributeList attributeList)
super.create(attributeList);
SequenceImpl mySeq = new SequenceImpl("MY_SEQ",getDBTransaction());
setMyObjectId(mySeq.getSequenceNumber());
Thank you,
KamranWell,
I still can't insert the parent's primary key as a forign key automatically. Like in the Dept/Emp situation, I need to setup the supporting Impl files so it would insert the Dept No automatically as a part of the Employee creation.
New info : Here is a sample of what I am trying to accomplish. Sorry I could
have been more clear:
I am sending you my Workspace using Scott's table Dept and Emp. In my JSP file,
The user needs to input the Department information and some of the Employee
info, but the same deptno generated for the Dept record needs to be populated
for the Employee at the time of submit.
Please let me know if you need anything else.
Thank you,
Kamran
Creat_Emp.jsp
<%@ taglib uri="/webapp/DataTags.tld" prefix="jbo" %>
<%@ page contentType="text/html;charset=windows-1252"%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>
Hello World
</TITLE>
</HEAD>
<BODY>
<jbo:ApplicationModule id="Mypackage2Module"
configname="mypackage2.Mypackage2Module.Mypackage2ModuleLocal"
releasemode="Stateful" />
<jbo:DataSource id="Dept" appid="Mypackage2Module" viewobject="DeptView" />
<jbo:DataSource id="Emp" appid="Mypackage2Module" viewobject="EmpView" />
<jbo:Row id="myrow" datasource="Dept" action="Create" >
<jbo:SetAttribute dataitem="*" />
</jbo:Row>
<jbo:Row id="myrow5" datasource="Emp" action="Create" >
<jbo:SetAttribute dataitem="*" />
</jbo:Row>
<form NAME="sForm" action="Submit.jsp" >
<td><h3> DAAO <br> New Dept Entry Screen</h3></td>
<tr>
<TABLE bgColor="#c0c0c0" cellspacing="0" cellpadding="0" border="0" frame="box"
style="WIDTH: 530px; HEIGHT: 34px" >
<TR>
<TD><font color=darkyellow >Dept No:<br><jbo:InputText datasource="Dept"
dataitem="Deptno" ></jbo:InputText></TD>
<TD><font color=darkyellow >Dept Name:<br><jbo:InputText datasource="Dept"
dataitem="Dname" ></jbo:InputText></TD>
<TD><font color=darkyellow >Dept Location:<br><jbo:InputText datasource="Dept"
dataitem="Loc" ></jbo:InputText></TD>
</TABLE>
<TABLE bgColor="#c0c0c0" cellspacing="0" cellpadding="0" border="0" frame="box"
style="WIDTH: 530px; HEIGHT: 34px" >
<TR>
<TD><font color=darkyellow >Emp Dept No:<br><jbo:InputText datasource="Emp"
dataitem="Deptno" ></jbo:InputText></TD>
<TD><font color=darkyellow >Emp Id<jbo:InputText datasource="Emp"
dataitem="Empno" ></jbo:InputText>
<TD><font color=darkyellow >Emp Name:<br><jbo:InputText datasource="Emp"
dataitem="Ename" ></jbo:InputText></TD>
<TD><font color=darkyellow >Emp Job:<br><jbo:InputText datasource="Emp"
dataitem="Job" ></jbo:InputText></TD>
</TR>
</TABLE>
<TABLE bgColor="#c0c0c0" cellspacing="0" cellpadding="0" border="0" frame="box"
style="WIDTH: 530px; HEIGHT: 34px" >
<TR>
<TD><font color=darkyellow >Emp Mgr:<br><jbo:InputText datasource="Emp"
dataitem="Mgr" ></jbo:InputText></TD>
</TABLE>
<input name="RowKeyValue" type="hidden" value="<jbo:ShowValue
datasource="Emp" dataitem="RowKey"/>" />
<input type="submit" value="Save" /> <input type="reset" value="Clear
Screen"/> <input type="BUTTON" value="Q&A" onClick="Create_new_qa.jsp">
</form>
<form NAME="qForm" action="Create_New_Qa2.jsp" ></TD>
<input type="submit" value="Q&A" />
</form>
</body>
<jbo:ReleasePageResources releasemode="Stateless" />
</html>
Here is the submit.jsp
<%@ page language="java" contentType="text/html;charset=WINDOWS-1252" %>
<html xmlns:jbo="foo">
<body>
<center>
<br>
<%@ taglib uri="/webapp/DataTags.tld" prefix="jbo" %>
<br>
<jbo:ApplicationModule id="Mypackage2Module" configname="mypackage2.Mypackage2Module.Mypackage2ModuleLocal" releasemode="Stateful" />
<jbo:DataSource id="Dept" appid="Mypackage2Module" viewobject="DeptView" />
<jbo:DataSource id="Emp" appid="Mypackage2Module" viewobject="EmpView" />
<jbo:Row id="myrow" datasource="Dept" action="create" >
<jbo:SetAttribute dataitem="*" />
</jbo:Row>
<jbo:Row id="myrow5" datasource="Emp" action="Create" >
<jbo:SetAttribute dataitem="*" />
</jbo:Row>
<%
try
%>
<jbo:PostChanges appid="Mypackage2Module" />
<jbo:Commit appid="Mypackage2Module"/>
<p><font face="Arial, Helvetica, sans-serif"><b><font color="006699">DAAO Case Saved Successfully! </b></font></font> </p>
<%
catch(Exception exc)
%>
<title>this page will be displayed</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF">
<h1> Attenion the following error has occured:</h1><br>
<%
String error_msg = exc.getMessage();
if(exc instanceof oracle.jbo.JboException)
oracle.jbo.JboException jboex = (oracle.jbo.JboException)exc;
String sMsg = jboex.getDetailMessage();
out.println("<center>JBO Error:" + sMsg + "</center>");
// grab exception object. type cast to jbo object then get details
// parse details for specific error
Object[] details = jboex.getDetails();
if ( sMsg.startsWith("JBO-26041") )
if (
(details !=null)
&& (details.length >0 )
&& (details[0] instanceof java.sql.SQLException )
java.sql.SQLException sourceException = (java.sql.SQLException)(details[0]);
int sqlErrorCode = sourceException.getErrorCode();
if (sqlErrorCode == 1400)
out.println("<br><br><b><font color=\"006699\">One or more of the following required fields (Labeled in Red) have not been entered: </b></font></center><b>");
else
out.println("<br><br><b><font color=\"006699\"> Already exist on our system!! </b></font></center><b>");
if ( sMsg.startsWith("JBO-26041") )
else // unknown JBO exception
} //JBO exception instance
%>
<jbo:ReleasePageResources releasemode="Stateless"/>
<%
return;
%>
<br>
<br>
<form action="main.html" method= onclick><input type="submit" value="Back to Main"></form>
</center>
</body>
<jbo:ReleasePageResources releasemode="Stateless"/>
</html> -
Parent-child hierarchy and fragmentation content
Hello,
I've tried to build simple model with OBIEE 11 using Oracle 11r2 as a data source. BMM has fragmentation content for fact table and few dimensions with different hierarchy types. It works fine with all hierarchy types except for parent child.
When I build an answer with parent child hierarchy it terminates with error "Target data source does not support the operation".
Does OBIEE 11 not support parent child with fragmentation content? Or am I missing something?
Greetings
MarcinI'm seeing the same issue. I've created a parent-child hierarchy along with two normal level-based hierarchies (one "normal", one skipped-level). The two level-based hierarchies work just fine in Answers. I can include them in the criteria, and data is displayed with the correct drilldowns.
If I include the parent-child hierarchy, I get the same results as noted in the original post: "The layout of this view combined with the data, selections, or drills, or prompt values chosen, resulted in no data." I'm trying to look at the table view, with no filters.
Interestingly, I can explicitly include that dimension's Parent column and Member column in the criteria, and data is displayed just fine.
Here is the XML for the set of criteria that includes the separate Parent and Member columns (the one that works):
SELECT s_0, s_1, s_2, s_3, s_4, s_5, s_6, s_7, s_8, s_9, s_10, s_11 FROM (
SELECT
0 s_0,
"Retro_Biz"."Channels"."MEMBER" s_1,
"Retro_Biz"."Channels"."PARENT" s_2,
"Retro_Biz"."Products"."TOTAL_PRODUCT" s_3,
"Retro_Biz"."Times"."YEAR" s_4,
SPACE(1) s_5,
SPACE(1) s_6,
SPACE(1) s_7,
IDOF("Retro_Biz"."Products"."Product"."Total Product") s_8,
IDOF("Retro_Biz"."Times"."Time"."Year") s_9,
"Retro_Biz"."Facts"."SALES" s_10,
CAST(NULL AS DOUBLE) s_11
FROM "Retro_Biz"
UNION ALL
SELECT
1 s_0,
"Retro_Biz"."Channels"."MEMBER" s_1,
"Retro_Biz"."Channels"."PARENT" s_2,
SPACE(1) s_3,
SPACE(1) s_4,
SPACE(1) s_5,
SPACE(1) s_6,
SPACE(1) s_7,
SPACE(1) s_8,
SPACE(1) s_9,
CAST(NULL AS DOUBLE) s_10,
REPORT_SUM("Retro_Biz"."Facts"."SALES" BY ) s_11
FROM "Retro_Biz"
) djm ORDER BY 1, 5 ASC NULLS FIRST, 4 ASC NULLS FIRST
Here is the XML that includes the Parent-Child hierarchy (the one that fails):
SELECT s_0, s_1, s_2, s_3, s_4, s_5, s_6, s_7, s_8, s_9, s_10, s_11, s_12 FROM (
SELECT
0 s_0,
"Retro_Biz"."Channels"."MEMBER" s_1,
"Retro_Biz"."Products"."TOTAL_PRODUCT" s_2,
"Retro_Biz"."Times"."YEAR" s_3,
CASE WHEN ISLEAF("Retro_Biz"."Channels"."Channel") THEN 1 ELSE 0 END s_4,
IDOF("Retro_Biz"."Channels"."Channel") s_5,
SPACE(1) s_6,
SPACE(1) s_7,
SPACE(1) s_8,
IDOF("Retro_Biz"."Products"."Product"."Total Product") s_9,
IDOF("Retro_Biz"."Times"."Time"."Year") s_10,
PARENT("Retro_Biz"."Channels"."Channel") s_11,
"Retro_Biz"."Facts"."SALES" s_12
FROM "Retro_Biz"
WHERE
ISROOT("Retro_Biz"."Channels"."Channel")
UNION ALL
SELECT
1 s_0,
SPACE(1) s_1,
SPACE(1) s_2,
SPACE(1) s_3,
CAST(NULL AS INTEGER) s_4,
SPACE(1) s_5,
SPACE(1) s_6,
SPACE(1) s_7,
SPACE(1) s_8,
SPACE(1) s_9,
SPACE(1) s_10,
SPACE(1) s_11,
"Retro_Biz"."Facts"."SALES" s_12
FROM "Retro_Biz"
WHERE
ISROOT("Retro_Biz"."Channels"."Channel")
) djm ORDER BY 1, 4 ASC NULLS FIRST, 3 ASC NULLS FIRST -
Query Help with Parent, Child, Child's Child
Hi all,
Need some help with a query. I'm trying to create a stored procedure that is sort of like a Customer, Order, Order, Details. In my situation the tables are different but nevertheless, I want to grab all the fields from the Parent, Child,
and Childs' Child, where the Parent.ParentID = @Parameter. I tried this:
CREATE PROCEDURE [dbo].[spGetCompleteProjectXML]
@ProjectID int = 0
AS
SELECT *,
(SELECT *,
(SELECT *
FROM PageControls
WHERE (PageControls.ProjectPageID = ProjectPages.ProjectPageID))
FROM ProjectPages
WHERE (ProjectPages.ProjectID = @ProjectID))
FROM Projects
WHERE (ProjectID = @ProjectID)
FOR XML AUTO, ELEMENTS
RETURN 0
I think I'm close, but it was my best effort. Could someone help?
thanks in advanceHi TPolo,
Regarding your description, are you looking for a sample like below?
CREATE TABLE customer(customerID INT, name VARCHAR(99))
INSERT INTO customer VALUES(1,'Eric')
INSERT INTO customer VALUES(2,'Nelson')
CREATE TABLE orders(orderID INT,customerID INT)
INSERT INTO orders VALUES(1,1);
INSERT INTO orders VALUES(2,1)
INSERT INTO orders VALUES(3,2)
INSERT INTO orders VALUES(4,2)
CREATE TABLE orderDetails(orderID INT,item VARCHAR(99))
INSERT INTO orderDetails VALUES(1,'APPLE1')
INSERT INTO orderDetails VALUES(1,'BANANA1')
INSERT INTO orderDetails VALUES(2,'APPLE2')
INSERT INTO orderDetails VALUES(2,'BANANA2')
INSERT INTO orderDetails VALUES(3,'APPLE3')
INSERT INTO orderDetails VALUES(3,'BANANA3')
INSERT INTO orderDetails VALUES(4,'APPLE4')
INSERT INTO orderDetails VALUES(4,'BANANA5')
SELECT customer.customerID,customer.name,
(SELECT orderId,
SELECT item FROM orderDetails WHERE orderID=orders.orderID FOR XML AUTO,TYPE,ELEMENTS
FROM orders Where customerID=customer.customerID FOR XML AUTO,TYPE,ELEMENTS)
FROM customer WHERE customerID=1
FOR XML AUTO,ELEMENTS
DROP TABLE customer,orderDetails,orders
If you have any feedback on our support, please click
here.
Eric Zhang
TechNet Community Support -
Parent Child Hierarchy Issue in OBIEE 11g
Hi All,
I am in OBIEE 11G v6. I have a sales fact table where the grain is one sale. So I have one row for every sale done.
Now I have a ragged employee hierarchy like this with David at the root node.
David >>Richard>>Sean
David >>James
Also, I have a role dimension which gives me what role each employee has performed on a sale. Only one employee can be associated with one sale. This is the way Roles have been asssigned
David = Manager
Richard = Off1
Sean = Off2
James = Off2
Both Sean and James can have same Roles. Now I have created a parent child hierarchy for my employee dimension and the closure table. Defined the member key, ancestor key relationship in the parent child setting etc.
Now in the report when I pull the parent child hierarchy and the sales_amount in the report, it comes out perfect with all the ragged hierarchy resolved. But the issue comes when I try to limit the report on Role = Off2. It gives me an error saying " The layout of this view combined with the data, selection , drills resulted in no data. Undo drill and view prompt values". Basically what i want is to be able to select any role type and then my hierarchy should be adjusted to show me that data. Like when I select Off2, I want to see David at the Top level and Sean and James under him because they are both Off 2 and David is their manager.
Is that possbile? Also, am I getting this error because when I select Off2 though it gets Sean and James but since David is not Off2, I don't get the data?
I hope I was able to explain the issue, any help on this would be greatly appreciated.
Thanks
RonnySo basically this means that if I build a parent child hierarchy on table A having the stucture like
--David (Manager)
-----James (Off1)
--------Bill (Off2)
and in my sales fact table for let's say today, I have only rows for Bill (Off2) because he is the only officer who did the sales today. Now when I will join my fact table to parent child hierarchy table A I will NOT get any data ? because there is no James who is the parent of Bill. So obiee need to have parent pulled off in the data (ANCESTOR) to be able to roll up the child.(IS_LEAF = 1)
I testes this and if my data only contains only rows for Bill (or I limit on ROLE = Off2) then it won't show the hierarchy. The query which OBIEE fires is to look for either ANCESTOR_KEY = NULL OR (DISTANCE = 1 AND ANCESTOR KEY IN (Bill). Therefore it doesn't I am wondering then what is the use of builiding the parent child hierarchy when we need to pull in all the ancestors (like in this case James for bill and David for james) because in real scenarios there can be cases wherein we would want to filter the data based on other dimensions to which the parent child hierarchy joins ? -
Help needed in retrieving parent child relationship values
Hi,
I have a requirement to get parent child relationship values as below.
Ex: Address table
cont cont_code state state_code
C1 10 S1 1
C1 10 S2 2
C1 10 S3 3
C2 20 S4 4
C2 20 S5 5
C3 30 S6 6
C3 30 S7 7
C3 30 S8 8
I want a result of country/state and corresponding code like below.
corresponding states should be displayed under each country with some space appended to it.
Geography code
C1 10
S1 1
S2 2
S3 3
C2 20
S4 4
S5 5
C3 30
S6 6
S7 7
S8 8
I am using oracle 10g version.
Thanks in advance.Hi,
When you post formatted text (like your output) on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
I think you're saying that you want this output:GEOGRAPHY CODE
C1 10
S1 1
S2 2
S3 3
C2 20
S4 4
S5 5
C3 30
S6 6
S7 7
S8 8
If so, UNION, as Hoek suggested, is a good way.
GROUP BY ROLLUP is more efficient, but harder to understand:SELECT CASE
WHEN GROUPING (state) = 1
THEN cont
ELSE ' ' || state
END AS geography
, CASE
WHEN GROUPING (state) = 1
THEN MAX (cont_code)
ELSE MAX (state_code)
END AS code
FROM t
GROUP BY cont
, ROLLUP (state)
ORDER BY cont
, state NULLS FIRST
By the way, this looks like a bad table design.
In a relational database, the fact that the name 'C1' belongs to cont_code 10 should only be stored in one place. You have the same information on 3 separate rows.
Also, if 'C1' and 'S1' are both names, they should probably be in the same column, so that (to give just one example) you can find the information about 'x1' without knowing if it is a cont or a state.
A better design would be.NAME CODE PARENT DSCR
==== ==== ====== ====
C1 10 CONT
S1 1 10 STATE
S2 2 10 STATE
S3 3 10 STATE
C2 20 CONT
S4 4 20 STATE
S5 5 20 STATE
C3 30 CONT
S6 6 30 STATE
S7 7 30 STATE
S8 8 30 STATE
If the data is this simple, then the dscr column isn't needed. Whether parent is NULL or not tells whether the rows represents a cont or a state.
To get the results you want from a table like this, you could use CONNECT BY. Using either UNION or ROLLUP, you have to know, at the time you write the query, how many levels there will be in the parent-child tree, and the length of the code is proportional to that depth, and the table has to be changed if you ever need to add another level. CONNECT BY can handle any number of levels, and the length and complexity of the code is the same whether you have just 2 levels (countries and strates), or 7 levels (continents, regions, countiries, states, districts, cities and neighborhoods) or 72 levels. The table doesn't need any more columns, no matter how deep the tree gets.
Edited by: Frank Kulash on Sep 16, 2010 11:54 AM -
Creating View for a table with parent child relation in table
I need help creating a view. It is on a base table which is a metadata table.It is usinf parent child relationship. There are four types of objects, Job, Workflow, Dataflow and ABAP dataflow. Job would be the root parent everytime. I have saved all the jobs
of the project in another table TABLE_JOB with column name JOB_NAME. Query should iteratively start from the job and search all the child nodes and then display all child with the job name. Attached are the images of base table data and expected view data
and also the excel sheet with data.Picture 1 is the sample data in base table. Picture 2 is data in the view.
Base Table
PARENT_OBJ
PAREBT_OBJ_TYPE
DESCEN_OBJ
DESCEN_OBJ_TYPE
JOB_A
JOB
WF_1
WORKFLOW
JOB_A
JOB
DF_1
DATAFLOW
WF_1
WORKFLOW
DF_2
DATAFLOW
DF_1
DATAFLOW
ADF_1
ADF
JOB_B
JOB
WF_2
WORKFLOW
JOB_B
JOB
WF_3
WORKFLOW
WF_2
WORKFLOW
DF_3
DATAFLOW
WF_3
WORKFLOW
DF_4
DATAFLOW
DF_4
DATAFLOW
ADF_2
ADF
View
Job_Name
Flow_Name
Flow_Type
Job_A
WF_1
WORKFLOW
Job_A
DF_1
DATAFLOW
Job_A
DF_2
DATAFLOW
Job_A
ADF_1
ADF
Job_B
WF_2
WORKFLOW
Job_B
WF_3
WORKFLOW
Job_B
DF_3
DATAFLOW
Job_B
DF_4
DATAFLOW
Job_B
ADF_2
ADF
I implemented the same in oracle using CONNECT_BY_ROOT and START WITH.
Regards,
MeghaI think what you need is recursive CTE
Consider your table below
create table basetable
(PARENT_OBJ varchar(10),
PAREBT_OBJ_TYPE varchar(10),
DESCEN_OBJ varchar(10),DESCEN_OBJ_TYPE varchar(10))
INSERT basetable(PARENT_OBJ,PAREBT_OBJ_TYPE,DESCEN_OBJ,DESCEN_OBJ_TYPE)
VALUES('JOB_A','JOB','WF_1','WORKFLOW'),
('JOB_A','JOB','DF_1','DATAFLOW'),
('WF_1','WORKFLOW','DF_2','DATAFLOW'),
('DF_1','DATAFLOW','ADF_1','ADF'),
('JOB_B','JOB','WF_2','WORKFLOW'),
('JOB_B','JOB','WF_3','WORKFLOW'),
('WF_2','WORKFLOW','DF_3','DATAFLOW'),
('WF_3','WORKFLOW','DF_4','DATAFLOW'),
('DF_4','DATAFLOW','ADF_2','ADF')
ie first create a UDF like below to get hierarchy recursively
CREATE FUNCTION GetHierarchy
@Object varchar(10)
RETURNS @RESULTS table
PARENT_OBJ varchar(10),
DESCEN_OBJ varchar(10),
DESCEN_OBJ_TYPE varchar(10)
AS
BEGIN
;With CTE
AS
SELECT PARENT_OBJ,DESCEN_OBJ,DESCEN_OBJ_TYPE
FROM basetable
WHERE PARENT_OBJ = @Object
UNION ALL
SELECT b.PARENT_OBJ,b.DESCEN_OBJ,b.DESCEN_OBJ_TYPE
FROM CTE c
JOIN basetable b
ON b.PARENT_OBJ = c.DESCEN_OBJ
INSERT @RESULTS
SELECT @Object,DESCEN_OBJ,DESCEN_OBJ_TYPE
FROM CTE
OPTION (MAXRECURSION 0)
RETURN
END
Then you can invoke it as below
SELECT * FROM dbo.GetHierarchy('JOB_A')
Now you need to use this for every parent obj (start obj) in view
for that create view as below
CREATE VIEW vw_Table
AS
SELECT f.*
FROM (SELECT DISTINCT PARENT_OBJ FROM basetable r
WHERE NOT EXISTS (SELECT 1
FROM basetable WHERE DESCEN_OBJ = r.PARENT_OBJ)
)b
CROSS APPLY dbo.GetHierarchy(b.PARENT_OBJ) f
GO
This will make sure it will give full hieraracy for each start object
Now just call view as below and see the output
SELECT * FROM vw_table
Output
PARENT_OBJ DESCEN_OBJ DESCEN_OBJ_TYPE
JOB_A WF_1 WORKFLOW
JOB_A DF_1 DATAFLOW
JOB_A ADF_1 ADF
JOB_A DF_2 DATAFLOW
JOB_B WF_2 WORKFLOW
JOB_B WF_3 WORKFLOW
JOB_B DF_4 DATAFLOW
JOB_B ADF_2 ADF
JOB_B DF_3 DATAFLOW
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Hi experts,
Please check it my code . in this procedure first cursor only inserted into t1 temp table not inserted second cursor please check it and modified the my code.
i want inserted parent child relation table like bellow
parent child
a b
a c
a d
b l
b m
b n
c d like that only inserted
PROCEDURE TEST_PARENTS_CHILD( p_TABLE VARCHAR2)
IS
CURSOR c(P_TABLE varchar2)
IS
SELECT p.table_name PARENT, c.table_name CHILD
FROM user_constraints p, user_constraints c
WHERE (p.constraint_type = 'P' OR p.constraint_type = 'U')
AND c.constraint_type = 'R'
AND p.constraint_name = c.r_constraint_name
AND p.table_name = P_TABLE;
CURSOR C1(p_child varchar2) IS SELECT p.table_name PARENT_TABLE, c.table_name CHILD_TABLE
FROM user_constraints p, user_constraints c
WHERE (p.constraint_type = 'P' OR p.constraint_type = 'U')
AND c.constraint_type = 'R'
AND p.constraint_name = c.r_constraint_name
AND p.table_name = P_CHILD;
type array
IS
TABLE OF T1%ROWTYPE INDEX BY PLS_INTEGER;
t_data ARRAY;
BEGIN
FOR I IN C(P_TABLE)
LOOP
FETCH C bulk collect INTO T_DATA limit 1000;
--- EXIT WHEN C%NOTFOUND;
FORALL I IN 1..T_DATA.last
INSERT INTO T1 VALUES T_DATA(I);
FOR J IN C1(i.CHILD)
LOOP
FETCH C1 BULK COLLECT INTO T_DATA LIMIT 1000;
--EXIT
--WHEN C1%NOTFOUND;
FORALL j IN 1..T_DATA.last
INSERT INTO T1 VALUES T_DATA(j);
end loop;
END LOOP;
END TEST_PARENTS_CHILD;
Regards,
VenkatYou've been asked before on your previous questions (all of which still appear to be unanswered) to read the FAQ: {message:id=9360002} and post correct details of your question, and use {noformat}{noformat} tags to preserve your code/data formatting on the forum.
But still you post a question lacking all the information and formatting. If you can't be bothered to help us understand your issue (and read your code), why do you expect others will be bothered to try and help you? -
Parent child relation in OBIEE -RPD Issue
Hi,
I created a star schema by taking two tables . Now i want to establish parent-child relation ship .
Now by clicking create logical dimension ----->Dimension with parent-child hierarchy ,the member key is not found.Pls correct me where i went wrong .
Thanks-BhaskarI know you said you have primary key defined already but just to make sure, can you follow these steps:
1) Double click on dimension table
2) go to tab 'Keys'. check if your primary key is defined there.
3) If not, in 'Key Name', type in the key name
4) select the primary key(column) in 'Columns'.
5) Click OK.
and then try to create hierarchy by following these steps:
1) Right Click on the dimension table
2) Create Logical Dimension -> Dimension with Parent-Child Hierarchy...
3) Click OK (if you are OK with default values) -
Parent - child tables foreign key relation ship
Hi All,
we have 600 hundred tables ..i would like to print a hierarchial tree based on the foreigh key relathionship
i tried my best but i couldnt.
parent table
child table 1
childtable3
child table 2
and so
Can somebody help me out with a query?
Thanks,
ktCREATE OR REPLACE FUNCTION get_child_tables (
ptable VARCHAR2,
powner VARCHAR2 DEFAULT 'SCOTT',
plevel NUMBER DEFAULT 10
RETURN stringarray
-- -- create this ON SQL*PLUS "CREATE OR REPLACE TYPE STRINGARRAY AS TABLE OF VARCHAR2(50);"
-- AUTHID CURRENT_USER
PIPELINED
AUTHOR DATE VERSION COMMENTS
======================================================================================
[email protected] 26-OCT-2009 1.0 Developed to ease developers effort to find Nth level of Referential integrity
======================================================================================
-- PURPOSE -> To find PARENT=> CHILD relational TABLE(S) in Oracle upto a depth max N Level.
--SYNTAX TO USE
SELECT * FROM TABLE( get_child_tables('DEPT','SCOTT',3)); Store this query in a file for your use
SELECT * FROM TABLE( get_child_tables('EMPLOYEE')); Store this query in a file for your use
-- RESULTS looks as below
--1 => DEPT
--2 => EMP
--2 => EMP2
--3 => EMP_CHILD
--3 => EMP2_CHILD
-- and so on
--This can be leveraged to use in any oracle database REGION 10g having and above.
--This FUNCTION gives formatted result of the Oracle 10g Hierarchical query result coded in the cursor
--to find MASTER => CHILD relational TABLE(S) upto a depth max 10 Level.
--The result of the PIPELINED function can be retrieved using Oracle new operator
--TABLE(array name) in SQL query.
--Due to the AUTHID CURRENT_USER compiler directive any user can use based on his/her access privileges on the database.
--GRANT EXECUTE ON SCOTT.get_child_tables TO PUBLIC;
--CREATE OR REPLACE PUBLIC SYNONYM get_child_tables FOR SCOTT.get_child_tables;
IS
atname stringarray := stringarray ();
-- create this ON SQL*PLUS CREATE OR REPLACE TYPE STRINGARRAY AS TABLE OF VARCHAR2(50);
vlevel NUMBER;
vtname VARCHAR2 (50);
nindex NUMBER := 0;
bprocessed BOOLEAN := FALSE;
CURSOR c1 (powner_in IN VARCHAR2, ptable_in VARCHAR2, plevel_in NUMBER)
IS
SELECT LEVEL, LPAD (' ', (LEVEL - 1) * 2, ' ') || pt AS "TNAME"
FROM (SELECT a.owner w1, a.table_name pt, a.constraint_name c1,
a.r_constraint_name r1, b.owner w2, b.table_name ct,
b.constraint_name c2, b.r_constraint_name r2
FROM all_constraints a, all_constraints b
WHERE a.constraint_name = b.r_constraint_name(+)
AND a.owner = b.owner(+)
AND a.owner =
UPPER (powner)
-- Change Owner here while testing
--AND A.r_constraint_name IS NULL
AND a.constraint_type IN ('P', 'R')) v1
START WITH pt =
UPPER
(ptable)
-- Change your master table here while testing the QUERY
CONNECT BY PRIOR ct = pt AND LEVEL <= plevel;
-- Change lavel here while testing
BEGIN
atname.EXTEND;
atname (1) := 'NOTHING';
OPEN c1 (powner, ptable, plevel);
LOOP
bprocessed := FALSE;
FETCH c1
INTO vlevel, vtname;
IF nindex > 1 AND atname (atname.LAST - 1) = vtname
THEN
--DBMS_OUTPUT.PUT_LINE('2 ==== vtname ' ||vtname || ' '|| atname.count|| ' '||atname.last || ' '||atname( atname.last-1));
bprocessed := TRUE;
END IF;
IF NOT bprocessed
THEN
nindex := nindex + 1;
atname.EXTEND;
atname (nindex) := vtname;
PIPE ROW (vlevel || ' => ' || vtname);
DBMS_OUTPUT.put_line ( ' **** nindex - atname( nindex) '
|| nindex
|| ' - '
|| atname (nindex)
DLOG('ADDING ',vTname); A LOGGING ATONOMUS PROCEDURE FOR DEBUG PURPOSE
END IF;
EXIT WHEN c1%NOTFOUND;
END LOOP;
CLOSE c1;
FOR i IN 1 .. atname.COUNT
LOOP
DBMS_OUTPUT.PUT_LINE('atname (i) ' ||atname (i));
END LOOP;
RETURN;
EXCEPTION
WHEN no_data_needed
THEN -- THIS EXCEPTION HAS TO BE THERE TO GET THE FUCTION WORKABLE
DBMS_OUTPUT.put_line (SQLERRM);
RETURN;
END get_child_tables;
/
Maybe you are looking for
-
"This is an Adobe Illustrator file that was save without PDf content."
I have a client that has been working on a file in AI CS, never left his machine, but when he went to open it today he gets a message that says this file "was generated by a newer version of Illustrator. Would you like to import this file? Some data
-
Calling my custom component several times 'freezes' my browser
I have a component (Interf) that has a sub-component (Inter57) that has a sub-components (Interf57User) In my app, i declare a variable interf of type Interf [the base component]: [Bindable] public var AasInt interf:Interf = new Interf; then in a fun
-
How to drag an object in case like this?
Hi, with the little I know about Action script after reading and following a book I decided to exercise on my own by trying to drag on object that changes its 2 children when the mouse clicks. I'm sure there are much better ways to do that but never
-
I had an PC crash while backing-up my iPhone4, before installing iOs7. Now I am unable to restore the iPhone. Can anyone please help me! Arjen Ronhaar
-
I Know ABAP and i dont have idea on abap hr. Pls Anyone Provide me the detailed tutorial to learn abap hr by my own Thanks and regards vamsin [email protected]