[10 g/8i] Need help with setting up a query
I have a query that takes about 5 minutes to run, and if there is a way to make it faster, I would like to know. It is not a huge problem, but I get to sleep while waiting for it to end. =)Here are the results of the explain plan command and the extra stuff generated by autotrace...
SQL> show parameter optimizer
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 10.2.0.1
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
SQL>
SQL> show parameter db_file_multi
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_file_multiblock_read_count integer 128
SQL>
SQL> show parameter db_block_size
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_block_size integer 8192
SQL>
SQL> show parameter cursor_sharing
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cursor_sharing string EXACT
SQL>
SQL> column sname format a20
SQL> column pname format a20
SQL> column pval2 format a20
SQL>
SQL> select
2 sname
3 , pname
4 , pval1
5 , pval2
6 from
7 sys.aux_stats$;
SNAME PNAME PVAL1 PVAL2
-------------------- -------------------- ----------- --------------------
SYSSTATS_INFO STATUS COMPLETED
SYSSTATS_INFO DSTART 02-07-2006 22:54
SYSSTATS_INFO DSTOP 02-07-2006 22:54
SYSSTATS_INFO FLAGS 1.000
SYSSTATS_MAIN CPUSPEEDNW 500.790
SYSSTATS_MAIN IOSEEKTIM 10.000
SYSSTATS_MAIN IOTFRSPEED 4,096.000
SYSSTATS_MAIN SREADTIM
SYSSTATS_MAIN MREADTIM
SYSSTATS_MAIN CPUSPEED
SYSSTATS_MAIN MBRC
SYSSTATS_MAIN MAXTHR
SYSSTATS_MAIN SLAVETHR
13 rows selected.
Elapsed: 00:00:00.03
SQL> explain plan into plan_table for
2 SELECT CONNECT_BY_ROOT b.parent_part AS part_nbr
3 , b.parent_part
4 , b.child_part
5 , eval_number ('1' || SYS_CONNECT_BY_PATH (b.qty_per, '*')) AS qty
6 FROM (
7 SELECT doc_nbr AS parent_part
8 , comp_part AS child_part
9 , line_nbr
10 , qty_per
11 FROM bill@DB8I
12 WHERE lst_code IN ('G','M')
13 AND begn_eff <= SYSDATE
14 AND end_eff > SYSDATE
15 AND component_type = 'R'
16 AND doc_type = 'BILL'
17 AND status = 'RL'
18 ) b
19 , part@DB8I p
20 , dual
21 WHERE b.child_part = p.part_nbr
22 START WITH b.parent_part = 'MYPARTNBR'
23 CONNECT BY b.parent_part = PRIOR b.child_part
24 AND PRIOR p.part_type = 'M'
25 ;
Explained.
Elapsed: 00:00:00.23
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 2565617462
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Inst |IN-OUT|
--------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 299 | 519 (14)| 00:00:07 | | |
|* 1 | CONNECT BY WITH FILTERING| | | | | | | |
|* 2 | FILTER | | | | | | | |
| 3 | COUNT | | | | | | | |
| 4 | NESTED LOOPS | | 1 | 299 | 519 (14)| 00:00:07 | | |
| 5 | NESTED LOOPS | | 1 | 217 | 517 (14)| 00:00:07 | | |
| 6 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 | | |
| 7 | REMOTE | BILL | 1 | 217 | 515 (14)| 00:00:07 | DB8I | R->S |
| 8 | REMOTE | PART | 1 | 82 | 2 (0)| 00:00:01 | DB8I | R->S |
|* 9 | HASH JOIN | | | | | | | |
| 10 | CONNECT BY PUMP | | | | | | | |
| 11 | COUNT | | | | | | | |
| 12 | NESTED LOOPS | | 1 | 299 | 519 (14)| 00:00:07 | | |
| 13 | NESTED LOOPS | | 1 | 217 | 517 (14)| 00:00:07 | | |
| 14 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 | | |
| 15 | REMOTE | BILL | 1 | 217 | 515 (14)| 00:00:07 | DB8I | R->S |
| 16 | REMOTE | PART | 1 | 82 | 2 (0)| 00:00:01 | DB8I | R->S |
| 17 | COUNT | | | | | | | |
| 18 | NESTED LOOPS | | 1 | 299 | 519 (14)| 00:00:07 | | |
| 19 | NESTED LOOPS | | 1 | 217 | 517 (14)| 00:00:07 | | |
| 20 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 | | |
| 21 | REMOTE | BILL | 1 | 217 | 515 (14)| 00:00:07 | DB8I | R->S |
| 22 | REMOTE | PART | 1 | 82 | 2 (0)| 00:00:01 | DB8I | R->S |
--------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("DOC_NBR"='MYPARTNBR')
2 - filter("DOC_NBR"='MYPARTNBR')
9 - access("DOC_NBR"=NULL AND NULL='M')
Remote SQL Information (identified by operation id):
----------------------------------------------------
7 - SELECT "DOC_NBR","BEGN_EFF","END_EFF","LST_CODE","COMP_PART_NBR","QTY_PE
R","COMPONENT_TYPE","DOC_TYPE","STATUS" FROM "BILL" "BILL" WHERE "COMPONENT_TYPE"='R' AND
"DOC_TYPE"='BILL' AND "STATUS"='RL' AND ("LST_CODE"='G' OR "LST_CODE"='M') AND
"END_EFF">:1 AND "BEGN_EFF"<=:2 (accessing 'DB8I ' )
8 - SELECT "PART_NBR","PART_TYPE" FROM "PART" "P" WHERE :1="PART_NBR" (accessing
'DB8I ' )
15 - SELECT "DOC_NBR","BEGN_EFF","END_EFF","LST_CODE","COMP_PART_NBR","QTY_PE
R","COMPONENT_TYPE","DOC_TYPE","STATUS" FROM "BILL" "BILL" WHERE "COMPONENT_TYPE"='R' AND
"DOC_TYPE"='BILL' AND "STATUS"='RL' AND ("LST_CODE"='G' OR "LST_CODE"='M') AND
"END_EFF">:1 AND "BEGN_EFF"<=:2 (accessing 'DB8I ' )
16 - SELECT "PART_NBR","PART_TYPE" FROM "PART" "P" WHERE :1="PART_NBR" (accessing
'DB8I ' )
21 - SELECT "DOC_NBR","BEGN_EFF","END_EFF","LST_CODE","COMP_PART_NBR","QTY_PE
R","COMPONENT_TYPE","DOC_TYPE","STATUS" FROM "BILL" "BILL" WHERE "COMPONENT_TYPE"='R' AND
"DOC_TYPE"='BILL' AND "STATUS"='RL' AND ("LST_CODE"='G' OR "LST_CODE"='M') AND
"END_EFF">:1 AND "BEGN_EFF"<=:2 (accessing 'DB8I ' )
22 - SELECT "PART_NBR","PART_TYPE" FROM "PART" "P" WHERE :1="PART_NBR" (accessing
'DB8I ' )
...
...
...
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("DOC_NBR"='MYPARTNBR')
2 - filter("DOC_NBR"='MYPARTNBR')
9 - access("DOC_NBR"=NULL AND NULL='M')
Remote SQL Information (identified by operation id):
----------------------------------------------------
7 - SELECT "DOC_NBR","BEGN_EFF","END_EFF","LST_CODE","COMP_PART_NBR","QTY_PE
R","COMPONENT_TYPE","DOC_TYPE","STATUS" FROM "BILL" "BILL" WHERE "COMPONENT_TYPE"='R' AND
"DOC_TYPE"='BILL' AND "STATUS"='RL' AND ("LST_CODE"='G' OR "LST_CODE"='M') AND
"END_EFF">:1 AND "BEGN_EFF"<=:2 (accessing 'DB8I ' )
8 - SELECT "PART_NBR","PART_TYPE" FROM "PART" "P" WHERE :1="PART_NBR" (accessing
'DB8I ' )
15 - SELECT "DOC_NBR","BEGN_EFF","END_EFF","LST_CODE","COMP_PART_NBR","QTY_PE
R","COMPONENT_TYPE","DOC_TYPE","STATUS" FROM "BILL" "BILL" WHERE "COMPONENT_TYPE"='R' AND
"DOC_TYPE"='BILL' AND "STATUS"='RL' AND ("LST_CODE"='G' OR "LST_CODE"='M') AND
"END_EFF">:1 AND "BEGN_EFF"<=:2 (accessing 'DB8I ' )
16 - SELECT "PART_NBR","PART_TYPE" FROM "PART" "P" WHERE :1="PART_NBR" (accessing
'DB8I ' )
21 - SELECT "DOC_NBR","BEGN_EFF","END_EFF","LST_CODE","COMP_PART_NBR","QTY_PE
R","COMPONENT_TYPE","DOC_TYPE","STATUS" FROM "BILL" "BILL" WHERE "COMPONENT_TYPE"='R' AND
"DOC_TYPE"='BILL' AND "STATUS"='RL' AND ("LST_CODE"='G' OR "LST_CODE"='M') AND
"END_EFF">:1 AND "BEGN_EFF"<=:2 (accessing 'DB8I ' )
22 - SELECT "PART_NBR","PART_TYPE" FROM "PART" "P" WHERE :1="PART_NBR" (accessing
'DB8I ' )
Statistics
----------------------------------------------------------
381 recursive calls
1 db block gets
0 consistent gets
0 physical reads
304 redo size
15558 bytes sent via SQL*Net to client
417 bytes received via SQL*Net from client
5 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
379 rows processed
SQL> disconnect
Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
I also have the tkprof output, but let's start with that. I have absolutely no idea where to even start looking for something to improve.
Performance would be much better if the whole query would be executed on the remote side, but the query uses the local function eval_number as well as parts of the query are executed on the remote side and results are brought alongside local and then only filtering is performed. Try the following:
SELECT part_nbr,
parent_part,
child_part,
eval_number ('1' || path) qty
FROM (
SELECT CONNECT_BY_ROOT b.parent_part part_nbr,
b.parent_part,
b.child_part,
SYS_CONNECT_BY_PATH(b.qty_per, '*') path
FROM (
SELECT doc_nbr parent_part,
comp_part child_part,
line_nbr
qty_per
FROM bill@DB8I
WHERE lst_code IN ('G','M')
AND begn_eff <= SYSDATE
AND end_eff > SYSDATE
AND component_type = 'R'
AND doc_type = 'BILL'
AND status = 'RL'
) b,
part@DB8I p
WHERE b.child_part = p.part_nbr
START WITH b.parent_part = 'MYPARTNBR'
CONNECT BY b.parent_part = PRIOR b.child_part
AND PRIOR p.part_type = 'M'
)
/
SY.
Tags: Database
Similar Questions
-
Need help with setting up in checkbox in interactive reports
I need help with setting up in checkbox in interactive reports, I use this statement a query
SELECT apex_item.checkbox
(
1, ROLEID,
'onchange = "spCheckChange (this);". ',
: F_ROLEID_LIST,.
':'
), del.
ROLEID, ROLEDESCRIPTION
OF EBA_ROLES
When I run it I get the following
< input type = "checkbox" name = "f01" value = "1" onchange = "spCheckChange (this); ' / > instead of the checkbox
Do I need to configure anything else
Aditya Gupta wrote:
I need help with setting up in checkbox in interactive reports, I use this statement a query
SELECT apex_item.checkbox
(
1, ROLEID,
'onchange = "spCheckChange (this);". ',
: F_ROLEID_LIST,.
':'
), del.
ROLEID, ROLEDESCRIPTION
OF EBA_ROLES
When I run it I get the following
instead of the checkbox
Do I need to configure anything else
This is one of the most frequently asked questions in this forum. Set the column attribute the text to display as Standard report column and not display text (special escape characters).
Always include the information referred to in these guidelines when you ask a question and if you use APEX 5.0, State, if you develop using the pages or the view of the component designer.
-
Hard drive controller is released on the PC need help with setting up new controller
I have a HP with a built NVidia controller on the mobo. The controller was an error and I am installing an Adaptec 2120SA on the system controller. The computer sees the controller and it tries to start the operating system but has problems it BlueScreens and it blue screens quickly so I do not see the error code. but I think it's because I don't have the drivers of the controller installed in the operating system. I really don't want to reload the workstation. Is it possible to install the drivers of the controller without starting the operating system I tried three other PC and they all have the same questions. as the driver for the controller is not there. The OS is Vista Home Premium 64-bit. The PC is no longer under warranty and a replacement MoBo is too much money.
Thanks in advance for your help.
Hi arjaywolverine,
There is a way that can be attempted to identify the problem and we'll see if it helps.
You need to extract the driver file from hard drive controller on a floppy/flash your motherboard CD drive, and then you restart the computer with the Windows Vista operating system DVD.1. turn on your computer and insert the CD or the DVD of Windows Vista.
2. on the page install Windows, do not click on install now. Instead, click on repair your computer. The System Recovery Options dialog box appears.
3. click load drivers and it prompts you to insert your floppy disk or USB key.
4. navigate to the correct device and click Ok.Once the drivers are installed correctly, remove the DVD and diskette. Restart the computer and who should do it.
Hope this information is useful.
Karena R - Microsoft Support
--------------------------------------------------------------------------------------------------------------------
Visit our Microsoft answers feedback Forum and let us know what you think[If this post can help solve your problem, please click the 'Mark as answer' or 'Useful' at the top of this message.] [Marking a post as answer, or relatively useful, you help others find the answer more quickly.]
-
Need help with set up on PC6624 InterVLAN routing
Hello
I stack 5-switch 5548 Dell PC / 1 PC 6624 switch for layer 3 routing.
I connected battery to PC6624 with 10 GB fiber cable.
I created several VLANs on the layer 2 stack. Now how to set up communication Inter VLAN switch PC 6624?
Concerning
Marion
Hello
Page 507 of the manual explains how to enable IP routing on the switch ftp://ftp.dell.com/Manuals/all-products/esuprt_ser_stor_net/esuprt_powerconnect/powerconnect-6248_User%27s%20Guide2_en-us.pdf
Here is a document explaining the Setup on an older switch, the concepts are the same http://www.dell.com/downloads/global/products/pwcnt/en/app_note_38.pdf
-
Need help with setting wrong and impossible to find ways to fix
Hello
I just installed LM and imported photo. However, I might accidentally click on a few buttons and all the picture in the section developing shown like this. They appear with weird colors (color incorrect). I guess that it maybe because of some settings, but I can't understand that one. Please see the example in this picture (has not edited anything yet). Could you suggest how to correct the adjustment? Thank you very much for your help.
Go to Preferences, click the performance tab, and then uncheck the box.
-
All new to APEX and Oracle - need help with setting up email
I have looked at the APEX for a few months now and finally took the plunge. I installed Oracle 11 g enterprise, 4.2 APEX, APEX listener 2.05 and GlassFish 4. Fine surpringly and I did the step "Activate the Oracle 11 g database Network Services" in the installation guide and can connect to the APEX Admin Services page. I'm about to create my first workspace and realized that only to not configure the e-mail for the APEX instance settings still (the SMTP host address, etc.) I wanted to make sure that the admin workspace would have received an email from the system.
I'll do it soon, but my question is what I have to do something else for the instance of the APEX or the database itself to send?
Thanks in advance!
Hello
If you already Activate Network Services for schema of the APEX to access SMTP server, you just need to Configure Email.
If your SMTP server uses SSL/TLS, you must also Configure portfolio and import the certificate to the SMTP server to the wallet.
Kind regards
Jari
-
Need help with Set-VMHostAdvancedConfiguration
Hello
Following commands do not work for some reason any.
Please see the errors of output.
No idea why it does not work?
$value1 = "[$datastorename] $syslogFoldername / $hostname.log.
$value2 = ' [] / scratch/log ".Game-VMHostAdvancedConfiguration - VMHost $vmhost - name of the "ScratchConfig.ConfiguredScratchLocation" - value $value1
Game-VMHostAdvancedConfiguration - VMHost $vmhost - name of the "Syslog.global.log.DirUnique" - value $value2Game-VMHostAdvancedConfiguration: 25/02/2013-11:55:51 Set-VMHostAdvancedConfiguration
A specified parameter was not correct.D:\sm\ScratchFolders\folder.ps1:23 char: 33
+ Set VMHostAdvancedConfiguration < < < <-VMHost $vmhost - name ScratchConfig.ConfiguredScratchL «»
apartment"- value $value1
+ CategoryInfo: NotSpecified: (:)) [game-VMHostAdvancedConfiguration], InvalidArgument)
+ FullyQualifiedErrorId: Client20_SystemManagementServiceImpl_GetVmHostAdvancedConfiguration_
ViError, VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetVMHostAdvancedConfigurationGame-VMHostAdvancedConfiguration: 25/02/2013-11:55:52 Set-VMHostAdvancedConfiguration
"Syslog.global.log.DirUnique" is not valid or exceeds the maximum number of characters allowed.
D:\sm\ScratchFolders\folder.ps1:25 tank: 36
+ Set VMHostAdvancedConfiguration < < < <-VMHost $vmhost - name of the "Syslog.global.log.DirUnique" - will
read $value2
+ CategoryInfo: NotSpecified: (:)) [game-VMHostAdvancedConfiguration], InvalidName)
+ FullyQualifiedErrorId: Client20_SystemManagementServiceImpl_GetVmHostAdvancedConfiguration_
ViError, VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetVMHostAdvancedConfigurationAs far as I know the 1 config entry should be a path in the local file, something like system "/ vmfs/volumes /...» »
See KB1033696.
For value 2, the key must be "Syslog.global.logDirUnique".
Game-VMHostAdvancedConfiguration - VMHost $vmhost - name of the "Syslog.global.logDirUnique" - value $value2
-
Need help with setting the value of the variable in the callable statement in the OPS
Hi all
I use a callable statement in my code, I put the value as below.
String updateStmt = "BEGIN TEST_PKG. MAIN_PROCEDURE ("+
":1)" +
"; END; « ;
CallableStatement cstmt is getDBTransaction (.createCallableStatement(updateStmt,1));.
cstmt.setString (1, empRow.getLinenum () m:System.NET.SocketAddress.ToString ());
but the problem is when the value of 1 is NULL, I'm not able to call the procedure, it is not inserting data into the table, but when the value of 1 is not null, it is able to call the procedure and inserting the data correctly.
Please help me urgent.
Hello
Please make changes as below
If (empRow.getLinenum (). ToString ()! = null)
{
String updateStmt = "BEGIN TEST_PKG. MAIN_PROCEDURE ('+': 1) «+»; END; « ;
CallableStatement cstmt is getDBTransaction (.createCallableStatement(updateStmt,1));.
cstmt.setString (1, empRow.getLinenum () m:System.NET.SocketAddress.ToString ());
}
Also check out the link Oracle Application Framework Dilip Articles: education prepared - controller
Thank you
Dilip
-
Newbie need help with setting up new WebLogic domain
Installed ALBMP for WebLogic Enterprise on a distribution SUSE Linux running on VMWare. Installation completed successfully and works through the configuration of the installation via the Configuration Wizard. I have problems creating a new WebLogic domain. He throws it toward the high "WebLogic invalid Home" when I try to enter any path directory for this field. He won't let me leave this field empty. Can anyone help? I am running version ALBPM 6.0 M3.
Thank you.Which way you give? a valid weblogic House is F:\bea102\wlserver_10.0 under windows. I think that you not include the wlserver directory.
-
[10g] need help with order by hierarchical query clause
I have the following data samples:
And the following query gives me exactly what I want, in the order I want. However, I wonder if there is a way to get this order without creating the column SEQ, given that I don't need in my resultsCREATE TABLE bill_test1 ( parent_part CHAR(25) , child_part CHAR(25) , line_nbr NUMBER(5) , qty_per NUMBER(9,5) ); INSERT INTO bill_test1 VALUES ('ABC-1','ABC-10',100,1); INSERT INTO bill_test1 VALUES ('ABC-1','ABC-20',200,2); INSERT INTO bill_test1 VALUES ('ABC-1','ABC-30',300,3); INSERT INTO bill_test1 VALUES ('ABC-1','HARDWARE-1',401,10); INSERT INTO bill_test1 VALUES ('ABC-1','HARDWARE-2',402,5); INSERT INTO bill_test1 VALUES ('ABC-10','ABC-155',100,2); INSERT INTO bill_test1 VALUES ('ABC-10','HARDWARE-1',200,1); INSERT INTO bill_test1 VALUES ('ABC-155','RAW-2',100,4.8); INSERT INTO bill_test1 VALUES ('ABC-155','HARDWARE-3',200,3); INSERT INTO bill_test1 VALUES ('ABC-20','RAW-1',100,10.2); INSERT INTO bill_test1 VALUES ('ABC-30','RAW-3',100,3);
SELECT part_nbr , parent_part , child_part FROM ( SELECT CONNECT_BY_ROOT b.parent_part AS part_nbr , b.parent_part , b.child_part , SYS_CONNECT_BY_PATH(b.line_nbr,' ') AS seq FROM bill_test1 b , dual CONNECT BY parent_part = PRIOR child_part ) WHERE part_nbr = 'ABC-1' ORDER BY seq ; Results of above query, except with SEQ included in SELECT (just to show what I'm sorting off of): PART_NBR PARENT_PART CHILD_PART SEQ ---------------------------- ---------------------------- ---------------------------- ----------------- ABC-1 ABC-1 ABC-10 100 ABC-1 ABC-10 ABC-155 100 100 ABC-1 ABC-155 RAW-2 100 100 100 ABC-1 ABC-155 HARDWARE-3 100 100 200 ABC-1 ABC-10 HARDWARE-1 100 200 ABC-1 ABC-1 ABC-20 200 ABC-1 ABC-20 RAW-1 200 100 ABC-1 ABC-1 ABC-30 300 ABC-1 ABC-30 RAW-3 300 100 ABC-1 ABC-1 HARDWARE-1 401 ABC-1 ABC-1 HARDWARE-2 402
Hello
As long as there is that a single root, brothers and SŒURS of ORDER BY, you say, but you can not do in a subquery (well, you can, but usually there is no interest in a subquery). If the CONNECT BY in a subquery, there is no guarantee that the main request will preserve the hierarchical order which provides the subquery.
The query you posted does not require a query of Tahina, so you can say:
SELECT CONNECT_BY_ROOT b.parent_part AS part_nbr , b.parent_part , b.child_part --, SYS_CONNECT_BY_PATH(b.line_nbr,' ') AS seq FROM bill_test1 b WHERE CONNECT_BY_ROOT b.parent_part = 'ABC-1' CONNECT BY parent_part = PRIOR child_part ORDER SIBLINGS BY b.line_nbr ;
I said the query you posted does not require a subquery. It also does not require double, so I guess that what you posted is a simplification of what you are really doing, and that could have a subquery. In particular, if you want to GROUP BY part_nbr, you need the subquery. We can use CONNECT_BY_ROOT expression in the WHERE clause (or, come to think of it, use a START WITH clause instead WHERE), but, for some reason, we cannot use CONNECT_BY_ROOT in a clause GROUP BY; We need to calculate CONNECT_BY_ROOT in a subquery, give it a name (like part_nbr) and Super GROUP OF this column in a query.
This requires that there is that one node root. ORDER OF brothers and SŒURS means just that: children of a common parent will appear in the order, but the root nodes, which have no parents, may not be in order.
Here's what I meant by using START WITH place WHERE:
SELECT CONNECT_BY_ROOT b.parent_part AS part_nbr , b.parent_part , b.child_part --, SYS_CONNECT_BY_PATH(b.line_nbr,' ') AS seq FROM bill_test1 b START WITH b.parent_part = 'ABC-1' CONNECT BY parent_part = PRIOR child_part ORDER SIBLINGS BY b.line_nbr ;
This should be much more effective, because it reduces the results before waste you your time by getting their descendants.
With the help of a clause START WITH here is analogous to me sending you an email, saying "come to a meeting one my office at 03:00."
By using a WHERE clause here is similar by sending me an e-mail to all members of society, saying: "come to a meeting one my office at 3:00" and then, as people get here, tell everyone except you could go back.Brothers and SŒURS ORDER BY was introduced in Oracle 9.
Published by: Frank Kulash, December 9, 2010 14:39
Added version with the START WITH clause -
Need help with a self-join query
Hello
I have A table with the following data
OID parent_oid
4 of 10
4 2
2 2
12 6
6 6
parent_oid is the parent of the oid. I would like a query that displays the final parent of the oid. The result must indicate the following
Final parent OID
2 of 10
4 2
2 2
12 6
6 6
I use Oracle 10 g. I am familiar with free joins, but that alone will not do the job. Thank you!Hello
arizona9952 wrote:
... I am familiar with free joins, but that alone will not do the job.You are absolutely right!
A self-join 2-way would work for lines have no parent, or lines which are directly related to their final ancestor (such as the oid = 4), but not for what anyone further.
A 3-way self-join would work to a level more away from the last row, but no more. That would be enough with the small set of sample data that you posted, but it won't work if you have added a new rank parent_id = 10.
An N - way self-join would work for up to N + 1 levels, but no more.You need something that can go to any number of levels, such as CONNECT BY:
SELECT CONNECT_BY_ROOT oid AS oid , parent_oid AS final_parent FROM a WHERE CONNECT_BY_ISLEAF = 1 CONNECT BY oid = PRIOR parent_oid AND oid != parent_oid ;
Published by: Frank Kulash, February 22, 2010 19:09
On sober reflection, I think that a request from top down, as one below, would be more effective than a motion up and down, like the one above:
SELECT oid , CONNECT_BY_ROOT parent_oid AS final_parent FROM a START WITH parent_oid = oid CONNECT BY parent_oid = PRIOR oid AND oid != PRIOR oid ;
-
Need help with rewrite of a query
Hi friends,
PFB the query and the result. Please ignore where the conditions, they are only about 50% accurate.
SELECT XMLELEMENT ( 'majorLine' XMLATTRIBUTES ( ) d. ) line_id AS "Row Id" ),
xmlforest (d. ) ordered_item as "itemName" ,
d . ordered_quantity as 'quantity' ),
(SELECT XMLAGG (XMLELEMENT ()"Service" XMLATTRIBUTES (e. ))) line_id AS Service ),
( ) SELECT XMLAGG (XMLELEMENT ( "ServiceName" ))
XMLATTRIBUTES (of. ) ordered_item AS "ItemName" ),
xmlforest (of. ) ordered_item as "itemName" ,
de . ordered_quantity as 'quantity' )))
DE oe_order_lines_all of
OÙ de . line_id = e. line_id et de . link_to_line_id is null )))
DE oe_order_lines_all e
OÙ e. line_id = 143424538 ),
(SELECT XMLAGG (XMLELEMENT ()"minorLine" XMLATTRIBUTES (e. ))) line_id AS minorLine ),
( ) SELECT XMLAGG (XMLELEMENT ( "itemName" ))
XMLATTRIBUTES (of. ) ordered_item AS "ItemName" ),
xmlforest (of. ) ordered_item as "itemName" ,
de . ordered_quantity as 'quantity' )))
DE oe_order_lines_all of
OÙ de . line_id = e. line_id )))
DE oe_order_lines_all e
OÙ ( e. line_id = 143424538 ), (SELECT XMLAGG (XMLELEMENT ()"service" XMLATTRIBUTES (e. ))) line_id AS Service ),
( ) SELECT XMLAGG (XMLELEMENT ( "serviceName" ))
XMLATTRIBUTES (of. ) ordered_item AS "itemName" ),
xmlforest (of. ) ordered_item as "itemName" ,
de . ordered_quantity as 'quantity' )))
DE oe_order_lines_all of
OÙ de . line_id = e. line_id et de . link_to_line_id is null )))
DE oe_order_lines_all e
OÙ ( e. line_id = 143424538 ( )
( ) YOU "dept_list"
DE oe_order_lines_all d où d . line_id = 143424538 ;
The output is:
< majorLine Line Id='143424538'>
< itemName > 15454-TCC3-K9 = </ itemName >
< quantity > 10 < / quantity >
< Service SERVICE='143424538'>
< ServiceName ItemName'15454-TCC3-K9 ='=>
< itemName > 15454-TCC3-K9 = </ itemName >
< quantity > 10 < / quantity >
</ ServiceName >
</ Service >
< minorLine MINORLINE='143424538'>
< itemName ItemName'15454-TCC3-K9 ='=>
< itemName > 15454-TCC3-K9 = </ itemName >
< quantity > 10 < / quantity >
</ itemName >
</ minorLine >
< service SERVICE='143424538'>
< serviceName itemName'15454-TCC3-K9 ='=>
< itemName > 15454-TCC3-K9 = </ itemName >
< quantity > 10 < / quantity >
</ serviceName >
</ service >
</ majorLine >
But the production expected as below
< majorLine Line Id="143">
< itemName > 15454-K = </ itemName >
< quantity > 10 < / quantity >
< Service >
< lineId >143424538 < / lineId >
< itemName > 15454-9 = </ itemName >
< quantity > 10 < / quantity >
</ Service >
< minorLine MINORLINE='143424538'>
< itemName > 1549 = </ itemName >
< quantity > 10 < / quantity >
</ minorLine >
< service >
< lineId >143424538 < / lineId >
< itemName > 159= </ itemName >
< quantity > 10 < / quantity >
</ service >
</ majorLine >
So the exact structure of XML output will be like that. In the example above, I didn't add the service of minors and several minor lines.
I need to change the code above in the format below.
< majorLine = "123456" LineID >-> there will be only one line of Major
< itemNamme > MajorLineItem < / itemName >
< quantity > 2 < / quantity >
< service > -> there may be more than one service or no service of this major axis
< > < lineId > 123456 lineId
< itemNamme > serviceOfmajor < / itemName >
< quantity > 2 < / quantity >
< / service >
< minorLine LineID '456789' = > -> there are several minor this major line lines
< itemNamme > first_MinorlineItem < / itemName >
< quantity > 7 < / quantity >
< service >-> there may be more than one or NONE of the lines of service for one minor line
< > < lineId > 11212 lineId
< itemNamme > First_serivceOfMinor < / itemName >
< quantity > 2 < / quantity >
< / service >
< service >-> it may be more than one service lines for a line of minor
< > 1347657 < lineId > lineId
< itemNamme > second_serivceOfMinor < / itemName >
< quantity > 2 < / quantity >
< / service >
< minorLine LineID = "477838" > -> there are several minor this major line lines
< itemNamme > second_MinorlineItem < / itemName >
< quantity > 3 < / quantity >
< / majorLine >
Please help me to re - write the code. I used the approach of DOM node, its very long, I'm trying to replace it. Help, please. Let me know if you have any questions.
Thank you and best regards,
Arun Thomas T
Not a Constructive Question.
-
[8i] need help with hierarchical (connection by) query
First of all, I work in 8i.
My problem is, I get the error ORA-01437 message: cannot have join with CONNECT BY.
And the reason why I get this error because one of the criteria that I use to cut a few branches with is in another table... Is anyway to circumvent this? I tried a view online (but got the same error). I thought to use the connection by query views online and filtering off the coast of what I don't want in this way, but I don't know how to filter an entire branch...
Simplified data examples:
It's the questioning of base (with no pruning of branches):CREATE TABLE bom_test ( parent CHAR(25) , component CHAR(25) , qty_per NUMBER(9,5) ); INSERT INTO bom_test VALUES ('ABC-1','101-34',10); INSERT INTO bom_test VALUES ('ABC-1','A-109-347',2); INSERT INTO bom_test VALUES ('ABC-1','ABC-100G',1); INSERT INTO bom_test VALUES ('ABC-1','1A247G01',2); INSERT INTO bom_test VALUES ('ABC-100G','70052',18); INSERT INTO bom_test VALUES ('ABC-100G','M9532-278',5); INSERT INTO bom_test VALUES ('1A247G01','X525-101',2); INSERT INTO bom_test VALUES ('1A247G01','1062-324',2); INSERT INTO bom_test VALUES ('X525-101','R245-9010',2); CREATE TABLE part_test ( part_nbr CHAR(25) , part_type CHAR(1) ); INSERT INTO part_test VALUES ('ABC-1','M'); INSERT INTO part_test VALUES ('101-34','P'); INSERT INTO part_test VALUES ('A-109-347','P'); INSERT INTO part_test VALUES ('ABC-100G','M'); INSERT INTO part_test VALUES ('1A247G01','P'); INSERT INTO part_test VALUES ('70052','P'); INSERT INTO part_test VALUES ('M9532-278','P'); INSERT INTO part_test VALUES ('X525-101','M'); INSERT INTO part_test VALUES ('1062-324','P'); INSERT INTO part_test VALUES ('R245-9010','P');
The above query results:SELECT LEVEL , b.component , b.parent , b.qty_per FROM bom_test b START WITH b.parent = 'ABC-1' CONNECT BY PRIOR b.component = b.parent
.. .but I want to only the branches (children, grandchildren, etc.) the type of part of'm '.LEVEL COMPONENT PARENT QTY_PER ----------- ------------------------- ------------------------- ----------- 1.000 101-34 ABC-1 10.000 1.000 A-109-347 ABC-1 2.000 1.000 ABC-100G ABC-1 1.000 2.000 70052 ABC-100G 18.000 2.000 M9532-278 ABC-100G 5.000 1.000 1A247G01 ABC-1 2.000 2.000 X525-101 1A247G01 2.000 3.000 R245-9010 X525-101 2.000 2.000 1062-324 1A247G01 2.000 9 rows selected.
for example:
Any suggestions?LEVEL COMPONENT PARENT QTY_PER ----------- ------------------------- ------------------------- ----------- 1.000 101-34 ABC-1 10.000 1.000 A-109-347 ABC-1 2.000 1.000 ABC-100G ABC-1 1.000 2.000 70052 ABC-100G 18.000 2.000 M9532-278 ABC-100G 5.000 1.000 1A247G01 ABC-1 2.000
Hello
Difficult problem!
Sorry for the false leads I posted last night.
In Oracle 8.1, you can CONNECT BY first of all, in a view online and then to join her, but you can't do the reverse.
We can change the 3 query to get the desired results by replacing the external CONNECTION BY a series of analytical functions to locate all ancestors and finally SELECT a line only if all the ancestors had part_type = am'.It's not pretty, but it works:
SELECT component, parent, qty_per --, r_num, lvl --, SUM (ancestor_ok) FROM ( -- Begin in-line view to calculate ancestor_ok SELECT m.* , CASE WHEN c_num < lvl THEN LAG ( part_ok , r_num - NVL ( a_pos , 0 ) ) OVER ( PARTITION BY c_num ORDER BY r_num ) END AS ancestor_ok FROM ( -- Begin in-line view of 'M' parts in hierarchy SELECT h.component , h.parent , h.qty_per , h.r_num , h.lvl , p.part_ok , c.c_num , MAX ( CASE WHEN lvl = c_num THEN r_num ELSE 0 END ) OVER ( PARTITION BY c_num ORDER BY r_num ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING ) AS a_pos FROM ( -- Begin in-line view h, hierarchy from bom_test SELECT component , parent , qty_per , ROWNUM AS r_num , LEVEL AS lvl FROM bom_test START WITH parent = 'ABC-1' CONNECT BY parent = PRIOR component ) h -- End in-line view h, hierarchy from bom_test , ( -- Begin in-line view p, to get part+_ok from part_test SELECT part_nbr , CASE WHEN part_type = 'M' THEN 1 ELSE 0 END AS part_ok FROM part_test ) p -- End in-line view p, to get part+_ok from part_test , ( -- Begin in-line view c, counter SELECT ROWNUM AS c_num FROM bom_test WHERE ROWNUM <= 10 -- Guess at maximum number of levels, or omit ) c -- End in-line view c, counter WHERE p.part_nbr = h.component AND c.c_num <= h.lvl ) m -- End in-line view of 'M' parts in hierarchy ) -- End in-line view to calculate ancestor_ok GROUP BY component, parent, qty_per , r_num, lvl HAVING lvl = 1 OR lvl = 1 + SUM (ancestor_ok) ORDER BY r_num ;
On 11 lines from the bottom, I assumed that the maximum depth of any node would be 10. If you do not higher that it should really be, or if you delete that WHEN the clause, then the query still works, it'll just be less effective.
This works for your sample data and some variations I've tried, including the case where a component has many parents. Sorry, I could not test it very carefully. Try it on some of your actual data, and let me know if there are problems.
I'll try to post a more detailed explanation later.
Basically, it works by capturing the results CONNECT BY in subquery h. Each line is identified solely by r_num, giving its place in CONNECT BY results.
In the subquery m, where most of the work takes place, it calculates the a_pos, the r_num of the ancestor of a node at a given level. That value is used in the LAG later function to see if the ancestor was part_type = am' or not. Only the lines where all the ancestors had part_type = am' are included in the final result set.I did have the time to read the messages you and Dev published today. I'll try to do this and get back to you.
Once more remind the people responsible that the Oracle 8.1 was replaced 9 years ago. Whatever they save by not upgrading is offset by what you have to write and maintain much more complicated code, which in turn runs much, much slower than something on a more recent database.
The following works in Oracle 10 and I think it would work in Oracle 9, too:SELECT b.component, b.parent, b.qty_per FROM bom_test b JOIN part_test p ON b.component = p.part_nbr START WITH b.parent = 'ABC-1' CONNECT BY b.parent = PRIOR b.component AND PRIOR p.part_type = 'M' ;
It's 7 lines of code instead of about 65 years it takes to do the same in Oracle 8.1.
-
need help to set up Linksys printserver with verizon wifi hotspot
need help to set up Linksys printserver with verizon wifi hotspot
pfsjmhall,
Configure your wireless router to use these recommended wireless router settings, I use channel 11. I would use a new SSID to connect easier.
Then configure the Linksys print server. Find your network to give your passkey (password)
Then set up the printer, choose network and follow the instructions.
Rick
-
Need help with the port forwarding for a XBox remote Streaming
I have a router R6200v2 and need help with port forwarding.
I came across this set of instructions for setting up stream port forwarding XBox remotely from anywhere
http://kinkeadtech.com/2015/07/how-to-stream-Xbox-one-to-Windows-10-from-anywhere-with-Internet/
I have no idea when it comes to such things and I want to make sure I do it correctly without messing up my existing home network.
Port Forwarding and triggering Port pages setup look very different from what the guy uses. Can someone walk me through what I do to set up please?
Hi @varxtis,
You must enter them in the field for a start external Port and external completion Port. You will need to send individually except for the range of 49000-65000. The steps are as follows.
1. create a Service name (it could be something else that you cannot use the same service name twice. Ex. XBOX1, XBOX2 and so forth.)
2. Select the type of service (TCP, UDP or both)
3 entry 5050 times a start external Port and external endpoints.
4. Select the IP address of your XBOX.
5. Select apply.
6 do the same for other port numbers. To the beach, use 49000 for the external departure Port and for the external completion Port 65000.
Kind regards
Dexter
The community team
Maybe you are looking for
-
Strange keyboard on my Satellite L40 problem
I have laptop Satellite L40 - 17u, and I had it again for about 2 months. My keyboard now seems to do its own thing. I'm going to the settings to correct this. It is ok for a while then goes haywire once again, so leave some letters on the key on boa
-
I would like to create a library for next year again. I worked with an opening through the years and am not sure that is a good idea or not. I would lose all the photos of 2015 if I do this? Can I still access my photos of 2015 should I create a n
-
I replace the HDD with a SSD. This laptop is able to run an SSD, with its limited processor AMD and BIOS? If so, any recommendations? Neil
-
I get these pop ups on an application I have to access it through a company VPN
-
X230t, windows 8, is not able to disable the entry of finger
Hi all! Recently, I bought my X230t, and I'm pretty setisfied with her. With windwos 7, I used the function to turn off the tap of entry, Contol Panel-online pen and finger input.This was really helpful while using the pen to write a lot of things at