Start with Connect by: Showing the whole hierarchy even if child parameter
11g
Hi There,
In our case the manager_id i= employee_id for the top level manager. So when I run the sql, it eliminates the top level manager and shows the output for the next level onwards.
For the regular start with connect by option on the employee table the query used is
select case when connect_by_isleaf = 1 then 0 when level = 1 then 1 else -1 end as status,
level,
First_name as title,
NULL as icon,
EMPloyee_id as value,
First_name as tooltip,
NULL as link
from EMPLOYEES
start with Manager_id is null
connect by prior EMPLOYEE_ID = Manager_id
order siblings by First_namenow this will show the hierarchy and level starting with managers. Now if we provide the "start with Manager_id = 171" then since 171 is not a manager no rows are returned. So for this we can use something like
start with manager_id =171 or employee_id = 171However, the output would be only the employee record since 171 is the last child.
The requirement we had was that, Irrespective of the value entered, whether ultimate parent or ultimate child the output should still show the top down hierarchy. starting with that persons ultimate manager.
So for example if there are two employees, 170 and 171 and 170 is the manager of 171
If in this query I use Start with manager = 170. It will show me the manager and the child records.
However, if I use start with manager = 171 or employee_id = 171 then it will only show me only the child record. I want it to show me both the manager and employee records. i.e all the levels
I hope that make sense!
Thanks,
Ryan
Edited by: ryansun on Dec 12, 2012 1:13 AM
Edited by: ryansun on Dec 13, 2012 1:59 AM
Hi Alberto,
I was using this query and the output is correct. Except for one thing, the nature of our data is such that the top most manager in this case has "Manager_Id" as null so we can use "start with Manager is null"
But in our case the manager id for the top most manager is the same as his employee id.
So If I modify the query, it then does not show the "top most managers record"
WITH entire_tree AS
SELECT *
FROM employees
START WITH manager_id = 171
CONNECT BY PRIOR employee_id = manager_id
UNION
SELECT *
FROM employees
START WITH employee_id = 171
CONNECT BY employee_id = PRIOR manager_id
SELECT CASE WHEN CONNECT_BY_ISLEAF = 1 THEN 0 WHEN LEVEL = 1 THEN 1 ELSE -1 END AS status
, LEVEL
, first_name AS title
, NULL AS icon
, employee_id AS VALUE
, first_name AS tooltip
, NULL AS link
FROM entire_tree
START WITH manager_id = 100
CONNECT BY PRIOR employee_id = manager_id
ORDER SIBLINGS BY first_name;the only change I made is from
Start with manager_id is null
to
start with manager_id = 100Basically, in this case the manager_id of the top most manager is the same as his employee id. So how can we have that condition incorporated instead of checking for null.
Thanks,
Ryan
Similar Messages
-
Transaction starting with Y_DEV are showing in German language even though
Hi,
When we are login into SAP with French language, then all the transaction starting with Y_DEV are showing in German language i.e the initial screen and when we execute(F8) any transaction starts with Y_DEV, the output is coming in French language.
Why in the initial screen, it is reflecting in German language even though the login is made with French language.
With regards.Hi,
Y_DEV* are user-developed reports. Could be that the selection parameters are not translated to French or maybe they just have to be re-generated (it happens sometimes in SAP). Use GR52 to regenerate the group of these reports.
Regards,
Eli -
Start with Connect By: What if Parent is the Child?
Version : 11g
Hi There,
I had a question regarding Start with Connect by.
The following is an example from the ORacle help from the Emploees table
select case when connect_by_isleaf = 1 then 0 when level = 1 then 1 else -1 end as status,
level,
First_name as title,
NULL as icon,
EMPloyee_id as value,
First_name as tooltip,
NULL as link
from EMPLOYEES
start with Manager_id ='171'
connect by prior EMPLOYEE_ID = Manager_id
order siblings by First_nameNow this works fine and shows the levels. In the help the start with is actually
start with Manager_id is nullNow if we use a lowest level employee using something like
start with Manager_id = '171'no rows are returned. This is because there are no child records for this employee (he is not a manager).
However, is it possible to atleast show this one record as the output? Any suggestions?
Thanks,
Ryan
Edited by: ryansun on Dec 10, 2012 10:51 PMOne way
start with
( manager_id ='171'
or
employee_id='171'
and '171' not in (
select distinct manager_id
from employees
where manager_id is not null
)Edited by: jeneesh on Dec 11, 2012 12:35 PM -
DB is 11gR1
I have a table that defines formulas for items that are created (line_type = 1) and what ingredients are needed to make it (line_type = -1). Some ingredients also need to be made, so they will have another record in the table (different formula) with a line_type of 1, and the ingredients that make it up. Those ingredients could also be created, and so on.
So in the example below formula 807 creates item 4112949142. The line_type = -1 for formula 807 define the ingredients that make up that item. One of the ingredients, KT00518, is also a manufactured item, defined by that item with line_type = 1 which is formula 1420. Ingredient WP50255 is manufactured with formula 3030.
What I need to be able to do, is starting with formula 807, recursively loop through all the formulas to get all of the ingredients needed to make that item:
KT00518
PK15199
PK13947
RM31009
RM30711
RM31004
WP50255
RM30951
RM30948
RM30981
RM30957
In this simple case it would be easy because there are no formulas that are not related to this item, but obviously I need a way to do this with a start with/connect by in the real world:
SELECT *
FROM XX_FORMULA
WHERE line_type = -1
DROP TABLE XX_FORMULA;
CREATE TABLE XX_FORMULA
FORMULA_ID NUMBER NOT NULL,
ITEM VARCHAR2(60) NOT NULL,
LINE_TYPE NUMBER NOT NULL,
LINE_NO NUMBER NOT NULL
--Top Level
INSERT INTO XX_FORMULA
VALUES( 807,'4112949142',1, 1);
INSERT INTO XX_FORMULA
VALUES( 807,'KT00518',-1, 1);
INSERT INTO XX_FORMULA
VALUES( 807,'PK15199',-1, 2);
INSERT INTO XX_FORMULA
VALUES( 807,'PK13947',-1, 3);
--Middle
INSERT INTO XX_FORMULA
VALUES( 1420,'KT00518',1, 1);
INSERT INTO XX_FORMULA
VALUES( 1420,'RM31009',-1, 1);
INSERT INTO XX_FORMULA
VALUES( 1420,'RM30711',-1, 2);
INSERT INTO XX_FORMULA
VALUES( 1420,'RM31004',-1, 3);
INSERT INTO XX_FORMULA
VALUES( 1420,'WP50255',-1, 4);
--Leaf
INSERT INTO XX_FORMULA
VALUES( 3030,'WP50255',1, 1);
INSERT INTO XX_FORMULA
VALUES( 3030,'RM30951',-1, 1);
INSERT INTO XX_FORMULA
VALUES( 3030,'RM30948',-1, 2);
INSERT INTO XX_FORMULA
VALUES( 3030,'RM30981',-1, 3);
INSERT INTO XX_FORMULA
VALUES( 3030,'RM30957',-1, 4);Thanks in advance for your help.
--JohnnieHi,
Vortex13 wrote:
DB is 11gR1
I have a table that defines formulas for items that are created (line_type = 1) and what ingredients are needed to make it (line_type = -1). Some ingredients also need to be made, so they will have another record in the table (different formula) with a line_type of 1, and the ingredients that make it up. Those ingredients could also be created, and so on.
So in the example below formula 807 creates item 4112949142. The line_type = -1 for formula 807 define the ingredients that make up that item. One of the ingredients, KT00518, is also a manufactured item, defined by that item with line_type = 1 which is formula 1420. Ingredient WP50255 is manufactured with formula 3030.Okay, so that explains that
VALUES( 807,'KT00518',-1, 1);is the parent of
VALUES( 1420,'KT00518',1, 1);But it looks like there's also another kind of parent-child relationship in this table. That is, the last row I showed above apparantly has children. I'm guessing that
VALUES( 1420,'RM31009',-1, 1);is one of its children. That is, a row with line_type=1 can have children: any row with the same formula_id and line_type=-1 is its child. Is that right?
If so:
SELECT *
FROM xx_formula
WHERE line_type = -1
START WITH formula_id IN (807) -- Change as needed
AND line_no = 1
CONNECT BY ( item = PRIOR item
AND line_type = 1
AND PRIOR line_type = -1
OR ( formula_id = PRIOR formula_id
AND line_no = PRIOR line_no + 1
What I need to be able to do, is starting with formula 807, recursively loop through all the formulas to get all of the ingredients needed to make that item:
KT00518
PK15199
PK13947
RM31009
RM30711
RM31004
WP50255
RM30951
RM30948
RM30981
RM30957I get 20 rows of output, not just the 11 you want. I guess I don't understand the requirements.
Here are my results:
FORMULA_ID ITEM LINE_TYPE LINE_NO
807 KT00518 -1 1
1420 RM31009 -1 1
1420 RM30711 -1 2
1420 RM31004 -1 3
1420 WP50255 -1 4
3030 RM30951 -1 1
3030 RM30948 -1 2
3030 RM30981 -1 3
3030 RM30957 -1 4
807 PK15199 -1 2
807 PK13947 -1 3
807 KT00518 -1 1
1420 RM31009 -1 1
1420 RM30711 -1 2
1420 RM31004 -1 3
1420 WP50255 -1 4
3030 RM30951 -1 1
3030 RM30948 -1 2
3030 RM30981 -1 3
3030 RM30957 -1 4Take a couple of examples where I'm getting the wrong results, and explain again, using different words, how you get the right results in those places.
Maybe I just need to say SELECT DISTINCT .
In this simple case it would be easy because there are no formulas that are not related to this item, Yes, it would be better to add a couple of rows that are not related. Why don't you?
but obviously I need a way to do this with a start with/connect by in the real world:Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful. -
I have a Blackberry 8330 and a MacBook. For some reason I started having connectivity issues. The handheld will not sync with the computer via pocketmac. I have uninstalled, etc 15 times. Please help
Hi Peter!
I'm sorry to read that you are having issues with your Sync account.
Your best bet is to follow the steps described in this blogposts and open a bug:
https://philikon.wordpress.com/2011/06/13/how-to-file-a-good-sync-bug/
After that, if you don't want to user Sync in your computer, you can stop it with this simple steps:
* At the top of the Firefox window, click on the Firefox button (Tools menu in Windows XP) and then click Options.
* Once the options window opens, click on the Sync tab.
* At the bottom of the Sync tab click on '''Deactivate this Device''' link -
Hi my Ipad shows that ITunes icon along with connection wire on the screen...I cannot access anything else, what should I do?
About recovery mode : http://support.apple.com/kb/HT1808
Have you made any backups of your data via iCloud btw? If not, you will loose your data :/ -
Hi.
I have data in a table which looks like:
Top level Step 3rd Level 4th Level Script Name
NORMAL_DAY Step 1 of NORMAL_DAY DATE_FEEDER Step 1 of DATE_FEEDER INT_EOD_DATE_FEEDER
NORMAL_DAY Step 2 of NORMAL_DAY EOD_FX_RATE_UPLOAD Step 3 of EOD_FX_RATE_UPLOAD SEND_MAIL_FXSPOTS
NORMAL_DAY Step 2 of NORMAL_DAY EOD_FX_RATE_UPLOAD Step 2 of EOD_FX_RATE_UPLOAD FXSPOTS
NORMAL_DAY Step 2 of NORMAL_DAY EOD_FX_RATE_UPLOAD Step 1 of EOD_FX_RATE_UPLOAD FX_FTPS_GET_EOD
NORMAL_DAY Step 3 of NORMAL_DAY CALENDAR_UPLOAD Step 1 of CALENDAR_UPLOAD CALENDAR
NORMAL_DAY Step 3 of NORMAL_DAY CALENDAR_UPLOAD Step 2 of CALENDAR_UPLOAD MDS_STOP
NORMAL_DAY Step 3 of NORMAL_DAY CALENDAR_UPLOAD Step 3 of CALENDAR_UPLOAD MDS_HOLIDAY
NORMAL_DAY Step 3 of NORMAL_DAY CALENDAR_UPLOAD Step 4 of CALENDAR_UPLOAD MDS_START
NORMAL_DAY Step 4 of NORMAL_DAY FA_VALUATIONS Step 1 of FA_VALUATIONS IMPORTMTM
NORMAL_DAY Step 4 of NORMAL_DAY FA_VALUATIONS Step 2 of FA_VALUATIONS INT_EOD_VALUATIONS
As you can see, it lends itself to a tree type structure. I am trying to display this information using the start with/connect by clauses.....
My initial query looks like:
select main.name "Top Level",
level2.name "Step",
level3.name "3rd Level",
level4.name "4th Level",
level5.name "Script Name",
level5.run_start,
level5.run_end,
(level5.run_end - level5.run_start) "Time difference",
to_char((level5.run_end - level5.run_start),'99999999999999999999999999990.0000000000')*1000 as Total_Run_Time
from jcs_jobs main,
jcs_jobs level2,
jcs_jobs level3,
jcs_jobs level4,
jcs_jobs level5
where main.name = 'NORMAL_DAY'
and main.PARENT_JOB_ID IS NULL
and main.job_id = 2253800
and main.job_id = level2.parent_job_id
and level2.job_id = level3.parent_job_id
and level3.job_id = level4.parent_job_id
and level4.job_id = level5.parent_job_id
order by level2.step_name;
This is a bit restrictive, so I need to make it more generic, because we can actually have more than 5 levels of depth.....
I haven't included the time element in the sample data. This also appears to be another conundrum.....how to display milliseconds in a reasonable date format?
Thank you very much in advance!
Devtry this way:
SQL> select script_name, job,
2 to_char(to_date(run_start,'Jhh24miss'),'dd-mon-yyyy hh24:mi:ss') run_start,
3 to_char(to_date(run_end,'Jhh24miss'),'dd-mon-yyyy hh24:mi:ss') run_end,
4 (to_date(run_end,'Jhh24miss')
5 - to_date(
6 substr(root_start,
7 2,
8 decode(instr(root_start,'/',1,2),
9 0,
10 length(root_start)+1,
11 instr(root_start,'/',1,2)
12 )-2
13 )
14 ,'Jhh24miss')
15 ) "Time difference"
16 from (
17 select name script_name, lpad(' ',2*level,' ')||job_id job
18 ,to_char(run_start,'Jhh24miss') run_start, to_char(run_end,'Jhh24miss') run_end,
19 sys_connect_by_path(to_char(run_start,'Jhh24miss'),'/') root_start
20 from jcs_jobs
21 where name = 'NORMAL_DAY'
22 connect by prior job_id = parent_job_id
23 start with PARENT_JOB_ID IS NULL and job_id = 2253800
24 );
SCRIPT_NAM JOB RUN_START RUN_END Time difference
NORMAL_DAY 2253800 23-jan-2010 15:30:16 27-jan-2010 01:06:16 3,4
NORMAL_DAY 2253801 27-jan-2010 01:06:16 28-jan-2010 15:30:16 5Max
[My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/01/23/la-forza-del-foglio-di-calcolo-in-una-query-la-clausola-model/] -
Could otool default to showing the whole object file in assembly?
When I try to use otool, it just complains "one of -fahlLtdoOrTMRIHGScis must be specified". I eventually found through Google that otool -tv shows the text section in assembly, but I want to see every section in assembly.
Could otool just default to showing the whole object file in assembly when no command line options are specified?
Specs:
* otool (couldn't find version number through command line options)
* Xcode 4.5
* Mac OS X 10.8.2
* MacBook Pro 2009Would be nice iif someone from the AE departement could take a look at this. I tested it now with a full LabVIEW 2014 for Mac installation and there is the same problem. The liblvexports.a file in cintools/Mach-O is for both installations (32 bit and 64 bit) a 64 bit object library. Definitely a bug!
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions -
Qosmio F30 starts with blue stripes during the start screen of Vista
My Qosmio F30-114 runs since years without Problems with Vista Ultimate.
Since some Days there is a huge Problem.
The Qosmio starts with blue stripes during the start screen of vista.
So I deleted the driver of the graphic card and used the standard vga card driver. the hardware assistent found a driver on the system.
For a short moment i was very lucky.
After a restart, there was a blue screen. after the next restard, again the standard vga card driver.
What can i do?
The download section of toshiba has no drivers for graphic card.
And really ... i wonder - how does it works all the years without problems...
Has anyone a solution?
thanx
toshibalover ;-)Hi!
First of all do you have this issue on an external monitor too or only on the internal monitor? Maybe its not a problem of the graphic card so check this with an external monitor.
I have checked the Toshiba website and there I can find some drivers for the Qosmio F30:
http://eu.computers.toshiba-europe.com => Support & Downloads => Download Drivers
Bye -
How to fit to size to show the whole image in image display?
HI, I am using a control palette to display my video images using image display. However, the size is alway out of proportion. How do i show the whole image in the small box screen size. Basically how to fit to size for the images?
Solved!
Go to Solution.This should do the trick:
Norbert
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it. -
HT4623 How do I get the calendar to show the whole month and not just the day or week.
How do I get the calendar on my updated i phone 7 to show the whole month and not just the week or the day?
Touch the arrow (or word) at upper left (e.g. September).
-
Hi,
I need to show the structure/hierarchy of every site in my site collection on masterpage (ie. side bar).
My purpose:
1. Help user can visualize which sites are they
2. User can know what's the parent site & subsite
3. User can easily navigate from sites to sites.
Apart from using third party tools( like MySharepoint Sites by QuePort), is there any way to achieve this? Or do you have any other third party tools to recommend?
Thanks,
ElliotTo achieve your goal, the feature of SharePoint Server Publishing Infrastructure needs to be enabled first. The following steps are for your reference:
1. Open the site collection, click the gear icon in the upper right corner, then click
Site settings.
2. On the Site Settings page, click Site collection features
under Site Collection Administration, locate SharePoint Server Publishing Infrastructure, and click
Activate.
3. Go back to the Site Settings page, click Navigation under
Look and Feel, select Show subsites in the Global Navigation section, and click
OK.
4. Go to the sub sites, click the gear icon in the upper right corner->Site settings->Naviagtion-> select
Show subsites in the Global Navigation section-> click
OK.
Or
1. Click Site Settings.
2. Click Tree view under Look and Feel.
3. Select Enable Tree View.
4. Click OK.
If this helped you resolve your issue, please mark it Answered -
i have a mac os x snow leopard. my problem is that when i go to the ethernet settings it shows 'not connected'. i called the internet person even he couldn't fix it PLEASE HELP!!!!!!!!!!!!!!
System Preferences > Network > Ethernet? If that shows "not connected" that is all your Mac knows. As far as it is concerned there is no cable connected to the port on your Mac, or the other end of the cable is either disconnected or connected to something that is broken.
Try another cable. If the cable is broken you will also get that status message. If you have exhausted all of these possibilities, the only remaining cause is an inoperative port on your Mac. -
When I try to go on the internet with my iPad 2, the whole section is greyed out. I can see the webpage, but can not navigate any further. I do have wifi access, though.
Try:
- A reset. Nothing will be lost.
Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
least ten seconds, until the Apple logo appears
- Power off and then back on the router
- Reset Network Settings: Settings>General>Reset>Reset Network Settings
- iOS: Troubleshooting Wi-Fi networks and connections -
What is going on with Forms Central? The whole systems seems to be down.
What is going on with Forms Central? The whole systems seems to be down. And why has my login window for the last few months become so small its almost unreadable?
tgostkowski1 wrote:
>> And why has my login window for the last few months become so small its almost unreadable?
I don't understand what you mean by this. Can you please elaborate and/or include a screenshot?
Thanks,
Shannon
Maybe you are looking for
-
My Equium M50 has no sound anymore
Hi there I got a Equium M50-216. About four months ago I have been using it to watch a lot of DVDs recently without any problem until last night. When I put a DVD on to watch there was no sound. This has happened with other DVDs and cannot understand
-
hi all, is there any way in sap through which we can mantain the G/L A/c Balance? i.e if an a/c balance goes below the particular balance the system should not allow the user to make any outgoing payment. I am an abap consultant.......so plz tell me
-
Lock the report changed by USER
Hi All, I have created queries in BEx for the end user . now i want to lock these report so that no one can change it ( Display Only). What are the steps to do that ? Regards, Komik Shah
-
Material Ledger - Not Distributed when use MR22
Dear All I do follow step and i have a problem which need your help 1. Create a Mew Materail, price determination: 3 - Single/Multi level 2. GR with Mvt 561. 3. Using MR22 to update valuae for that material. 4. Run CKMLCP --> I have 2 question 1. Whe
-
How to create recovery discs for HP notebook with preinstall​ed Windows ?
I Have just bought the HP ProBook 4530s with preinstalled Windows 7 Home Premium 64bit. The notebook was purchased in the hipermarket so that it has no Windows installation discs. There is a Windows 7 label sticked to the machine. When I try to use