SQL Query : Order By issue with HUGE Table
Hello friends,
I have been through a terrible issue with order by. I would appreciate your help. Please let me know, your input for my case:
=> if i run select query it returns result quick in some milliseconds. (sql dev. fetches 50 rows at a time)
=> if i run select query with where condition and column (say A) in where condition is even indexed and i have order by and that order by column (say B) is also indexed.
Now, here is the issue:
1. if no. of rows with that where condition can filter yielding small result set then order by works fine .. 1-5 sec which is good.
2.*if no. of rows with that where condition can filter yielding Large result set, say more than 50,000 then with order by then the wait time is exponential.... i have even waited 10+ mins to get the result back for 120,000 records.*
Is order by takes that long for 100K records ... i think something else if wrong... your pointer will really be helpful... i am very new to sql and even newer for large table case.
I am using SQL Developer Version 2.1.1.64
and Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
Thank you so much.
Edited by: 896719 on Jan 11, 2013 8:38 AM
Yes you are correct, but my concentration was on order by thing, so it will do full scan of table so i was putting that ... and was also wondering if millions of record in table should not be a issue...???
Any way for the explain plan , when just a value in the where changes there is the huge difference i want to point out too as below:
SELECT
FROM
EES_EVT EES_EVT where APLC_EVT_CD= 'ABC' ORDER BY CRE_DTTM DESC
execution time : 0.047 sec
Plan hash value: 290548126
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 27 | 14688 | 25 (4)| 00:00:01 |
| 1 | SORT ORDER BY | | 27 | 14688 | 25 (4)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| EES_EVT | 27 | 14688 | 24 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | XIE1EES_EVT | 27 | | 4 (0)| 00:00:01 |
Predicate Information (identified by operation id):
3 - access("APLC_EVT_CD"='ABC')
Note
- SQL plan baseline "SYS_SQL_PLAN_6d41e6b91925c463" used for this statement
=============================================================================================
SELECT
FROM
EES_EVT EES_EVT where APLC_EVT_CD= 'XYZ' ORDER BY CRE_DTTM DESC
execution : 898.672 sec.
Plan hash value: 290548126
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 121K| 62M| | 102K (1)| 00:11:02 |
| 1 | SORT ORDER BY | | 121K| 62M| 72M| 102K (1)| 00:11:02 |
| 2 | TABLE ACCESS BY INDEX ROWID| EES_EVT | 121K| 62M| | 88028 (1)| 00:09:27 |
|* 3 | INDEX RANGE SCAN | XIE1EES_EVT | 121K| | | 689 (1)| 00:00:05 |
Predicate Information (identified by operation id):
3 - access("APLC_EVT_CD"='XYZ')
Note
- SQL plan baseline "SYS_SQL_PLAN_ef5709641925c463" used for this statementAlso Note this table contains 74328 MB data in it.
Thanks
Similar Messages
-
Hello Gurus..... ISSUE with child Table update
I have an issue with child table update
I have created a GTC with one parent table and two child tables. I'm able to update the parent table and the values are found in db, but the ISSUE is the child Table values are not updating the db.
please give me a solution
regards
SrikanthIf you are keeping referential integrity in the database, not in the application, it is easy to find the child and parent tables. Here is a quick and dirty query. You can join this to dba_cons_columns to find out on which columns the referential constraints are defined. This lists all child-parent table including SYS and SYSTEM users. You can run this for specific users of course.
select cons1.owner child_owner,cons1.table_name child_table,
cons2.owner parent_owner,cons2.table_name parent_table
from dba_constraints cons1,dba_constraints cons2
where cons1.constraint_type='R'
and cons1.r_constraint_name=cons2.constraint_name; -
How to Use SQL Query having IN Clause With DB Adapter
Hi,
I am using 11.1.1.5 want to find out how to Use SQL Query having IN Clause With DB Adapter. I want to pass the IN values dynamically. Any ideas.
Thanksinvoke a stored procedure, it's safer than trying to put together an arbitrary SQL statement in the JCA adapter
-
How to create sql query for item master with operator LIKE with variables?
hi all,
How to create sql query for item master with
operator LIKE(Contains,Start With,End With) with variables using query generator in SAP B1 ?
JeyakanthanHi Jeyakanthan,
here is an example (put the like statement into the where field)
SELECT T0.CardCode, T0.CardName FROM OITM T0 WHERE T0.CardName Like '%%test%%'
The %% sign is a wildcard. If you need start with write 'test%%' and otherwise ends with '%%test'. For contains you need '%%test%%'. You also could combinate this statements like 'test%%abc%%'. This means starts with test and contains abc.
Regards Steffen -
Issues with Advance Table Add Row New Row not work in some scenarios.
Hi,
Wondering if there's any issue with Advanced Tables where it does not create any rows. I don't know if anyone tried this or not. I have one OA Page with Advanced Table and a button that when clicked open a new OA Page in a POP-UP Window. The pop-up page conatins one textbox where u enter a data and this gets saved in one of the VO's transient attribute. Now on the ase page if you don't click a button to open a pop-up page you can Add New Rows in the Advanced Table by clicking Add Row Button. But as soon as you open a popup window and close it Add New Rows button doesn't work and is not creating any new rows. Basically page stops working. Both the POP-UP and the base page share the same AM but have different controllers.
POP-UP page is a custom page that I open giving the Destination URI value in the button item and target frame _blank.
I even tried creating rows programmatically for Advance Table but this too doesn't work once u open a pop-up. Also I have used pageContext.putTransactionValue in the pop-up page and am checking and removing this in the base page.
Any help is appreciated.
Thanksanyone
-
Performance issues with pipelined table functions
I am testing pipelined table functions to be able to re-use the <font face="courier">base_query</font> function. Contrary to my understanding, the <font face="courier">with_pipeline</font> procedure runs 6 time slower than the legacy <font face="courier">no_pipeline</font> procedure. Am I missing something? The <font face="courier">processor</font> function is from [url http://www.oracle-developer.net/display.php?id=429]improving performance with pipelined table functions .
Edit: The underlying query returns 500,000 rows in about 3 minutes. So there are are no performance issues with the query itself.
Many thanks in advance.
CREATE OR REPLACE PACKAGE pipeline_example
IS
TYPE resultset_typ IS REF CURSOR;
TYPE row_typ IS RECORD (colC VARCHAR2(200), colD VARCHAR2(200), colE VARCHAR2(200));
TYPE table_typ IS TABLE OF row_typ;
FUNCTION base_query (argA IN VARCHAR2, argB IN VARCHAR2)
RETURN resultset_typ;
c_default_limit CONSTANT PLS_INTEGER := 100;
FUNCTION processor (
p_source_data IN resultset_typ,
p_limit_size IN PLS_INTEGER DEFAULT c_default_limit)
RETURN table_typ
PIPELINED
PARALLEL_ENABLE(PARTITION p_source_data BY ANY);
PROCEDURE with_pipeline (argA IN VARCHAR2,
argB IN VARCHAR2,
o_resultset OUT resultset_typ);
PROCEDURE no_pipeline (argA IN VARCHAR2,
argB IN VARCHAR2,
o_resultset OUT resultset_typ);
END pipeline_example;
CREATE OR REPLACE PACKAGE BODY pipeline_example
IS
FUNCTION base_query (argA IN VARCHAR2, argB IN VARCHAR2)
RETURN resultset_typ
IS
o_resultset resultset_typ;
BEGIN
OPEN o_resultset FOR
SELECT colC, colD, colE
FROM some_table
WHERE colA = ArgA AND colB = argB;
RETURN o_resultset;
END base_query;
FUNCTION processor (
p_source_data IN resultset_typ,
p_limit_size IN PLS_INTEGER DEFAULT c_default_limit)
RETURN table_typ
PIPELINED
PARALLEL_ENABLE(PARTITION p_source_data BY ANY)
IS
aa_source_data table_typ;-- := table_typ ();
BEGIN
LOOP
FETCH p_source_data
BULK COLLECT INTO aa_source_data
LIMIT p_limit_size;
EXIT WHEN aa_source_data.COUNT = 0;
/* Process the batch of (p_limit_size) records... */
FOR i IN 1 .. aa_source_data.COUNT
LOOP
PIPE ROW (aa_source_data (i));
END LOOP;
END LOOP;
CLOSE p_source_data;
RETURN;
END processor;
PROCEDURE with_pipeline (argA IN VARCHAR2,
argB IN VARCHAR2,
o_resultset OUT resultset_typ)
IS
BEGIN
OPEN o_resultset FOR
SELECT /*+ PARALLEL(t, 5) */ colC,
SUM (CASE WHEN colD > colE AND colE != '0' THEN colD / ColE END)de,
SUM (CASE WHEN colE > colD AND colD != '0' THEN colE / ColD END)ed,
SUM (CASE WHEN colD = colE AND colD != '0' THEN '1' END) de_one,
SUM (CASE WHEN colD = '0' OR colE = '0' THEN '0' END) de_zero
FROM TABLE (processor (base_query (argA, argB),100)) t
GROUP BY colC
ORDER BY colC
END with_pipeline;
PROCEDURE no_pipeline (argA IN VARCHAR2,
argB IN VARCHAR2,
o_resultset OUT resultset_typ)
IS
BEGIN
OPEN o_resultset FOR
SELECT colC,
SUM (CASE WHEN colD > colE AND colE != '0' THEN colD / ColE END)de,
SUM (CASE WHEN colE > colD AND colD != '0' THEN colE / ColD END)ed,
SUM (CASE WHEN colD = colE AND colD != '0' THEN 1 END) de_one,
SUM (CASE WHEN colD = '0' OR colE = '0' THEN '0' END) de_zero
FROM (SELECT colC, colD, colE
FROM some_table
WHERE colA = ArgA AND colB = argB)
GROUP BY colC
ORDER BY colC;
END no_pipeline;
END pipeline_example;
ALTER PACKAGE pipeline_example COMPILE;Edited by: Earthlink on Nov 14, 2010 9:47 AM
Edited by: Earthlink on Nov 14, 2010 11:31 AM
Edited by: Earthlink on Nov 14, 2010 11:32 AM
Edited by: Earthlink on Nov 20, 2010 12:04 PM
Edited by: Earthlink on Nov 20, 2010 12:54 PMEarthlink wrote:
Contrary to my understanding, the <font face="courier">with_pipeline</font> procedure runs 6 time slower than the legacy <font face="courier">no_pipeline</font> procedure. Am I missing something? Well, we're missing a lot here.
Like:
- a database version
- how did you test
- what data do you have, how is it distributed, indexed
and so on.
If you want to find out what's going on then use a TRACE with wait events.
All nessecary steps are explained in these threads:
HOW TO: Post a SQL statement tuning request - template posting
http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
Another nice one is RUNSTATS:
http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551378329289980701 -
Inserting field text into sql query and comparing values to another table
I have an issue in Visual Web Developer 2010 that I need help with.
The code below is a Gridview Sql query where I'm extracting PART_NUMBER from various tables. I would like to add the table name in a separate field named Table. The end result should appear as follows:
PART_NUMBER Table
010-0075-06 Resistors (or Capacitors, etc.)
Sql query:
SELECT PART_NUMBER
FROM Capacitors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Connectors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Diodes
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM ICs
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Inductors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Misc
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Relays
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Resistors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Switches
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Transformers
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Transistors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM [Crystals and Oscillators]
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
ORDER BY PART_NUMBER
I have a separate table (CIS Manufacturer Parts) that contains manufacturer data for the above parts. Multiple manufacturer rows can exist. The connection between tables in the PART_NUMBER field. What I would like to do is make this query
add the table name to the gridview output listing only parts without manufacturer data and the table they can be found in.
This is a lot for a newbie so I will appreciate any help, thanks!Hello Bulldog248,
Thank you for your post.
Your issue is out of support range of VS General Question forum which mainly discusses the usage issue of Visual Studio IDE such as
WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
and Visual Studio Editor.
I am moving your question to the moderator forum ("Where is the forum for..?"). The owner of the forum will direct you to a right forum.
Best regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Issue with Multiple Tables in Report
Post Author: dwessell
CA Forum: General
Hi,
I'm using Crystal Reports 2k8.
I'm doing a report with three tables, CQ_HEADER, SO_HEADER and SALESPERSON. Both the CQ_HEADER and the SO_HEADER tables link to the SALESPERSON table via a SPN_AUTO_KEY field.
However, I always receive duplicates in my result set, due to the joins made, and I don't receive results that are valid in one table, and empty in another (Such that it only counts a CQ, if there is a SO associated with it. Here's the query that's produced by CR.
SELECT "CQ_HEADER"."CQ_NUMBER", "CQ_HEADER"."ENTRY_DATE", "CQ_HEADER"."TOTAL_PRICE", "SALESPERSON"."SALESPERSON_NAME", "SO_HEADER"."ENTRY_DATE", "SO_HEADER"."TOTAL_PRICE"
FROM "CQ_HEADER" "CQ_HEADER" INNER JOIN ("SO_HEADER" "SO_HEADER" INNER JOIN "SALESPERSON" "SALESPERSON" ON "SO_HEADER"."SPN_AUTO_KEY"="SALESPERSON"."SPN_AUTO_KEY") ON "CQ_HEADER"."SPN_AUTO_KEY"="SALESPERSON"."SPN_AUTO_KEY"
WHERE ("CQ_HEADER"."ENTRY_DATE">={ts '2007-12-01 00:00:00'} AND "CQ_HEADER"."ENTRY_DATE"<{ts '2007-12-18 00:00:00'}) AND ("SO_HEADER"."ENTRY_DATE">={ts '2007-12-01 00:00:00'} AND "SO_HEADER"."ENTRY_DATE"<{ts '2007-12-18 00:00:00'})
ORDER BY "SALESPERSON"."SALESPERSON_NAME"
There is no link between the SO_HEADER and the CQ_HEADER. Can anyone make a suggestion as to how I could go about structuring this such that it doesn't return duplicate values?
Thanks
DavidHey,
I understand you used Retainsameconnection property true for all the OLEDB connections you used in the package if not make sure its for all the connection including file connection as well.
Additionally, you can try to set Delayvalidation property to true for all the dataflows and control flows in the connection and try running the package for 10MB file.
I hope this will fix the intermittent failure issue you are facing with SSIS.
(Please mark solved if I've answered your question, vote for it as helpful to help other user's find a solution quicker)
Thanks,
Atul Gaikwad. -
ADF Issue with Tree Table , Child Row not getting rendered.
Hi All,
I am trying to show a single Level Master-Detail Table via ADF Tree Table.
I have MasterVO : InventoryVO (1 SubInventoryCode)
DetailVO: SubInventoryVO (n :SubInventoryCode)
Both VOs are SQL query based VO with bindVariables.
I have a viewLink between MasterVO and ChildVO (1:n relationship)
I dragged and drop the MasterVO as a tree Table. I added the Rule in the Tree Binding too.
I have the Tree table under a Tab , I execute the AM impl method when the Tab is clicked where I set the bindvariables of the MasterVO and ChildVO and execute it.
when I run the Page , the VO query gets executed but the I am able to see only the MasterVO Datas, and when I click MasterVO ROW , the Table doesnt expand and it doesnt render any ChildVO ROws.
Please find the Page Definition and Jspx Page Code Below
Page Definition Code
<tree IterBinding="ItemsLocatorIterator" id="ItemsLocator">
<nodeDefinition DefName="xxplp.oracle.adf.items.model.view.ItemsLocatorVO"
Name="ItemsLocator0">
<AttrNames>
<Item Value="SubinventoryCode"/>
<Item Value="Openorderqty"/>
<Item Value="Openwoqty"/>
<Item Value="Qoh"/>
</AttrNames>
<Accessors>
<Item Value="ItemSubInventoryVO"/>
</Accessors>
</nodeDefinition>
<nodeDefinition DefName="xxplp.oracle.adf.items.model.view.ItemSubInventoryVO"
Name="ItemsLocator1">
<AttrNames>
<Item Value="Locator"/>
</AttrNames>
</nodeDefinition>
</tree>Jspx Page Code
<af:treeTable value="#{bindings.ItemsLocator.treeModel}"
var="node"
selectionListener="#{bindings.ItemsLocator.treeModel.makeCurrent}"
rowSelection="single" id="tt2"
styleClass="AFStretchWidth"
rowDisclosureListener="#{backingBeanScope.TabListenerBean.LocationTableRowDisclosureListener}">
<f:facet name="nodeStamp">
<af:column id="c110">
<af:outputText value="#{node.SubinventoryCode}" id="ot116"/>
</af:column>
</f:facet>
<f:facet name="pathStamp">
<af:outputText value="#{node}" id="ot117"/>
</f:facet>
<af:column id="c111"
headerText="#{bindings.ItemsLocator.hints.Qoh.label}">
<af:outputText value="#{node.Qoh}" id="ot118"/>
</af:column>
<af:column id="column1"
headerText="#{bindings.ItemsLocator.hints.Openorderqty.label}">
<af:outputText value="#{node.Openorderqty}"
id="outputText1"/>
</af:column>
<af:column id="column2"
headerText="#{bindings.ItemsLocator.hints.Openwoqty.label}">
<af:outputText value="#{node.Openwoqty}"
id="outputText2"/>
</af:column>
<af:column id="column3"
headerText="Locator">
<af:outputText value="#{node.Locator}"
id="outputText3"/>
</af:column>
</af:treeTable>I was able to find the issue which is causing the problem, both the VOs are SQL Query Based VOs.
The ChildVO (SubInventoryVO) is has a bindvariable in its Query, which is losing its value when the viewlink accessor query gets appended to it.
Please find the query below
SELECT * FROM (SELECT MOTV.ORGANIZATION_CODE, MOTV.SUBINVENTORY_CODE
FROM MTL_ONHAND_TOTAL_V MOTV
WHERE INVENTORY_ITEM_ID = :P_INVENTORY_ITEM_ID) QRSLT WHERE ORGANIZATION_CODE = :Bind_OrganizationCode Though I am setting the VO query before the Table is rendered, ":P_INVENTORY_ITEM_ID".
Its Losing its value, when the above whereclause "ORGANIZATION_CODE = :Bind_OrganizationCode " gets appended to it.
I am thinking to use ExecuteWithParams Operation on SelectionListener method of the Tree Table to set the ":P_INVENTORY_ITEM_ID" bind variable, but I also want the viewLinkAccessor rule also to be applied ..
Please suggest me how to retain the implicit bindVariable of the Query. -
Form on a SQL Query - doesn't work with SELECT * - bug or feature ?
When I do this,
Create Page -> Page with Component -> Form -> Form on a SQL Query -> SELECT * FROM EMP
I do not get any items displayed and it creates a simple HTML region / page. Do we have to necessarily specify the column names ?
Iam looking at a way to see if any addition of columns in the table does not involve IT intervention in recreating the form.
When we try to create with Form on a SQL Query, then shouldn't it be similar to the Report where the same thing works, if I give SELECT function_returning_columns() from DUAL even then the same thing happens where it creates an ITEM called functions_returning_columns() it creates HTML region
I asked a related question with no answer :-( in
Dynamic Creation of Items in Runtime through Application UIHi Marc,
Thanks. I just tried something like this. Taking the EMP table example, (it doesn't matter which table), I created a region based on a Pl/Sql function returning SQL query
( I selected the vertical report template including nulls to display it like a form ) :
DECLARE
v_sql VARCHAR2(3000) ;
mn_idx NUMBER := 1 ;
BEGIN
v_sql := 'SELECT ' ;
FOR recs IN (SELECT * FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = 'EMP' ORDER BY COLUMN_ID)
LOOP
v_sql := v_sql || 'HTMLDB_ITEM.TEXT(' || mn_idx || ',' ||
recs.column_name || ') ' || recs.column_name || ', ' ;
mn_idx := mn_idx + 1 ;
END LOOP ;
v_sql := SUBSTR(v_sql, 1, LENGTH(v_sql) -2) ;
v_sql := v_sql || ' FROM EMP WHERE EMPNO = 7369 ORDER BY 1 ' ;
RETURN v_sql ;
END ;
This allowed me to do my updates etc.., Then I created a button called 'Apply' and a process called 'update_changes' on button click and defined this:
DECLARE
v_sql varchar2(1000) ;
mn_ctr NUMBER := 1 ;
BEGIN
v_sql := 'BEGIN UPDATE EMP SET ' ;
FOR recs IN (select COLUMN_ID, COLUMN_NAME, DATA_TYPE
from all_tab_columns where table_name = 'EMP'
ORDER BY COLUMN_ID) loop
-- Make changes here if required- this is assuming 9 columns --
v_sql := v_sql || recs.column_name || ' = HTMLDB_APPLICATION.G_F0' || mn_ctr || '(1),' ;
mn_ctr := mn_ctr + 1;
end loop ;
v_sql := substr(v_sql, 1, length(v_sql) - 1) ;
v_sql := v_sql || ' WHERE EMPNO = 7369; END ;' ;
execute immediate (v_sql) ;
END ;
Since this is for example, I didn't include code for Checksum and hardcoded empno = condition and have provision for 9 columns. I made some changes and tried saving it and I was able to do it.
I altered the table to add a column / drop a column and when I relogin, Iam able to see the changes.
Can you tell me if there could be any drawbacks in this approach ?. -
SQL Query Having performance issues
I need help on rewriting this query, I am having performance issues with the way it is now. I create a temporary table and query against it. Any help will be appreciated. Thanks, Antonio
Here it is:
create global temporary table pr_php_elig_tmp
on commit preserve rows as
SELECT UNIQUE A.SAK_PROV, A.CDE_SERVICE_LOC, a.sak_short
FROM T_PR_PHP_ELIG A,
T_PR_TYPE C
WHERE C.SAK_PROV = A.SAK_PROV
AND C.CDE_SERVICE_LOC = A.CDE_SERVICE_LOC
AND C.CDE_PROV_TYPE not in ('01', '03', '08', '24', '27', '31')
AND A.SAK_PROV_PGM not in (11, 13)
AND A.DTE_END >= :il_current_date
AND A.DTE_EFFECTIVE <= :il_prev_18_months
AND NOT EXISTS (
SELECT 'X'
FROM T_PR_GRP_MBR T
WHERE T.SAK_PROV = A.SAK_PROV
AND T.CDE_SVC_LOC_MBR = A.CDE_SERVICE_LOC)
AND NOT EXISTS (
select a.sak_prov, a.cde_service_loc
from t_pmp_svc_loc d
where a.sak_prov = d.sak_prov
and a.cde_service_loc = d.cde_service_loc
and d.dte_end >= :il_current_date)
ORDER BY A.SAK_PROV, A.CDE_SERVICE_LOC;
select * from pr_php_elig_tmp
minus
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_dntl_dtl temp01
WHERE temp01.sak_prov_perf = a.sak_prov
and temp01.cde_svc_loc_perf = a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp01.DTE_FIRST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp01.DTE_FIRST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_dntl_hdr temp02
WHERE ( (temp02.prov_billing = a.sak_prov
and temp02.cde_service_loc = a.cde_service_loc)
OR (temp02.sak_prov_perf = a.sak_prov
and temp02.cde_perf_svc_loc = a.cde_service_loc)
OR (temp02.sak_prov_referring = a.sak_prov
and temp02.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp02.sak_prov_referring_2 = a.sak_prov
and temp02.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp02.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp02.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_phrm_hdr temp03
WHERE ( (temp03.prov_billing = a.sak_prov and
temp03.cde_service_loc = a.cde_service_loc)
OR (temp03.sak_prov_rendering = a.sak_prov and
temp03.cde_svc_loc_rend = a.cde_service_loc)
OR (temp03.sak_presc_prov = a.sak_prov and
temp03.cde_svc_loc_presc = a.cde_service_loc)
OR temp03.id_prov_prescrb = to_char(a.sak_prov) || a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp03.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp03.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_phys_dtl temp04
WHERE ( (temp04.sak_prov_perf = a.sak_prov
and temp04.cde_svc_loc_rend = a.cde_service_loc)
OR (temp04.sak_prov_referring = a.sak_prov
and temp04.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp04.sak_prov_referring_2 = a.sak_prov
and temp04.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp04.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp04.DTE_LAST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_phys_hdr temp05
WHERE ( (temp05.prov_billing = a.sak_prov
and temp05.cde_service_loc = a.cde_service_loc)
OR (temp05.sak_prov_perf = a.sak_prov
and temp05.cde_perf_svc_loc = a.cde_service_loc)
OR (temp05.sak_prov_referring = a.sak_prov
and temp05.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp05.sak_prov_referring_2 = a.sak_prov
and temp05.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp05.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp05.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_ub92_dtl temp06
WHERE ( (temp06.sak_pr_other = a.sak_prov
and temp06.cde_scv_loc_other = a.cde_service_loc)
OR (temp06.sak_pr_other_2 = a.sak_prov
and temp06.cde_svc_loc_other_2 = a.cde_service_loc)
OR (temp06.sak_pr_attend = a.sak_prov
and temp06.cde_svc_loc_attend = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp06.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp06.DTE_LAST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_ub92_hdr temp07
WHERE ( (temp07.prov_billing = a.sak_prov
and temp07.cde_service_loc = a.cde_service_loc)
OR (temp07.sak_pr_facility = a.sak_prov
and temp07.cde_svc_loc_fa = a.cde_service_loc)
OR (temp07.sak_pr_other = a.sak_prov
and temp07.cde_svc_loc_other = a.cde_service_loc)
OR (temp07.sak_pr_other_2 = a.sak_prov
and temp07.cde_svc_loc_other_2 = a.cde_service_loc)
OR (temp07.sak_pr_attend = a.sak_prov
and temp07.cde_svc_loc_attend = a.cde_service_loc)
OR temp07.id_prov_attend = to_char(a.sak_prov) || a.cde_service_loc
OR temp07.id_prov_other = to_char(a.sak_prov) || a.cde_service_loc
OR temp07.id_prov_other_2 = to_char(a.sak_prov) || a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp07.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp07.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_dntl_dtl temp08
WHERE temp08.sak_prov_perf = a.sak_prov
and temp08.cde_svc_loc_perf = a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp08.DTE_FIRST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp08.DTE_FIRST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_dntl_hdr temp09
WHERE ( (temp09.prov_billing = a.sak_prov
and temp09.cde_service_loc = a.cde_service_loc)
OR (temp09.sak_prov_perf = a.sak_prov
and temp09.cde_perf_svc_loc = a.cde_service_loc)
OR (temp09.sak_prov_referring = a.sak_prov
and temp09.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp09.sak_prov_referring_2 = a.sak_prov
and temp09.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp09.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp09.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_pharm_hdr temp10
WHERE ( (temp10.prov_billing = a.sak_prov
and temp10.cde_service_loc = a.cde_service_loc)
OR (temp10.sak_prov_rend = a.sak_prov
and temp10.cde_svc_loc_rend = a.cde_service_loc)
OR (temp10.sak_presc_prov = a.sak_prov
and temp10.cde_svc_loc_presc = a.cde_service_loc)
OR temp10.id_prov_prescrb = to_char(a.sak_prov) || a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp10.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp10.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_phys_dtl temp11
WHERE ( (temp11.sak_prov_perf = a.sak_prov
and temp11.cde_svc_loc_rend = a.cde_service_loc)
OR (temp11.sak_prov_referring = a.sak_prov
and temp11.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp11.sak_prov_referring_2 = a.sak_prov
and temp11.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp11.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp11.DTE_LAST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_phys_hdr temp12
WHERE ( (temp12.prov_billing = a.sak_prov
and temp12.cde_service_loc = a.cde_service_loc)
OR (temp12.sak_prov_perf = a.sak_prov
and temp12.cde_perf_svc_loc = a.cde_service_loc)
OR (temp12.sak_prov_referring = a.sak_prov
and temp12.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp12.sak_prov_referring_2 = a.sak_prov
and temp12.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp12.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp12.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_ub92_dtl temp13
WHERE ( (temp13.sak_pr_other = a.sak_prov
and temp13.cde_scv_loc_other = a.cde_service_loc)
OR (temp13.sak_pr_other_2 = a.sak_prov
and temp13.cde_svc_loc_other_2 = a.cde_service_loc)
OR (temp13.sak_pr_attend = a.sak_prov
and temp13.cde_svc_loc_attend = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp13.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp13.DTE_LAST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_ub92_hdr temp14
WHERE ( (temp14.prov_billing = a.sak_prov
and temp14.cde_service_loc = a.cde_service_loc)
OR (temp14.sak_pr_facility = a.sak_prov
and temp14.cde_svc_loc_fa = a.cde_service_loc)
OR (temp14.sak_pr_other_2 = a.sak_prov
and temp14.cde_svc_loc_other_2 = a.cde_service_loc)
OR (temp14.sak_pr_attend = a.sak_prov
and temp14.cde_svc_loc_attend = a.cde_service_loc)
OR (temp14.sak_pr_other = a.sak_prov
and temp14.cde_svc_loc_other = a.cde_service_loc)
OR temp14.id_prov_attend = to_char(a.sak_prov) || a.cde_service_loc
OR temp14.id_prov_other = to_char(a.sak_prov) || a.cde_service_loc
OR temp14.id_prov_other_2 = to_char(a.sak_prov) || a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp14.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp14.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_dental_dtl temp15
WHERE temp15.sak_prov_perf = a.sak_prov
and temp15.cde_svc_loc_perf = a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp15.DTE_FIRST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp15.DTE_FIRST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_dental_hdr temp16
WHERE ( (temp16.sak_prov_perf = a.sak_prov
and temp16.cde_perf_svc_loc = a.cde_service_loc)
OR (temp16.sak_prov_referring = a.sak_prov
and temp16.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp16.sak_prov_referring_2 = a.sak_prov
and temp16.cde_svc_loc_ref_2 = a.cde_service_loc)
OR (temp16.prov_billing = a.sak_prov
and temp16.cde_service_loc = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING ((MAX(temp16.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp16.DTE_LAST_SVC),0) = 0)
and (MAX(temp16.DTE_BILLED) >= :il_prev_18_months
OR NVL(MAX(temp16.DTE_BILLED),0) = 0) )
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_phrm_hdr temp17
WHERE ( (temp17.prov_billing = a.sak_prov
and temp17.cde_service_loc = a.cde_service_loc)
OR (temp17.sak_prov_rend = a.sak_prov
and temp17.cde_svc_loc_rend = a.cde_service_loc)
OR (temp17.sak_presc_prov = a.sak_prov
and temp17.cde_svc_loc_presc = a.cde_service_loc)
OR temp17.id_prov_prescrb = to_char(a.sak_prov) || a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp17.DTE_BILLED) >= :il_prev_18_months
OR NVL(MAX(temp17.DTE_BILLED),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_phys_dtl temp18
WHERE ( (temp18.sak_prov_perf = a.sak_prov
and temp18.cde_svc_loc_rend = a.cde_service_loc)
OR (temp18.sak_prov_referring = a.sak_prov
and temp18.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp18.sak_prov_referring_2 = a.sak_prov
and temp18.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp18.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp18.DTE_LAST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_phys_hdr temp19
WHERE ( (temp19.prov_billing = a.sak_prov
and temp19.cde_service_loc = a.cde_service_loc)
OR (temp19.sak_prov_perf = a.sak_prov
and temp19.cde_perf_svc_loc = a.cde_service_loc)
OR (temp19.sak_prov_referring = a.sak_prov
and temp19.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp19.sak_prov_referring_2 = a.sak_prov
and temp19.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING ((MAX(temp19.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp19.DTE_LAST_SVC),0) = 0)
and (MAX(temp19.DTE_BILLED) >= :il_prev_18_months
OR NVL(MAX(temp19.DTE_BILLED),0) = 0) )
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_ub92_dtl temp20
WHERE ( (temp20.sak_pr_other = a.sak_prov
and temp20.cde_scv_loc_other = a.cde_service_loc)
OR (temp20.sak_pr_other_2 = a.sak_prov
and temp20.cde_svc_loc_other_2 = a.cde_service_loc)
OR (temp20.sak_pr_attend = a.sak_prov
and temp20.cde_svc_loc_attend = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp20.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp20.DTE_LAST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_ub92_hdr temp22
WHERE ( (temp22.prov_billing = a.sak_prov
and temp22.cde_service_loc = a.cde_service_loc)
OR (temp22.sak_pr_facility = a.sak_prov
and temp22.cde_svc_loc_fa = a.cde_service_loc)
OR (temp22.sak_pr_other_2 = a.sak_prov
and temp22.cde_svc_loc_other_2 = a.cde_service_loc)
OR (temp22.sak_pr_attend = a.sak_prov
and temp22.cde_svc_loc_attend = a.cde_service_loc)
OR (temp22.sak_pr_other = a.sak_prov
and temp22.cde_svc_loc_other = a.cde_service_loc)
OR temp22.id_prov_attend = to_char(a.sak_prov) || a.cde_service_loc
OR temp22.id_prov_other = to_char(a.sak_prov) || a.cde_service_loc
OR temp22.id_prov_other_2 = to_char(a.sak_prov) || a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp22.DTE_BILLED) >= :il_prev_18_months
OR NVL(MAX(temp22.DTE_BILLED),0) = 0
);Perhaps an approach like this would work better. No promises, but it's worth a try.
SELECT *
FROM pr_php_elig_tmp a
WHERE NOT EXISTS (
SELECT a.sak_prov,
a.cde_service_loc,
a.sak_short
FROM aim01.t_deny_dntl_dtl temp01
WHERE temp01.sak_prov_perf = a.sak_prov
AND temp01.cde_svc_loc_perf = a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX (temp01.dte_first_svc) >= :il_prev_18_months
OR NVL (MAX (temp01.dte_first_svc), 0) = 0)
AND NOT EXISTS (
SELECT a.sak_prov,
a.cde_service_loc,
a.sak_short
FROM aim01.t_deny_dntl_hdr temp02
WHERE ( ( temp02.prov_billing = a.sak_prov
AND temp02.cde_service_loc = a.cde_service_loc)
OR ( temp02.sak_prov_perf = a.sak_prov
AND temp02.cde_perf_svc_loc = a.cde_service_loc)
OR ( temp02.sak_prov_referring = a.sak_prov
AND temp02.cde_svc_loc_ref_1 = a.cde_service_loc)
OR ( temp02.sak_prov_referring_2 = a.sak_prov
AND temp02.cde_svc_loc_ref_2 = a.cde_service_loc))
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX (temp02.dte_final) >= :il_prev_18_months
OR NVL (MAX (temp02.dte_final), 0) = 0) -
Insert performance issue with Partitioned Table.....
Hi All,
I have a performance issue during with a table which is partitioned. without table being partitioned
it ran in less time but after partition it took more than double.
1) The table was created initially without any partition and the below insert took only 27 minuts.
Total Rec Inserted :- 2424233
PL/SQL procedure successfully completed.
Elapsed: 00:27:35.20
2) Now I re-created the table with partition(range yearly - below) and the same insert took 59 minuts.
Is there anyway i can achive the better performance during insert on this partitioned table?
[ similerly, I have another table with 50 Million records and the insert took 10 hrs without partition.
with partitioning the table, it took 18 hours... ]
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 4195045590
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 643K| 34M| | 12917 (3)| 00:02:36 |
|* 1 | HASH JOIN | | 643K| 34M| 2112K| 12917 (3)| 00:02:36 |
| 2 | VIEW | index$_join$_001 | 69534 | 1290K| | 529 (3)| 00:00:07 |
|* 3 | HASH JOIN | | | | | | |
| 4 | INDEX FAST FULL SCAN| PK_ACCOUNT_MASTER_BASE | 69534 | 1290K| | 181 (3)| 00:00
| 5 | INDEX FAST FULL SCAN| ACCOUNT_MASTER_BASE_IDX2 | 69534 | 1290K| | 474 (2)| 00:00
PLAN_TABLE_OUTPUT
| 6 | TABLE ACCESS FULL | TB_SISADMIN_BALANCE | 2424K| 87M| | 6413 (4)| 00:01:17 |
Predicate Information (identified by operation id):
1 - access("A"."VENDOR_ACCT_NBR"=SUBSTR("B"."ACCOUNT_NO",1,8) AND
"A"."VENDOR_CD"="B"."COMPANY_NO")
3 - access(ROWID=ROWID)
Open C1;
Loop
Fetch C1 Bulk Collect Into C_Rectype Limit 10000;
Forall I In 1..C_Rectype.Count
Insert test
col1,col2,col3)
Values
val1, val2,val3);
V_Rec := V_Rec + Nvl(C_Rectype.Count,0);
Commit;
Exit When C_Rectype.Count = 0;
C_Rectype.delete;
End Loop;
End;
Total Rec Inserted :- 2424233
PL/SQL procedure successfully completed.
Elapsed: 00:51:01.22
Edited by: user520824 on Jul 16, 2010 9:16 AMI'm concerned about the view in step 2 and the index join in step 3. A composite index with both columns might eliminate the index join and result in fewer read operations.
If you know which partition the data is going into beforehand you can save a little bit of processing by specifying the partition (which may not be a scalable long-term solution) in the insert - I'm not 100% sure you can do this on inserts but I know you can on selects.
The APPEND hint won't help the way you are using it - the VALUES clause in an insert makes it be ignored. Where it is effective and should help you is if you can do the insert in one query - insert into/select from. If you are using the loop to avoid filling up undo/rollback you can use a bulk collect to batch the selects and commit accordingly - but don't commit more often than you have to because more frequent commits slow transactions down.
I don't think there is a nologging hint :)
So, try something like
insert /*+ hints */ into ...
Select
A.Ing_Acct_Nbr, currency_Symbol,
Balance_Date, Company_No,
Substr(Account_No,1,8) Account_No,
Substr(Account_No,9,1) Typ_Cd ,
Substr(Account_No,10,1) Chk_Cd,
Td_Balance, Sd_Balance,
Sysdate, 'Sisadmin'
From Ideaal_Cons.Tb_Account_Master_Base A,
Ideaal_Staging.Tb_Sisadmin_Balance B
Where A.Vendor_Acct_Nbr = Substr(B.Account_No,1,8)
And A.Vendor_Cd = b.company_no
;Edited by: riedelme on Jul 16, 2010 7:42 AM -
Performance issue with MSEG table
Hi all,
I need to fetch materials(MATNR) based on the service order number (AUFNR) in the selection screen,but there is performance isssue with this , how to over come this issue .
Regards ,
AmitHi,
There could be various reasons for performance issue with MSEG.
1) database statistics of tables and indexes are not upto date.
because of this wrong index is choosen during the execution.
2) Improper indexes, because there is no indexes with the fields mentioned in the WHERE clause of the statement. Because of this reason, CBO would have choosen wrong index and did a range scan.
3) Optimizer bug in oracle.
4) Size of table is very huge, archive.
Better switch on ST05 trace before you run this statements, so it will give more detailed information, where exactly time being spent during the execution.
Hope this helps
dileep -
SQL query to retrieve families with only one generation from a family db
Hi,
I need to write an SQL query that would select families with only one generation ((which means a person - or a married couple - with kids) or (a person - or a married couple - with parents but no kids)) from a database containing families. The simplified db structure is:
person:
id - int, primary key
siblings:
id
parent_id
kid_id
marriage
id:
husband_id
wife_id
Could anyone please help me? I dont really have any idea how to accomplish that...Hi,
Welcome to the forum!
Assuming that siblings (despite its name) contains only parent-child relationships, and that the parent_id could be either the mother or the father:
WITH got_tree AS
SELECT CONNECT_BY_ROOT s.parent_id AS root_id
, LEVEL AS lvl
FROM siblings s
LEFT OUTER JOIN marriage m ON s.parent_id IN ( m.husband_id
, m.wife_id
START WITH parent_id NOT IN ( SELECT kid_id
FROM siblings
CONNECT BY s.parent_id IN ( PRIOR m.husband_id
, PRIOR m.wife_id
, PRIOR kid_id
SELECT root_id
FROM got_tree
GROUP BY root_id
HAVING MAX (lvl) <= 2
;This will get a list of parents who may or may not have children, but who do not have either parents or grandchildren.
To get their spouses and children (if any) you will have to join this result set to all the other tables. At that point, you can eliminate poeple who do not have ancestors themselves, but are married to people who have more than one generation of ancestors.
The details of how to do that depend on the details of your tables. If you'd like help, then post a little sample data (CREATE TABLE and INSERT statements for all tables) and the results you want from that data.
Edited by: Frank Kulash on Oct 14, 2009 4:05 PM
I'd need sample data in order to test this, of course. -
Need help in SQL Query: Update a row in a table & insert the same row into another table
I want to update a row in a table say Table A and the updated row should be inserted into another table say Table B. I need to do it in a single SQL query and i don't want to do it in PL/SQL with triggers. And i tried with MERGE statement but its working with this scenario. (Note: I'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0).
Thanks in Advance.Using Sven's code as an example, you could save the updated row in a sql plus variable. (also untested):
SQL> var v_id number
update tableA
set colB='ABC'
where colC='XYZ'
returning id into :v_id;
insert into table A_History (ID, colA, colB, ColC)
select id, ColA, ColB, ColC
from tableA
where id = :v_id;
Maybe you are looking for
-
I use windows desktop at home and want to use Apple laptop on the go. What do I have to do to be able to use both platforms when my account is for Win.? I am thinking of converting my home computer to Apple as well in the near future. Thanks Messa
-
SSRS Log shows Reporting web server started, was it closed before?
Hi there: During the weekend, one of our sql jobs that calls a RSS script to create a SSRS PDF report failed The job error says " Could not connect to server: http://XXXXXXXXX/ReportServer/ReportService2005.asmx " The command inside
-
Heterogeneous system copy. Error in SMIGR_CREATE_DDL
Hello! I perform a heterogeneous system copy of RHEL5/Oracle11/ERP6/0 > RHEL6/MaxDB/ERP6.0 I use the "System Copy Guide for SAP Systems Based on NW 7.0 SR3 ABAP + Java". At the stage "4.2 Generating DDL" statements is a problem. I'm doing "Call trans
-
How to install LookAndFeel downloaded into JVM??
I've downloaded a couple of nice L&F's ( i wonder if sun has a download part of lookandfeel-s?? ive searched but found nothing :(( ) and want to install it. What should i do for that? Thank you very much!! Boris.
-
I have a powerbook 5300cs with just a floppy drive in it. The guy i got it from deleted everything off it but the os. It has mac os 7.5 rev 3 on it. How can i put diskcopy back on it. I have no cd drive for it or internet for it too. Is there a progr