Building a recursive query using start with/connect by......
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!
Dev
try 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/]
Similar Messages
-
How to pass multiple parameters to Query using START WITH, CONNECT BY OBIEE
Hi
I have following oracle query which need to be used as a Data Source in OBIEE Physical Layer. I guess I have to create stored proc. How do I implement this in OBIEE RPD and how do I implement the respective Dashboard prompts for the parameters.
SELECT
CIRC.PATH_NAME, CIRC.BANDWIDTH , CIRC.CATEGORY, CIRC.CUSTOMER_ID,
CIRC.STATUS, CIRC.CUSTOMER_NAME,
QUER.LEV
FROM
CIRCUIT_PATH circ, VAL_CUSTOMER cust,
( SELECT
DISTINCT CIRC_PATH_INST_ID, LEVEL LEV
FROM
CIRC_PATH_ELEMENT
START WITH
CIRC_PATH_ELEMENT.CIRC_PATH_INST_ID IN ( SELECT
DISTINCT CIRC_PATH_INST_ID
FROM
PORTS a
WHERE SITE_NAME = @variable('Enter a Site Name')
AND CARD_SLOT = @variable('Enter a Card Slot')
CONNECT BY
PRIOR CIRC_PATH_ELEMENT.CIRC_PATH_INST_ID =
CIRC_PATH_ELEMENT.PATH_INST_ID
AND ELEMENT_TYPE != 'K' ) QUER
WHERE
circ.circ_path_inst_id = QUER.CIRC_PATH_INST_ID
and circ.cust_inst_id = cust.cust_inst_id (+)
ORDER BY
LEV DESC , CIRC.PATH_NAME ASC, CIRC.BANDWIDTH ASC
Thanks
DGHi John
Thanks. I looked at your URL. I do have package. Just using procedure. So my initialization string (For stored proc in Physical Layer of RPD) is
exec demo.add_employee(VALUEOF(NQ_SESSION.empid1));
But when I run request in Answer I get the error
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 900, message: ORA-00900: invalid SQL statement at OCI call OCIStmtExecute: exec demo.add_employee(105); . [nQSError: 17011] SQL statement execution failed. (HY000)
What should I put in initialization string in RPD?
Thanks
DG -
Using START WITH and CONNECT BY PRIOR in a report
Hi - I am using Oracle 9i and reports 10g. Does anyone know of a reason why running my sql in TOAD will produce the correct results, but the report is dropping records? I am using start with and connect by prior to build a hierarchy of linked records. The report is dropping the "child records" and only returning records from the route level.
Thanks you for your help.Hi user574499
Could u pls share us ur Query...?
Regards,
Abdetu... -
How i use start with and rollup both in one query
hi master
sir i use rollup function for subtotal but rollup not give tree
for tree i want to use start with and connect by function
but that query give error
sir how i use both rollup and start with connect by in one query
for tree wise subtotal
please give me idea
thanking youhi master
thank for your reply
sir i get accid and title from master table and balance from detial table then system give me error
sir i send me all table and data with query and error
Sir this is my master table
SQL> desc chartofacc;
Name Null? Type
PARENT NUMBER
CHILD NUMBER
ACCID NOT NULL VARCHAR2(15)
TITLE VARCHAR2(99)
CAMPID VARCHAR2(2)
ACTIVE NUMBER
FSTATUS NUMBER
Data
Parent child accid
1 K1
1 11 K11
11 1101 K1101
11 1102 K1102
11 1103 K1103
11 1104 K1104
11 1105 K1105
11 1106 K1106
11 1107 K1107
11 1108 K1108
11 1109 K1109
11 1110 K1110
11 1111 K1111
11 1112 K1112
11 1113 K1113
11 1114 K1114
1 12 K12
12 1201 K1201
12 1202 K1202
12 1203 K1203
1 13 K13
13 1301 K1301
1301 130101 K130101
1301 130102 K130102
1301 130103 K130103
1301 130104 K130104
1301 130105 K130105
1301 130106 K130106
1301 130107 K130107
1301 130108 K130108
1301 130109 K130109
1301 130110 K130110
1301 130111 K130111
1301 130112 K130112
1301 130113 K130113
1301 130114 K130114
1301 130115 K130115
13 1302 K1302
1302 130201 K130201
1302 130202 K130202
1302 130203 K130203
1302 130204 K130204
1302 130205 K130205
13 1303 K1303
1303 130301 K130301
1303 130302 K130302
1303 130303 K130303
13 1304 K1304
1304 130401 K130401
1304 130402 K130402
1304 130403 K130403
1304 130404 K130404
1304 130405 K130405
1304 130406 K130406
1304 130407 K130407
1304 130408 K130408
13 1305 K1305
1305 130501 K130501
1305 130502 K130502
13 1306 K1306
1306 130601 K130601
13 1307 K1307
1307 130701 K130701
1307 130702 K130702
1307 130703 K130703
1307 130704 K130704
13 1308 K1308
1308 130801 K130801
1308 130802 K130802
1308 130803 K130803
1308 130804 K130804
1308 130805 K130805
1308 130806 K130806
1308 130807 K130807
1308 130808 K130808
1308 130809 K130809
1308 130810 K130810
1308 130811 K130811
1308 130812 K130812
1308 130813 K130813
13 1309 K1309
13 1310 K1310
13 1311 K1311
1311 131101 K131101
2 K2
2 21 K21
21 2101 K2101
2101 210101 K210101
2101 210102 K210102
2101 210103 K210103
2101 210104 K210104
21 2102 K2102
2102 210201 K210201
2102 210202 K210202
2102 210203 K210203
2102 210204 K210204
21 2103 K2103
2103 210301 K210301
2103 210302 K210302
2103 210303 K210303
2103 210304 K210304
21 2104 K2104
2104 210401 K210401
2104 210402 K210402
2104 210403 K210403
2104 210404 K210404
2 22 K22
22 2201 K2201
2201 220101 K220101
2201 220102 K220102
2201 220103 K220103
2201 220104 K220104
2201 220105 K220105
22 2202 K2202
2202 220201 K220201
2202 220202 K220202
2202 220203 K220203
2202 220204 K220204
22 2203 K2203
2203 220301 K220301
2203 220302 K220302
2203 220303 K220303
2203 220304 K220304
22 2204 K2204
2204 220401 K220401
2204 220402 K220402
2204 220403 K220403
22 2205 K2205
2205 220501 K220501
2205 220502 K220502
220502 22050201 K22050201
220502 22050202 K22050202
220502 22050203 K22050203
220502 22050204 K22050204
22 2206 K2206
2206 220601 K220601
2206 220602 K220602
2206 220603 K220603
2206 220604 K220604
2 23 K23
23 2301 K2301
2301 230101 K230101
2301 230102 K230102
2301 230103 K230103
2301 230104 K230104
2301 230105 K230105
2301 230106 K230106
2301 230107 K230107
2301 230108 K230108
23 2302 K2302
2302 230201 K230201
2302 230202 K230202
2302 230203 K230203
2302 230204 K230204
23 2303 K2303
2303 230301 K230301
2303 230302 K230302
23 2304 K2304
2304 230401 K230401
2304 230402 K230402
2304 230403 K230403
23 2305 K2305
2305 230501 K230501
23 2306 K2306
2306 230601 K230601
2306 230602 K230602
2306 230603 K230603
2306 230604 K230604
23 2307 K2307
23 2308 K2308
2308 230801 K230801
2308 230802 K230802
2308 230803 K230803
23 2309 K2309
2309 230901 K230901
2309 230902 K230902
2309 230903 K230903
2309 230904 K230904
23 2310 K2310
2310 231001 K231001
2310 231002 K231002
2310 231003 K231003
23 2311 K2311
2311 231101 K231101
2311 231102 K231102
2311 231103 K231103
23 2312 K2312
2312 231201 K231201
2312 231202 K231202
2312 231203 K231203
2312 231204 K231204
23 2313 K2313
2313 231301 K231301
2313 231302 K231302
2313 231303 K231303
2313 231304 K231304
2313 231305 K231305
2313 231306 K231306
2313 231307 K231307
2313 231308 K231308
2313 231309 K231309
2313 231310 K231310
2313 231311 K231311
2313 231312 K231312
2313 231313 K231313
2313 231314 K231314
2313 231315 K231315
23 2314 K2314
2314 231401 K231401
2314 231402 K231402
2314 231403 K231403
2314 231404 K231404
2314 231405 K231405
2314 231406 K231406
2314 231407 K231407
23 2315 K2315
23 2316 K2316
2316 231601 K231601
2316 231602 K231602
23 2317 K2317
23 2318 K2318
23 2319 K2319
2319 231901 K231901
2319 231902 K231902
2319 231903 K231903
2319 231904 K231904
2319 231905 K231905
2319 231906 K231906
23 2320 K2320
2320 232001 K232001
3 K3
3 31 K31
31 3101 K3101
31 3102 K3102
31 3103 K3103
31 3104 K3104
31 3105 K3105
3 32 K32
32 3201 K3201
32 3202 K3202
32 3203 K3203
32 3204 K3204
32 3205 K3205
32 3206 K3206
32 3207 K3207
4 K4
4 41 K41
41 4101 K4101
4101 410101 K410101
4101 410102 K410102
4101 410103 K410103
4101 410104 K410104
4101 410105 K410105
4101 410106 K410106
4101 410107 K410107
4101 410108 K410108
4101 410109 K410109
4101 410110 K410110
4101 410111 K410111
4101 410112 K410112
4101 410113 K410113
4101 410114 K410114
4101 410115 K410115
4101 410116 K410116
4101 410117 K410117
4101 410118 K410118
4101 410119 K410119
4101 410120 K410120
4101 410121 K410121
4101 410122 K410122
4101 410123 K410123
4101 410124 K410124
4101 410125 K410125
4101 410126 K410126
4101 410127 K410127
4101 410128 K410128
4101 410129 K410129
4101 410130 K410130
4101 410131 K410131
4101 410132 K410132
41 4102 K4102
41 4103 K4103
41 4104 K4104
4104 410401 K410401
4104 410402 K410402
4104 410403 K410403
4104 410404 K410404
41 4105 K4105
41 4106 K4106
41 4107 K4107
41 4108 K4108
4108 410801 K410801
4108 410802 K410802
4108 410803 K410803
41 4109 K4109
4109 410901 K410901
4109 410902 K410902
4109 410903 K410903
41 4110 K4110
41 4111 K4111
4111 411101 K411101
4111 411102 K411102
4111 411103 K411103
41 4112 K4112
4112 411201 K411201
41 4113 K4113
4113 411301 K411301
41 4114 K4114
4114 411401 K411401
4114 411402 K411402
5 K5
5 51 K51
51 5101 K5101
51 5102 K5102
51 5103 K5103
51 5104 K5104
51 5105 K5105
51 5106 K5106
51 5107 K5107
51 5108 K5108
51 5109 K5109
51 5110 K5110
51 5111 K5111
51 5112 K5112
51 5113 K5113
51 5114 K5114
6 K6
6 61 K61
7 K7
7 71 K71
7 72 K72
7 73 K73
7 74 K74
7 75 K75
7 76 K76
This is my detil table
SQL> desc accbal;
Name Null? Type
ACCID VARCHAR2(15)
YEARID NUMBER
CRBAL NUMBER
DRBAL NUMBER
ENTDATE DATE
BALID NUMBER
Data in detail
K1101 46291132
K1102 13182173
K1103 23784045
K1107 10001795
K1108 9083529
K1110 4224350
K1112 6696832
K1113 7963381
K1114 742766
K1201 1486082
K130104 1977616
K130106 736266
K130107 396673
K130108 42751
K130109 298362
K130110 187696
K130111 537
K130112 942
K130113 987
K130114 1272
K130115 40000
K130205 259941
K130303 177716
K130406 809719
K130408 1786091
K130701 301000
K130702 151200
K130703 7570
K130704 34400
K1308
K130801 5400
K130802 45000
K130803 10856
K130807 24300
K130808 16500
K130810 104500
K130811 60000
K130812 181000
K130813 1750000
K1309 1225565
K1310 2176259
K1311
K131101 788780
K410101 24926
K410102 9545
K410103 28500
K410104 8192
K410105 847
K410106 37100
K410107 2332
K410108 9844
K410109 7843
K410110 9313
K410111 1425
K410112 6089
K410113 15497
K410114 5790
K410115 4251
K410116 22293
K410117 855
K410118 6497
K410119 14996
K410120 124214
K410121 6713
K410122 1567
K410123 75821
K410124 5085
K410125 7125
K410126 4342
K410127 21485
K410128 641111
K410129 589
K410130 50
K410131 163900
K410132 3849
K4105 3946489
K4107 100000
K410801 972011
K410802 1707806
K410803 116450
K4110 13113874
K411101 98335
K411102 32454
K411103 53569
K411201 25327406
K411301 7143103
K411401 4500000
K411402 12754
K5102 2120031
K5103 13543810
K5107 4596103
K5108 5604493
K5110 2008401
K5112 2182778
K5113 4748537
K5114 556914
K61 43297680
Sir I use this query
select lpad(' ',2*(level-1)) || to_char(child),title,sum(drbal),sum(crbal),
from chartofacc, accbal
where chartofacc.accid=accbal.accid(+)
start with parent is null
connect by prior child = parent
group by rollup(substr(mas.accid,2,1),substr(mas.accid,3,1),substr(mas.accid,4,2),substr(mas.accid,6,2) ,chartofacc.accid,title,fstatus);
sir this query not give me result and give me error this
SQL> /
from chartofacc, accbal
ERROR at line 2:
ORA-00936: missing expression
Please give me idea how I get tree type subtotal tribalance
Thanking you
Aamir -
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 AMHi 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 -
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. -
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 -
Flash Builder 4.5 can't start with Error 3
Flash Builder 4.5 can't start with error 3 occurred "Please uninstall and reinstall the product".
It is fine after those are done, but this problem occurred again and again after some days.
It is very annoying, please help!For god's sake will anybody from Adobe say something about this?
I'm having the same issue and it's f***ing annoying.
"Please uninstall and reinstall the product" is not an acceptable error message.
Please provide a workaround. -
How to use unload query using JDBC with Informix database
Hi friends,
How can i use unload query using JDBC with Informix database?
When i use it as "unload to 'abc.txt' select * from ........" it gives syntax error.I want to take the data of a table to a file.With dbaccess i can use it but i need to do it using jdbc.
Thanks,
Raneesh.To the best of my ability to tell, the right way to use this product from within Power Query would be to use its API. Unfortunately, we don't currently support either of the methods needed to be able to authenticate with the service (OAuth 2.0 and a relatively-custom
digest-based method). Adding a mechanism to allow use of arbitrary OAuth-protected resources is a fairly high priority for us, and I hope we'll be able to deliver something before mid-2015.
Scraping the website is very hard to do well -- both from an authentication and from a data discovery perspective. -
Hierarchy/heirarchical queries/query start with connect
ok... I have seen many examples of using hierachical queries. All of the example has parent as null and children with 1 parent. I haven't seen any query that queries a child with multiple parents.
For example.
Table A:
Child--Parent
1--null
2--1
3--1
3--2
4--3
5--2
Select query:
Select child, level
from A
start with child = 3
connect by prior child = parent
Result
Child--Level
3--1
4--2
3--1
4--2
Notice that it display the child '3' twice. Its because it has 2 different parent.
My question is that, how do I make the query to display this iteration once?Hi, Sentinel,
I'd love to see a solution that simple, but I don't think it's possible.
Suppose you want to see child=2 and all it's descendants:
--<"begin sample data">
with a as (select 1 child, null parent from dual
union all select 2, 1 from dual
union all select 3, 1 from dual
union all select 3, 2 from dual
union all select 4, 3 from dual
union all select 5, 2 from dual
--<"cut here">
Select child, level
from (select child, min(parent) parent from a group by child)
start with child = 2
connect by prior child = parent;Produces this output:
CHILD LEVEL
2 1
5 2I believe OP wants to get this for the descendants of child=2:
CHILD LEVEL
2 1
5 2[b]
3 2
4 3So what happened to child=3? For child=3, MIN (parent) = 1, according to this query. That's true when the universe is the entire table, but we're only interested in child=2 and its descendants.
Message was edited by:
Frank Kulash
By the way, the comments
--<"begin sample data">
and
--<"cut here">
are brilliant! -
Improve hierarchical query speed using 'start with' and 'conect by prior'
Hi
The query within the 'explain' runs about a second and I need to imporve it.
There are indexes set for both the child_id and the parent_id.
The total number of rows for the PRM_COMPONENTS table is 120000.
I'm working on 'Oracle Database 10g Release 10.2.0.4.0 - 64bit Production' in a Linux OS.
I've included the explain plan below.
Any suggestions would be appreciated.
Thanks
EXPLAIN PLAN FOR
SELECT substr(SYS_CONNECT_BY_PATH(usage_title, '|'), 2, instr( SYS_CONNECT_BY_PATH(usage_title, '|'), '|', -1) -2 )
FROM prm_components p
WHERE LEVEL > 1 and usage_id = 10301100
START WITH parent_usage_id is null
CONNECT BY PRIOR usage_id = parent_usage_id;
select * from table(dbms_xplan.display);
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
| 0 | SELECT STATEMENT | | 6 | 174 | 4 (0)|
|* 1 | FILTER | | | | |
|* 2 | CONNECT BY WITH FILTERING | | | | |
|* 3 | TABLE ACCESS FULL | PRM_COMPONENTS | 69526 | 3937K| 2468 (1)|
| 4 | NESTED LOOPS | | | | |
| 5 | CONNECT BY PUMP | | | | |
| 6 | TABLE ACCESS BY INDEX ROWID| PRM_COMPONENTS | 6 | 174 | 4 (0)|
|* 7 | INDEX RANGE SCAN | PRM_PARENT_USAGE_ID_I | 2 | | 1 (0)|
Predicate Information (identified by operation id):
1 - filter(LEVEL>1 AND "USAGE_ID"=10301100)
2 - access("PARENT_USAGE_ID"=PRIOR "USAGE_ID")
3 - filter("PARENT_USAGE_ID" IS NULL)
7 - access("PARENT_USAGE_ID"=PRIOR "USAGE_ID")
Note
- 'PLAN_TABLE' is old versionHi
I've resolved the issue by other means but here is the description of the table anyways.
USAGE_ID NOT NULL NUMBER
PARENT_USAGE_ID NUMBER
PRODUCT_CODE NOT NULL VARCHAR2(12)
PRINT_OR_ONLINE NOT NULL CHAR(1)
SLP_ID VARCHAR2(24)
RELEASE_NAME VARCHAR2(80)
USAGE_TITLE VARCHAR2(255)
ENT_USAGE_TITLE VARCHAR2(255)
TRANS_TITLE VARCHAR2(255)
REVISION_TYPE VARCHAR2(8)
ACTIVE CHAR(1)
MARKED_FOR_DELETION CHAR(1)
CREATED_DT DATE
CREATED_BY VARCHAR2(80)
UPDATED_DT DATE
UPDATED_BY VARCHAR2(80)
PLANNING_COMMENTS VARCHAR2(2000)
OUTPUT_FILENAME VARCHAR2(200)
TRANSFORMER_ID NUMBER(38)
START_PAGE VARCHAR2(8)
START_PAGE_NUM NUMBER
END_PAGE VARCHAR2(8)
END_PAGE_NUM NUMBER
VOLUME VARCHAR2(8)
SORT_ORDER NUMBER
PRIORITY NUMBER
XREF_BLIND_ENTRY CHAR(1)
SPECIAL_CATEGORY VARCHAR2(20)
TO_BE_REVISED CHAR(1)
EDITOR VARCHAR2(80)
DUE_DT DATE
POSTED_DT DATE
LOGICAL_UOI_ID NOT NULL VARCHAR2(40)
PHYSICAL_UOI_ID NOT NULL VARCHAR2(40)
EDIT_APPROV_UOI_ID VARCHAR2(40)
EDIT_APPROV_BY VARCHAR2(80)
EDIT_APPROV_DT DATE
FINAL_APPROV_UOI_ID VARCHAR2(40)
FINAL_APPROV_BY VARCHAR2(80)
FINAL_APPROV_DT DATE
PHOTO_APPROV_UOI_ID VARCHAR2(40)
PHOTO_APPROV_BY VARCHAR2(80)
PHOTO_APPROV_DT DATE
RIGHTS_APPROV_UOI_ID VARCHAR2(40)
RIGHTS_APPROV_BY VARCHAR2(80)
RIGHTS_APPROV_DT DATE
LAYOUT_APPROV_UOI_ID VARCHAR2(40)
LAYOUT_APPROV_BY VARCHAR2(80)
LAYOUT_APPROV_DT DATE
BLUES_APPROV_UOI_ID VARCHAR2(40)
BLUES_APPROV_BY VARCHAR2(80)
BLUES_APPROV_DT DATE
LAST_PUB_ONLINE_DT DATE
LAST_PUB_PRINT_DT DATE
BLIND_ENTRY_ON_DT DATE
BLIND_ENTRY_OFF_DT DATE
DELIVERY_APPROV_UOI_ID VARCHAR2(40)
DELIVERY_APPROV_BY VARCHAR2(80)
DELIVERY_APPROV_DT DATE
APPROVAL_STATUS VARCHAR2(40)
CHANGE_SINCE_LAST_DELIVERY CHAR(1)
USAGE_COMMENTS VARCHAR2(2000)
LEXILE_CODE VARCHAR2(18)
SERIES VARCHAR2(8)
USAGE_TITLE_TMP VARCHAR2(255)
ENT_USAGE_TITLE_TMP VARCHAR2(255)
WORD_COUNT VARCHAR2(10)
READ_LEV VARCHAR2(7)
GRADES VARCHAR2(80)
DELIVERY_TYPE NOT NULL CHAR(1)
METADATA_APPROVAL_STATUS VARCHAR2(40)
METADATA_APPROVAL_BY VARCHAR2(80)
METADATA_APPROVAL_DT DATE
RESOURCE_FLAG CHAR(1)
STZ_FLAG CHAR(1)
RESOURCE_TYPE_CODE VARCHAR2(16)
ASSET_DESCRIPTION VARCHAR2(2000)
ROLE_CODE VARCHAR2(16)
PROGRAMS_DATA VARCHAR2(256)
TIME_TO_COMPLETE VARCHAR2(32)
ENTITLEMENTS_DATA VARCHAR2(256)
ISBN_10 VARCHAR2(32)
ISBN_13 VARCHAR2(32)
MFG_ITEM_NO VARCHAR2(256)
AR CHAR(1)
SRC CHAR(1)
SRC_POINTS NUMBER
AUTHORS VARCHAR2(320)
SEARCH_STRINGS VARCHAR2(2000)
PATH_SLP_ID VARCHAR2(256)
PATH_GTC VARCHAR2(256)
PATH_TITLE VARCHAR2(2560)
GRL VARCHAR2(8)
COMMON_CORE CHAR(1) -
Required query perfomance tuning which has START WITH CONNECT BY PRIOR
Hi,
I have below small query and the CDDS table with 40+ million records.
SELECT -LEVEL, COMPONENT_ID, COMPONENT_TYPE, COMPONENT_STATUS,
PARENT_COMPONENT_ID, PARENT_COMPONENT_TYPE, other_info
BULK COLLECT INTO ltbl_cdds_rec
FROM CDDS
START WITH
PARENT_COMPONENT_ID IN
( SELECT dns_name
FROM RAS_CARD
WHERE ras_name = <<INPUT_PARAMATER>>
AND parent_component_type = 'CT_NRP')
CONNECT BY PARENT_COMPONENT_ID = PRIOR COMPONENT_ID;
To process this query, its taking 3 hours.
Please suggest the way forward to tune the query for better performance.Create statement for CDDS:
CREATE TABLE CDDS
COMPONENT_TYPE VARCHAR2(30 BYTE),
COMPONENT_ID VARCHAR2(255 BYTE),
PARENT_COMPONENT_TYPE VARCHAR2(30 BYTE),
PARENT_COMPONENT_ID VARCHAR2(255 BYTE),
COMPONENT_VERSION_NO VARCHAR2(30 BYTE),
COMPONENT_STATUS VARCHAR2(30 BYTE),
ODS_CREATE_DATE DATE,
ODS_LAST_UPDATE_DATE DATE,
OTHER_INFO VARCHAR2(255 BYTE)
TABLESPACE APPL_DATA
PCTUSED 0
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
BUFFER_POOL DEFAULT
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
NOMONITORING
ENABLE ROW MOVEMENT;
Create statement for RAS_CARD:
CREATE TABLE RAS_CARD
RAS_NAME VARCHAR2(20 BYTE),
SLOT VARCHAR2(2 BYTE),
RAS_CARD_ID VARCHAR2(30 BYTE),
CARD_TYPE VARCHAR2(5 BYTE),
IP_ADDRESS VARCHAR2(15 BYTE),
DNS_NAME VARCHAR2(255 BYTE),
STATUS VARCHAR2(15 BYTE),
NRP_NO CHAR(2 BYTE),
NRP_TOTAL_ALLOC_CAPACITY NUMBER(10),
CREATED_BY VARCHAR2(10 BYTE),
NRP_ALLOCATED_CAPACITY NUMBER(10),
NIDB_DRA2_KEY VARCHAR2(15 BYTE),
NIDB_DRN1_KEY CHAR(6 BYTE),
ODS_CREATE_DATE DATE,
LAST_UPDATED_BY VARCHAR2(10 BYTE),
ODS_LAST_UPDATE_DATE DATE,
WATERMARK NUMBER(38)
TABLESPACE APPL_DATA
PCTUSED 0
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 1M
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
BUFFER_POOL DEFAULT
NOLOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
NOMONITORING;
Explain Plan for the below query:
select * from CDDS
where PARENT_COMPONENT_ID IN
( SELECT dns_name
FROM RAS_CARD
WHERE ras_name = <<INPUT_PARAMATER>>
| Id | Operation | Name | Rows | Bytes | Cost | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 1 | 107 | 12 | | |
| 1 | TABLE ACCESS BY INDEX ROWID| CDDS | 1 | 62 | 1 | | |
| 2 | NESTED LOOPS | | 1 | 107 | 12 | | |
| 3 | SORT UNIQUE | | | | | | |
|* 4 | TABLE ACCESS FULL | RAS_CARD | 4 | 180 | 6 | | |
| 5 | PARTITION RANGE ITERATOR | | | | | KEY | KEY |
|* 6 | INDEX RANGE SCAN | CDDS_I02 | 10 | | 1 | KEY | KEY |
--------------------------------------------------------------------------------------------- -
How to perform order by in START with connect by ?
I am using the start with function to call range of bom code. Here is the code :
SELECT level BOM_LEVEL, BCODE, bi_item_code,bi_qty
FROM OM_BOM, OM_BOM_ITEM_DETAIL, OM_ITEM_PLANT_PROPERTY_HEAD,
OM_ITEM_PLANT_PROPERTY_DETAIL, OM_ITEM
WHERE BOM_CODE = BI_BOM_CODE
AND IPH_SYS_ID = IPD_IPH_SYS_ID
AND IPH_PLANT_CODE = IPD_IPH_PLANT_CODE
AND IPH_ITEM_CODE = IPD_IPH_ITEM_CODE
AND IPH_GRADE_CODE_1 = IPD_IPH_GRADE_CODE_1
AND IPH_GRADE_CODE_2 = IPD_IPH_GRADE_CODE_2
AND IPH_ITEM_CODE = ITEM_CODE
AND NVL(ITEM_FRZ_FLAG_NUM,2) = 2
AND IPH_APP_CODE_NUM = 1
AND BOM_ITEM_CODE = IPH_ITEM_CODE
AND BOM_CODE = BI_BOM_CODE
AND NVL(BOM_DEVELOPMENT_YN_NUM, 2) = 2 commented by vellingiri.n on 22/06/2007 for enabling the development BOM
AND NVL(BOM_FRZ_FLAG_NUM, 2) = 2
AND IPD_ATTR_CODE = 'DFLT_BOM_CODE'
AND IPD_ATTR_VALUE IS NOT NULL
AND BOM_CODE = IPD_ATTR_VALUE
CONNECT BY PRIOR BI_ITEM_CODE = BOM_ITEM_CODE
AND PRIOR BI_LOWEST_LEVEL_YN = 'N'
--START WITH BOM_CODE = :PWH_BOM_CODE
START WITH ( BOM_CODE >= :F_BOM AND BOM_CODE <= :T_BOM )
The range is from bom code : 95-01-001 to 95-01-002
And the output is :-
Bom Level____bom_code____Bom_item_code_________bi_qty
1____________95-01-001____95-01-001______________1
1____________95-01-001____50-23-008______________2
1____________95-01-001____50-37-001______________1
2____________50-37-001____59-01-001______________2
2____________50-37-001____4230112_______________2
3____________59-01-001____132133________________4
2____________50-23-008____232323________________5
2____________50-23-008____12-11-22_______________3
1____________95-01-002____232323________________5
2____________95-01-002____232311________________1
........ and more
My problem right now, I want to group the bom so that I will be know the total qty of each bom from the range of bom that I count. That output was shown when I run the query in sql. But when I put into report 6i, the grouping has caused the arrangement of my bom runing up and down. How can I control the bom or any group funtion that I can used so that it will group the bom before start with a new bom ???
please help me. Thanks.
LimYou wrote that the output in SQL*Plus is correct but not in Oracle Reports 6i.
Seems to me you have a Reports issue and should ask in that forum. -
To build dynamic SQL Query using some conditions: Pseudo code required
Hi,
I have a requirement where in i have to build a dynamic query based on one count.
Some details on requirement:
1) It's a Proc where i need to return some columns
2) There are some fix set of columns
3) Based on one Count column, i have to decide the rest of the columns.
Consider there is an employee who can work on 'N' number of assignments.
For a particular employee i have to return all the predefined details of assignments like:
1) Assignment Name
2) Assignmanet Id
3) Assignemnt Start Date
4) Assignment End Date
This 'N' can vary from employee to employee. Based on which i have to return my result set. For instance if employee has 3 assignemnts, i have to return Fix columns( employee info) + (3*4) columns. Similarly if the employee has 4 assignments, i will be returning Fix columns + (4*4) columns.
Certainly, the Employee ID is coming as an I/P parameter.
The source table is a vertical table having all details of the employee assignments.
Can anyone help me in coding this proc with the help of some pseudo code?Do you mean you need something like this to be executed dynamically for some known n := max(count(assignment_id))
NOT TESTED !
select e.dept_id,e.emp_id,e.epm_name,
substr(x1,1,instr(x1,';',1,1) - 1) assignment_name_1,
to_number(substr(x1,instr(x1,';',1,1) + 1,instr(x1,';',1,2) - instr(x1,';',1,1) - 1))) assignment_id_1,
to_date(substr(x1,instr(x1,';',1,1) + 1,instr(x1,';',1,3) - instr(x1,';',1,2) - 1)),'yyyymmdd') assignment_start_date_1,
to_date(substr(x1,instr(x1,';',1,1) + 1,instr(x1,';',1,3) + 1)),'yyyymmdd') assignment_end_date_1,
substr(x2,1,instr(x2,';',1,1) - 1) assignment_name_2,
to_number(substr(x2,instr(x2,';',1,1) + 1,instr(x2,';',1,2) - instr(x2,';',1,1) - 1))) assignment_id_2,
to_date(substr(x2,instr(x2,';',1,1) + 1,instr(x2,';',1,3) - instr(x2,';',1,2) - 1)),'yyyymmdd') assignment_start_date_2,
to_date(substr(x2,instr(x2,';',1,1) + 1,instr(x2,';',1,3) + 1)),'yyyymmdd') assignment_end_date_2,
substr(xn,1,instr(xn,';',1,1) - 1) assignment_name_n,
to_number(substr(xn,instr(xn,';',1,1) + 1,instr(xn,';',1,2) - instr(xn,';',1,1) - 1))) assignment_id_n,
to_date(substr(xn,instr(xn,';',1,1) + 1,instr(xn,';',1,3) - instr(xn,';',1,2) - 1)),'yyyymmdd') assignment_start_date_n,
to_date(substr(xn,instr(xn,';',1,1) + 1,instr(xn,';',1,3) + 1)),'yyyymmdd') assignment_end_date_n
from (select e.dept_id,e.emp_id,e.epm_name,
max(decode(rnk,1,x)) x1,
max(decode(rnk,1,x)) x2,
max(decode(rnk,1,x)) xn
from (select e.dept_id,e.emp_id,e.epm_name,
a.assignment_name||';'||to_char(a.assignment_id)||';'||
to_char(a.assignment_start_date,'yyyymmdd')||';'||to_char(a.assignment_end_date,'yyyymmdd') x,
dense_rank() over (partition by e.dept_id,e.emp_id,e.epm_name order by a.assignment_id) rnk
from employees e,assignments a
where e.emp_id = a.emp_id
group by e.dept_id,e.emp_id,e.epm_name
)Regards
Etbin -
Sharepoint 2013 Search Query, get 'Starts With' for the whole term.
Hi,
I need to build an A to Z index for the values of a particular managed property. Managed property contains text with multiple words (for example: 'Whole Sale Items', 'Sample Items').
I need the search to return the values that start with a particular letter. 'myPropOWSTEXT:s*' should return 'Sample Items'. However, this query returns both 'Whole Sale Items' and 'Sample Items'.
Is there a way to write query so that I can get the text values that start with a letter from the beginning of the whole sentence? I mean, in the above example, is there a way that the query returns 'Sale Items' only and
NOT 'Whole Sale Items'?Hi sukhdevtur,
Could you please elaborate the requirement? Also please provide a screenshot about the issue if possible.
What do you mean "Managed property contains text with multiple words (for example: 'Whole Sale Items', 'Sample Items')."?
Is the list column value containing multiple values(e.g. multiple choices type column, manged metadata type column)?
Also it is by design that SharePoint query will match each word divided by the special character "blank space", if it's the case for your issue, as a workaround, you can remove the "blanks space" between the words(e.g.
WholeSaleItems, SampleItems), then start a full crawl and test again, it should work.
Thanks
Daniel Yang
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected]
Maybe you are looking for
-
Help! iPhoto trashed by upgrade to Yosemite.
I just got an iMac Retina 5K (with Yosemite). I "migrated" from a late '09 iMac running Mountain Lion with iPhoto '09 version 8.1.2. Everything migrated EXCEPT iPhoto. Now, iPhoto won't launch. Details below. I tried updating iPhoto to version 9
-
Mountain lion install crashes-corrupted download
Twice now, after lengthy downloads to my 27" IMac running 10.6.8. the mountain lion install crashed in the early stages with the same error message that the download is corrupted. please delete the install package from the application folder and repe
-
Your iTunes store(Kuwaiti) does not match that of the gift certificate(us)
when i entered gift card number i have got this error what should i do ?
-
Lost all calenders when updating software
Hi, Being an utter simpleton I managed to lose all my info from ical when I had a problem with another peice of software. I had to bin my libary and with it all my preferences. I have salvaged some info from the old libary but can't work out where al
-
Listening to Streamed Radio/Sports on the iPhone
One of the reason I stop using the Treo and got the iPhone, was to listen to streaming audio, particularly MLB and college sports. Not sure if this is possible now or in the future. Anyone have any info and updates?