Help required in writing the query
I have the following level accounts
10000
11000
11100
11101
11200
11201
12000
12100
12101
12102
12103
20000
21000
21100
21101
22000
22101
21200
21201
I have to take the amount of the child account and sum it to the parent account as below:
11100 = 11101 + 11102 - 11103+.........
11000 = 11100 + 11200 + 11300+.........
10000 = 11000 + 12000 + 13000+.........
21100 = 21101 + 21102 - 21103+.........
21000 = 21100 + 21200 + 21300+.........
20000 = 21000 + 22000 + 23000+.........
Please help...
Thanks in advance.
SQL> with t as (
2 select 10000 ACCOUNT, NULL BEG_BAL, NULL END_BAL from dual union all
3 select 11000,NULL,NULL from dual union all
4 select 11100,NULL,NULL from dual union all
5 select 11101,1750.00,4150.00 from dual union all
6 select 11102,1550.00,3150.00 from dual union all
7 select 11103,1650.00,3200.00 from dual union all
8 select 11200,NULL,NULL from dual union all
9 select 11201,800.00,1250.00 from dual union all
10 select 11202,1550.00,3150.00 from dual union all
11 select 12000,NULL,NULL from dual union all
12 select 12100,NULL,NULL from dual union all
13 select 12101,1200.00,5000.00 from dual union all
14 select 12102,1500.00,3000.00 from dual union all
15 select 12103,1550.00,2750.00 from dual union all
16 select 20000,NULL,NULL from dual union all
17 select 21000,NULL,NULL from dual union all
18 select 21100,NULL,NULL from dual union all
19 select 21101,2000.00,6500.00 from dual union all
20 select 21102,1500.00,3500.00 from dual union all
21 select 21103,1750.00,3550.00 from dual union all
22 select 22000,NULL,NULL from dual union all
23 select 22100,NULL,NULL from dual union all
24 select 22101,1550.00,3550.00 from dual union all
25 select 22102,2550.00,5550.00 from dual union all
26 select 21200,NULL,NULL from dual union all
27 select 21201,2550.00,6500.00 from dual union all
28 select 21202,3550.00,7500.00 from dual
29 )
30 select account,
31 beg_bal,
32 end_bal,
33 sum(beg_bal) over(order by account range between current row and grouping_window follow
ing) group_beg_bal,
34 sum(end_bal) over(order by account range between current row and grouping_window follow
ing) group_end_bal
35 from (
36 select t.*,
37 case
38 when account / 10000 = trunc(account / 10000) then 9999
39 when account / 1000 = trunc(account / 1000) then 999
40 when account / 100 = trunc(account / 100) then 99
41 when account / 10 = trunc(account / 10) then 9
42 else 0
43 end grouping_window
44 from t
45 )
46 order by account
47 /
ACCOUNT BEG_BAL END_BAL GROUP_BEG_BAL GROUP_END_BAL
10000 11550 25650
11000 7300 14900
11100 4950 10500
11101 1750 4150 1750 4150
11102 1550 3150 1550 3150
11103 1650 3200 1650 3200
11200 2350 4400
11201 800 1250 800 1250
11202 1550 3150 1550 3150
12000 4250 10750
12100 4250 10750
ACCOUNT BEG_BAL END_BAL GROUP_BEG_BAL GROUP_END_BAL
12101 1200 5000 1200 5000
12102 1500 3000 1500 3000
12103 1550 2750 1550 2750
20000 15450 36650
21000 11350 27550
21100 5250 13550
21101 2000 6500 2000 6500
21102 1500 3500 1500 3500
21103 1750 3550 1750 3550
21200 6100 14000
21201 2550 6500 2550 6500
ACCOUNT BEG_BAL END_BAL GROUP_BEG_BAL GROUP_END_BAL
21202 3550 7500 3550 7500
22000 4100 9100
22100 4100 9100
22101 1550 3550 1550 3550
22102 2550 5550 2550 5550
27 rows selected.
SQL> SY.
Similar Messages
-
Help required in optimizing the query response time
Hi,
I am working on a application which uses a jdbc thin client. My requirement is to select all the table rows in one table and use the column values to select data in another table in another database.
The first table can have maximum of 6 million rows but the second table rows will be around 9000.
My first query is returning within 30-40 milliseconds when the table is having 200000 rows. But when I am iterating the result set and query the second table the query is taking around 4 millisecond for each query.
the second query selection criteria is to find the value in the range .
for example my_table ( varchar2 column1, varchar2 start_range, varchar2 end_range);
My first query returns a result which then will be used to select using the following query
select column1 from my_table where start_range < my_value and end_range> my_value;
I have created an index on start_range and end_range. this query is taking around 4 millisseconds which I think is too much.
I am using a preparedStatement for the second query loop.
Can some one suggest me how I can improve the query response time?
Regards,
ShyamTry the code below.
Pre-requistee: you should know how to pass ARRAY objects to oracle and receive resultsets from java. There are 1000s of samples available on net.
I have written a sample db code for the same interraction.
Procedure get_list takes a array input from java and returns the record set back to java. You can change the tablenames and the creteria.
Good luck.
DROP TYPE idlist;
CREATE OR REPLACE TYPE idlist AS TABLE OF NUMBER;
CREATE OR REPLACE PACKAGE mypkg1
AS
PROCEDURE get_list (myval_list idlist, orefcur OUT sys_refcursor);
END mypkg1;
CREATE OR REPLACE PACKAGE BODY mypkg1
AS
PROCEDURE get_list (myval_list idlist, orefcur OUT sys_refcursor)
AS
ctr NUMBER;
BEGIN
DBMS_OUTPUT.put_line (myval_list.COUNT);
FOR x IN (SELECT object_name, object_id, myvalue
FROM user_objects a,
(SELECT myval_list (ROWNUM + 1) myvalue
FROM TABLE (myval_list)) b
WHERE a.object_id < b.myvalue)
LOOP
DBMS_OUTPUT.put_line ( x.object_name
|| ' - '
|| x.object_id
|| ' - '
|| x.myvalue
END LOOP;
END;
END mypkg1;
[pre]
Testing the code above. Make sure dbms output is ON.
[pre]
DECLARE
a idlist;
refc sys_refcursor;
c number;
BEGIN
SELECT x.nu
BULK COLLECT INTO a
FROM (SELECT 5000 nu
FROM DUAL) x;
mypkg1.get_list (a, refc);
END;
[pre]
Vishal V. -
Help required in writing a query
hi
Consider a table (ShogenValue) with following data:
Model_Id header_id Serial_no shogen_no si_val
4329 1 40001 A0001 1
4329 1 40001 B0001 2
4329 1 50300 B0001 3
4329 1 40001 C0001 4
4329 1 50300 C0001 5
4329 1 60001 C0001 6
Select
si_val
From
ShogenValue
Where
model_id = 4329
And
header_id = 1
And
serial_no = '60001'
Is it possible to write a modified version of above query which will bring the following result:
Model_Id header_id Serial_no shogen_no si_val
4329 1 40001 A0001 1
4329 1 50300 B0001 3
4329 1 60001 C0001 6
Meaning if a record exists for a particular shogen_no (Shogen_no C0001 has value corrosponding to '60001' in above query), pick it up, if it
does not exist (Shogen_no B0001 does not have value corrosponding to '60001' in above case) then pick a record with one level less serial number ('50300' in above case) and so on.
Thanx
Regards
Omer ImtiazThis should help, although it will probably not perform. Try it and see what the plan for it is.
SELECT
FROM
shogenvalue sv,
(SELECT
max(serial_no) serial_no_max,
shogen_no
FROM
shogenvalue
WHERE
model_id = 4329
AND header_id = 1
AND serial_no <= '60001'
GROUP BY
shogen_no
) svm
WHERE
sv.serial_no = svm.serial_no_max
AND sv.shogen_no = svm.shogen_no
;HTH,
Lennert -
Help required regarding tunning the query mentioned
HI all ,
Query mentioned below takes around 1 hr to complete . It's being used by the autoconfig kindly me in tunning it ..
QUery :
UPDATE WF_ITEM_ATTRIBUTE_VALUES WIAV SET WIAV.TEXT_VALUE = REPLACE(WIAV.TEXT_VALUE,:B1,:B2)
WHERE (WIAV.ITEM_TYPE, WIAV.NAME) = (SELECT WIA.ITEM_TYPE, WIA.NAME
FROM WF_ITEM_ATTRIBUTES WIA WHERE WIA.TYPE = 'URL'
AND WIA.ITEM_TYPE = WIAV.ITEM_TYPE
AND WIA.NAME = WIAV.NAME)
AND WIAV.TEXT_VALUE IS NOT NULL
AND INSTR(WIAV.TEXT_VALUE
, :B1) > 0
Plan :*
<pre>
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | UPDATE STATEMENT | | 453 | 14496 | 284K|
| 1 | UPDATE | WF_ITEM_ATTRIBUTE_VALUES | | | |
|* 2 | FILTER | | | | |
|* 3 | TABLE ACCESS FULL | WF_ITEM_ATTRIBUTE_VALUES | 453 | 14496 | 282K|
|* 4 | TABLE ACCESS BY INDEX ROWID| WF_ITEM_ATTRIBUTES | 1 | 33 | 2 |
|* 5 | INDEX UNIQUE SCAN | WF_ITEM_ATTRIBUTES_PK | 1 | | 1 |
Predicate Information (identified by operation id):
2 - filter(("SYS_ALIAS_2"."ITEM_TYPE","SYS_ALIAS_2"."NAME")= (SELECT /*+ */
"WIA"."ITEM_TYPE","WIA"."NAME" FROM "APPLSYS"."WF_ITEM_ATTRIBUTES" "WIA" WHERE
"WIA"."NAME"=:B1 AND "WIA"."ITEM_TYPE"=:B2 AND "WIA"."TYPE"='URL'))
3 - filter("SYS_ALIAS_2"."TEXT_VALUE" IS NOT NULL AND
INSTR("SYS_ALIAS_2"."TEXT_VALUE",:Z)>0)
4 - filter("WIA"."TYPE"='URL')
5 - access("WIA"."ITEM_TYPE"=:B1 AND "WIA"."NAME"=:B2)
</pre>
Index :*
<pre>
INDEX_NAME COLUMN_NAME
APPLSYS WF_ITEM_ATTRIBUTE_VALUES_PK 1 ITEM_TYPE
2 ITEM_KEY
3 NAME
</pre>
regds
Rahul
Edited by: RahulG on Jan 2, 2009 10:47 PM
Edited by: RahulG on Jan 2, 2009 10:48 PMRahulG wrote:
HI all ,
Query mentioned below takes around 1 hr to complete . It's being used by the autoconfig kindly me in tunning it ..
A few notes:
1. Your query is using bind variables. If you're already on 9i or later (probably 9iR2 according to plan output), this statement will be subject to bind variable peeking and therefore the output of EXPLAIN PLAN is only of limited use, since the actual execution plan might be different and/or might be based on different cardinality estimates based on the actual bind values peeked at hard parse time. You can use the V$SQL_PLAN view to get the actual execution plan(s) if the statement is still cached in the shared pool, from 10g on DBMS_XPLAN.DISPLAY_CURSOR is available for that purpose.
2. The execution plan posted suggests that only 453 rows will correspond to the filter criteria (but, as mentioned in 1. is based on an unknown bind variable value when using EXPLAIN PLAN), and probably therefore the optimizer didn't unnest the subquery but runs this as recursive FILTER query potentially for each row passing the filter criteria on the driving table WF_ITEM_ATTRIBUTE_VALUES. Depending on the actual number of rows this might be inefficient, and unnesting the subquery and turning it into a join might be more appropriate. This might accomplished e.g. by providing more representative statistics to the optimizer (are the statistics up-to-date?).
Although you can't change the SQL you could try this manually by using the UNNEST hint to see if it makes any difference in the execution plan (and run time):
WHERE (WIAV.ITEM_TYPE, WIAV.NAME) = (SELECT /*+ UNNEST */ WIA.ITEM_TYPE, WIA.NAME
...3. The composite index WF_ITEM_ATTRIBUTE_VALUES_PK can only be used on the first column ITEM_TYPE for effective index access, the NAME column would have to be used as filter on all index leaf blocks that would be found using a range scan on ITEM_TYPE. This might be quite inefficient, and/or might lead to a lot of rows/blocks that need to be visited in the table using this index access path.
4. You could try to trace the execution by enabling extended SQL trace, e.g. using the (undocumented) DBMS_SUPPORT package in 9i. Running the "tkprof" utility on the generated trace file tells you the actual row source cardinalities (which can then be compared to the estimates of the optimizer) and - if the "waits" have been enabled - what your statement has waited for most.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
Help needed to optimize the query
Help needed to optimize the query:
The requirement is to select the record with max eff_date from HIST_TBL and that max eff_date should be > = '01-Jan-2007'.
This is having high cost and taking around 15mins to execute.
Can anyone help to fine-tune this??
SELECT c.H_SEC,
c.S_PAID,
c.H_PAID,
table_c.EFF_DATE
FROM MTCH_TBL c
LEFT OUTER JOIN
(SELECT b.SEC_ALIAS,
b.EFF_DATE,
b.INSTANCE
FROM HIST_TBL b
WHERE b.EFF_DATE =
(SELECT MAX (b2.EFF_DATE)
FROM HIST_TBL b2
WHERE b.SEC_ALIAS = b2.SEC_ALIAS
AND b.INSTANCE =
b2.INSTANCE
AND b2.EFF_DATE >= '01-Jan-2007')
OR b.EFF_DATE IS NULL) table_c
ON table_c.SEC_ALIAS=c.H_SEC
AND table_c.INSTANCE = 100;To start with, I would avoid scanning HIST_TBL twice.
Try this
select c.h_sec
, c.s_paid
, c.h_paid
, table_c.eff_date
from mtch_tbl c
left
join (
select sec_alias
, eff_date
, instance
from (
select sec_alias
, eff_date
, instance
, max(eff_date) over(partition by sec_alias, instance) max_eff_date
from hist_tbl b
where eff_date >= to_date('01-jan-2007', 'dd-mon-yyyy')
or eff_date is null
where eff_date = max_eff_date
or eff_date is null
) table_c
on table_c.sec_alias = c.h_sec
and table_c.instance = 100; -
Help me for writing the password script on solaris
hi,
help me for writing password scripts to change the user/root password.
in the script itself myself want to mention the new password.
now user want to login with the new password only.
model script:
echo $test:`perl -e '$x=crypt('$test123','test');
print $x'`::::::: >> /etc/shadow
test--->username
test123---->new password.
the above script is not working.
kindly help me for writing the script.
Regards,
rajaWell. For one thing, if you just append the new password to the /etc/shadow file there will be two entries for the user in that file (at least if the user already had a password). Which probably is a bad thing.
-
Help required in writing an sql to fetch the the difference of the data.
Hi Gurus,
Could some one help me in writing an sql to pull data the difference between two same structured tables from two different database and to store that data in an temperory table.
many many thanks in advanceLets say you have two db SOURCE and DEST
SOURCE is the DB that you have Logged in into. Now you do the following.
1. Createa DBLink to DEST database.
2. Check if the DBLink works properly.
3. Then execute the following sql.
select <column_list> from <table_name>
minus
select <column_list> from <table_name>@<dblink>
union all
select <column_list> from <table_name>@<dblink>
minus
select <column_list> from <table_name> -
Help required in generating the following query
Hi all,
i need solution regarding the following problem.
we got many number of groups ,each group containg many number of names,each name containing some items under that
i had written a query stating that select item where grp =[0%] and name =[1%] from a table
it will execute and dispaly a window with two fields at the first field i entered group and in the second field when i select for existing values it shows all the items of all groups
but we need only items that belong to the group that we enter in the first field
any one tell me the query regarding this requirementHI,
The alternative solution is: develop your add-on, which get the filtering window, and connects the 2 parameters inside, then runs the query and displays it in a matrix/Grid.
It is not takes so many time.
Regards,
J. -
Help needed in writing a Query/Procedure
Hello All,
Need all ur help in writing a query or procedure
Lets say the Table name is DEMO
There i have one column like num it has values
1
2
3
4
5
8
9
10
my query output should be
1-5
8-10
i,e .. if the diff between two rows is greater than 1 then it result should be in a separate group
I need a query/Procedure for this. Kindly help
Regards,
ChandraTried obtaining the output using SQL and the result is as follows:
SQL> WITH T AS
2 (
3 SELECT 1 COL1 FROM DUAL
4 UNION
5 SELECT 2 COL1 FROM DUAL
6 UNION
7 SELECT 3 COL1 FROM DUAL
8 UNION
9 SELECT 4 COL1 FROM DUAL
10 UNION
11 SELECT 5 COL1 FROM DUAL
12 UNION
13 SELECT 8 COL1 FROM DUAL
14 UNION
15 SELECT 9 COL1 FROM DUAL
16 UNION
17 SELECT 10 COL1 FROM DUAL
18 UNION
19 SELECT 13 COL1 FROM DUAL
20 UNION
21 SELECT 14 COL1 FROM DUAL
22 UNION
23 SELECT 15 COL1 FROM DUAL
24 UNION
25 SELECT 16 COL1 FROM DUAL
26 UNION
27 SELECT 23 COL1 FROM DUAL
28 UNION
29 SELECT 24 COL1 FROM DUAL
30 )
31 SELECT OUTPUT FROM
32 (
33 SELECT DECODE(COL3,NULL,COL1, COL2) || '-' || LEAD(DECODE(COL3,NULL,COL3, COL1)) OVER (ORDER BY DECODE(COL3,NULL,COL1, COL2)) OUTPUT FROM
34 (
35 SELECT COL1, LEAD(COL1) OVER (ORDER BY COL1) COL2, LAG(COL1) OVER (ORDER BY COL1) COL3 FROM T
36 )
37 WHERE
38 (COL2 - COL1 > 1 OR COL2 IS NULL OR COL3 IS NULL)
39 )
40 WHERE OUTPUT != '-';
OUTPUT
1-5
8-10
13-16
23-24 -
Help required in refining a query
I have a sql query :
select C1 AS No_Of_Completed_WOs, C2 as Wos_with_Soft_Fail, (C1-C2) as Completed_Wos,C3 as Failed_Wos,C4 as TimedOut_Wos from (select (CASE WHEN TBL_WRK_ORD.EXTSYS_ID IS NULL THEN '<NULL>'
ELSE TBL_WRK_ORD.EXTSYS_ID END),
count(case when WO_STAT=104 AND XACTION_TYPE like '%Completion%' then WO_STAT end ) as C1,
count(case when WO_STAT=104 AND XACTION_TYPE like '%Soft Error%' then WO_STAT end ) AS C2,
count(case when WO_STAT=253 then WO_STAT end ) AS C3,
count(case when WO_STAT=251 then WO_STAT end ) AS C4
from TBL_WRK_ORD,TBL_WO_EVENT_QUEUE WHERE TBL_WRK_ORD.WO_ID=TBL_WO_EVENT_QUEUE.WO_ID group by TBL_WRK_ORD.EXTSYS_ID)
The query basically maintains a separate counter for each of the qualifying condition.
C1 : if the WO_STAT is 104 and XACTION_TYPE is '%Completion%'
C2 : if the WO_STAT is 104 and XACTION_TYPE is '%Soft Error%'
C3 : if the WO_STAT is 253
C4 : if the WO_STAT is 251.
Now, the requirement is that we need to fetch distinct records, based on which the summation will be carried upon.
I was not able to incorporate the "distinct" logic in the above query.
Required help in this regards, as how to fetch distinct records and use it in the summation logic.
A quick help would be appreciated and thankful.
Regards
RAT.
Edited by: user9546298 on Feb 24, 2010 6:36 AM
Edited by: user9546298 on Feb 24, 2010 7:06 AMHere is the sample data :
{code }
Table : TBL_WRK_ORD
WO_ID SCHED_DTS WO_STAT
EXTSYS_ID
A00000001-QRY_ISUP_SERVICE_L 20091126 03:28:02 103
MRK
A00000002-S3 20091201 02:42:34 255
MRK
A00000003-A4 20091201 02:50:28 253
A00000006-ADD1 20091202 05:37:45 104
A00000004-ADD1 20091201 03:40:39 104
A00000005-DNH1 20091202 05:12:06 253
6 rows selected.
Table : TBL_WO_EVENT_QUEUE
WO_ID XACTION_TYPE
A00000001-QRY_ISUP_SERVICE_L WO Accept
A00000001-QRY_ISUP_SERVICE_L WO Startup
A00000001-QRY_ISUP_SERVICE_L WO Completion
A00000002-S3 WO Accept
A00000003-A4 WO Accept
A00000003-A4 WO Startup
A00000003-A4 WO Rollback
A00000003-A4 WO Failure
A00000005-DNH1 WO Rollback
A00000005-DNH1 WO Failure
A00000006-ADD1 WO Accept
A00000006-ADD1 WO Startup
A00000004-ADD1 WO Accept
A00000004-ADD1 WO Startup
A00000004-ADD1 WO Completion
A00000005-DNH1 WO Accept
A00000005-DNH1 WO Startup
A00000006-ADD1 WO Completion
Current output :
NO_OF_COMPLETED_WOS WOS_WITH_SOFT_FAIL COMPLETED_WOS FAILED_WOS TIMEDOUT_WOS
2 0 2 8 0
0 0 0 0 0
Here, as you can see above that the result has duplicates, which caused the counters to show wrong result.
Now, the query should filter based on given criteria and produce the count of the filtered rows.
But doing so, should consider distinct rows for counting.
Also, just placing distinct at counting logic [ pasted by you ] didnot work. I tried it out, but in vain.
Regards
RAT.
Edited by: user9546298 on Feb 24, 2010 7:09 AM -
Help needed to tune the Query:Statistics added
Can someone DBA please help me to tune this query:
SELECT DISTINCT K.ATTRIBUTE_VALUE AGENCY_ID,B.PROFILE_NM ,NVL(G.OFFICE_DESC,'--') OFFICE_DESC,f.OFFICE_ID,B.PROFILE_ID,'%' ROLE,'%' LAYOUT,
CASE
WHEN 'flagB' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING')
WHEN 'flagO' = '%' THEN
NVL(J.ISS_GRP_DESC,'ORDERING')
WHEN 'flag' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
ELSE
NVL(J.ISS_GRP_DESC,' ')
END ISS_GRP_DESC,
DECODE(NVL(H.USERID,' ') ,' ','--','<a sbcuid_in=' || H.USERID || ' target=NEW >'||H.FIRSTNAME || ' ' || H.LASTNAME || '( ' || H.USERID || ' )</a>' ) USER_NAME
FROM
PROFILE_PORTAL B ,
TBL_BDA_AGENCY_RESP_REP C ,
TBL_BDA_AGENCY_OFFICE F,
TBL_BDA_OFFICE G,
USERS_PORTAL H,
TBL_BDA_USR_ISS_GRP I ,
TBL_BDA_ISS_GROUP J,
ATTRIBUTE_VALUES_PORTAL K,
PROFILE_TYPE_PORTAL L
WHERE
B.PROFILE_ID = F.AGENCY_ID (+)
AND B.PROFILE_ID = C.AGENCY_ID (+)
AND G.OFFICE_ID (+)= F.OFFICE_ID
AND H.USERID (+)= C.RESP_USR_ID
AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
AND K.ATTRIBUTE_VALUE IS NOT NULL
AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
AND L.APPLICATION_CD='BDA'
AND NOT EXISTS (SELECT agency_id
FROM TBL_BDA_AGENCY_RESP_REP t
WHERE t.ISS_GRP_ID IN ('%')
AND t.AGENCY_ID = C.AGENCY_ID)
AND K.ATTRIBUTE_VALUE LIKE '%'
AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
AND (to_char(NVL(B.PROFILE_ID,0)) LIKE '%' OR NVL(B.PROFILE_ID,0) IN ('a'))
AND NVL(G.OFFICE_ID,0) IN ('%')
AND (to_char(NVL(C.RESP_USR_ID,'0')) LIKE '%' OR NVL(C.RESP_USR_ID,'0') IN ('k'))
ORDER BY PROFILE_NM
The number of rows in these tables are as follows:
PROFILE_PORTAL -- 2392
TBL_BDA_AGENCY_RESP_REP 3508
TBL_BDA_AGENCY_OFFICE 2151
TBL_BDA_OFFICE 3
USERS_PORTAL 270500
TBL_BDA_USR_ISS_GRP 234
TBL_BDA_ISS_GROUP 2
ATTRIBUTE_VALUES_PORTAL 2790
PROFILE_TYPE_PORTAL 3
The Explain pal nhas given this o/p to me:
SQL> select * from table(dbms_xplan.display) dual;
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost |
| 0 | SELECT STATEMENT | | 807 | 102K| | 2533 |
| 1 | SORT UNIQUE | | 807 | 102K| 232K| 82 |
|* 2 | FILTER | | | | | |
|* 3 | HASH JOIN OUTER | | 807 | 102K| | 52 |
|* 4 | HASH JOIN OUTER | | 807 | 95226 | | 40 |
|* 5 | TABLE ACCESS BY INDEX ROWID | ATTRIBUTE_VALUES | 1 | 23 | | 2 |
| 6 | NESTED LOOPS | | 7 | 805 | | 37 |
| 7 | NESTED LOOPS OUTER | | 6 | 552 | | 25 |
|* 8 | FILTER | | | | | |
| 9 | NESTED LOOPS OUTER | | | | | |
|* 10 | FILTER | | | | | |
| 11 | NESTED LOOPS OUTER | | | | | |
| 12 | NESTED LOOPS OUTER | | 3 | 141 | | 10 |
|* 13 | HASH JOIN | | 3 | 120 | | 7 |
|* 14 | TABLE ACCESS FULL | PROFILE | 6 | 198 | | 4 |
|* 15 | TABLE ACCESS FULL | PROFILE_TYPE | 1 | 7 | | 2 |
|* 16 | INDEX RANGE SCAN | SYS_C0019777 | 1 | 7 | | 1 |
| 17 | TABLE ACCESS BY INDEX ROWID| TBL_BDA_OFFICE | 1 | 10 | | 1 |
|* 18 | INDEX UNIQUE SCAN | SYS_C0019800 | 1 | | | |
| 19 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 2 | 26 | | 2 |
|* 20 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
| 21 | TABLE ACCESS BY INDEX ROWID | USER_ | 1 | 22 | | 1 |
|* 22 | INDEX UNIQUE SCAN | USER_PK | 1 | | | |
|* 23 | INDEX RANGE SCAN | IDX_ATTVAL_ENTATTID | 1 | | | 1 |
| 24 | TABLE ACCESS FULL | TBL_BDA_USR_ISS_GRP | 234 | 702 | | 2 |
| 25 | TABLE ACCESS FULL | TBL_BDA_ISS_GROUP | 2 | 24 | | 2 |
|* 26 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 1 | 7 | | 3 |
|* 27 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
Predicate Information (identified by operation id):
2 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "TBL_BDA_AGENCY_RESP_REP" "T" WHERE "T"."AGENCY_ID"=:B1
AND "T"."ISS_GRP_ID"=TO_NUMBER('%')))
3 - access("I"."ISS_GRP_ID"="J"."ISS_GRP_ID"(+))
4 - access("SYS_ALIAS_1"."ISS_GRP_ID"="I"."ISS_GRP_ID"(+))
5 - filter("K"."ATTRIBUTE_VALUE" IS NOT NULL AND "K"."ATTRIBUTE_VALUE" LIKE '%')
8 - filter(NVL("SYS_ALIAS_1"."RESP_USR_ID",'0') LIKE '%' OR NVL("SYS_ALIAS_1"."RESP_USR_ID",'0')='k')
10 - filter(NVL("G"."OFFICE_ID",0)=TO_NUMBER('%'))
13 - access("L"."PROFILE_TYPE_ID"="B"."PROFILE_TYPE_ID")
14 - filter(UPPER("B"."PROFILE_NM") LIKE '%' AND (TO_CHAR(NVL("B"."PROFILE_ID",0)) LIKE '%' OR
NVL("B"."PROFILE_ID",0)=TO_NUMBER('a')))
15 - filter("L"."APPLICATION_CD"='BDA')
16 - access("B"."PROFILE_ID"="F"."AGENCY_ID"(+))
18 - access("G"."OFFICE_ID"(+)="F"."OFFICE_ID")
20 - access("B"."PROFILE_ID"="SYS_ALIAS_1"."AGENCY_ID"(+))
22 - access("H"."USERID"(+)="SYS_ALIAS_1"."RESP_USR_ID")
23 - access("K"."ENTITY_ID"='PROFILE.'||TO_CHAR("B"."PROFILE_ID"))
26 - filter("T"."ISS_GRP_ID"=TO_NUMBER('%'))
27 - access("T"."AGENCY_ID"=:B1)
Note: cpu costing is off
57 rows selected.
Elapsed: 00:00:01.08
Please help me.
Aashish S.Hello Eric,
Here is the code:
SELECT DISTINCT
K.ATTRIBUTE_VALUE AGENCY_ID,
B.PROFILE_NM ,
NVL(G.OFFICE_DESC,'--') OFFICE_DESC,
f.OFFICE_ID,
B.PROFILE_ID,
'%' ROLE,
'%' LAYOUT,
case
WHEN 'flagB' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING')
WHEN 'flagO' = '%' THEN
NVL(J.ISS_GRP_DESC,'ORDERING')
WHEN 'flag' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
else
NVL(J.ISS_GRP_DESC,' ')
END ISS_GRP_DESC,
DECODE(NVL(H.USERID,' ') ,' ','--','<a sbcuid_in=' || H.USERID || ' target=NEW >'||H.FIRSTNAME || ' ' || H.LASTNAME ||
'( ' || H.USERID || ' )</a>' ) USER_NAME
from
PROFILE_PORTAL B ,
TBL_BDA_AGENCY_RESP_REP C ,
TBL_BDA_AGENCY_OFFICE F,
TBL_BDA_OFFICE G,
USERS_PORTAL H,
TBL_BDA_USR_ISS_GRP I ,
TBL_BDA_ISS_GROUP J,
ATTRIBUTE_VALUES_PORTAL K,
PROFILE_TYPE_PORTAL L
WHERE
B.PROFILE_ID = F.AGENCY_ID (+)
AND B.PROFILE_ID = C.AGENCY_ID (+)
AND G.OFFICE_ID (+)= F.OFFICE_ID
AND H.USERID (+)= C.RESP_USR_ID
AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
AND K.ATTRIBUTE_VALUE IS NOT NULL
AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
AND L.APPLICATION_CD='BDA'
AND NOT EXISTS
(SELECT agency_id
FROM TBL_BDA_AGENCY_RESP_REP t
WHERE t.ISS_GRP_ID IN (1)
AND t.AGENCY_ID = C.AGENCY_ID)
AND K.ATTRIBUTE_VALUE LIKE '%'
AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
AND (to_char(NVL(B.PROFILE_ID,0))
LIKE '%'
OR NVL(B.PROFILE_ID,0) IN (1))
AND NVL(G.OFFICE_ID,0) IN (1)
AND (to_char(NVL(C.RESP_USR_ID,'0'))
LIKE '%'
OR NVL(C.RESP_USR_ID,'0') IN ('%'))
ORDER BY PROFILE_NM
This is the Query and the query takes some mins. to run in prod environment.
From the Query plan ,I am not able to get any idea for optimization.
Now,Can you tell me which steps I need to follow to run it faster and which all modifications should be made?
Thanks.
Aashish S. -
Help required in understanding the flow of control in working with EJB 3.0
*1. Can anyone help me in understanding the flow after getting an object of InitialContext in using Stateless/Stateful in EJB 3.0 from client i.e. what we are getting in the step Object ref=jndiContext.lookup("CalculateBean/Remote) .*
*2. What is the use of INITIAL_CONTEXT_FACTORY*
*3. PROVIDER_URL*
*4. Java.naimg.factory.url.pkgs*
*5. why org.jboss.naming and org.jnp.interfaces separated by semi colon.*
*6. Why we dont require INITIAL_CONTEXT_FACTORY, PROVIDER_URL and Java.naming.factory.url.pkgs if the client is a web client.*
Properties p=new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
p.put(Context.PROVIDER_URL,"jnp://localhost:1099");
p.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
Context jndiContext = new InitialContext(p);
Object ref = jndiContext.lookup("CalculateBean/Remote");
Calculate c = (Calculate)ref;
int sum=c.add(3,4);
System.out.println(sum);
Thanx in advance........Annotations can also be processed at run time using the core reflection API (java.lang.Class & java.lang.reflect.*), so you might want to explore down that path. I have no idea how JBoss actually does it, but annotation processing at build time and core reflection at runtime are the two most obvious possibilities.
Bruce -
Need Help in tuning of the query
Hi all,
Can any body help me how we can rewrite this query in
optimized way.
SELECT A.C1 AS COLUMN_1, B.C2 AS COLUMN_2
FROM A,B
WHERE A.C1 IN (
SELECT COLUMN_1 FROM(
(SELECT A.C1 AS COLUMN_1,
COUNT(C1) AS COUNT,
RANK() OVER (ORDER BY COUNT(C1) DESC) AS RANK
FROM A, B, C
WHERE A.C1 = B.C3
AND B.C2 = C.C1
AND <other conditions>
GROUP BY A.C1)
WHERE RANK <= 10)
AND A.C1 = B.C3
AND <other conditions>
ORDER BY A.C1
I am using <other conditions> are same in outer query and inner query also.
Thanks in Advance,Hi,
Yes exactly I am looking TOP-10 results the query is like this
SELECT A.C1 AS COLUMN_1, B.C2 AS COLUMN_2
FROM A,B
WHERE B.C2 IN (
SELECT COLUMN_1 FROM(
(SELECT B.C2 AS COLUMN_1,
COUNT(A.C1) AS COUNT,
RANK() OVER (ORDER BY COUNT(C1) DESC) AS RANK
FROM A, B, C
WHERE A.C1 = B.C3
AND B.C2 = C.C1
AND <other conditions>
GROUP BY B.C2)
WHERE RANK <= 10)
AND A.C1 = B.C3
AND <other conditions>
ORDER BY B.C2
Thanks -
Help needed in generating the query
Hi All,
While fetching the required columns from the table, i also have to display the seq no starting with some no. ( which will vary based on the functionality, so it ll be a sep variable.) and will get incremented with a offset value.
Current code:
select col1, col2, col3 from table1 where col1 = valid_condition; Expected code / Or approach:
select start_val+offset_val , col1, col2, col3 from table1 where col1 = valid_condition; This select query is part of a view and the values for start_val, offset_val will be set as global params.
Is there any easier way of implementing this in the query, other than creating a seq no.
thanks in advance.Hi,
This sounds like a job for ROWNUM or ROW_NUMBER.
The ROWNUM pseudo-column is easy to use, but the numbers aren't necessarily assigned in the order you'd like:
SELECT ename
, 1000 + ROWNUM AS seq_no
FROM scott.emp
WHERE deptno = 30
ORDER BY ename
;Output:
ENAME SEQ_NO
ALLEN 1001
BLAKE 1004
JAMES 1006
MARTIN 1003
TURNER 1005
WARD 1002To assign the numbers in order, you could select ROWNUM from an ordered sub-query (or view), but if you're going to that much trouble, you might as well use the analytic ROW_NUMBER function:
SELECT ename
, 1000 + ROW_NUMBER () OVER (ORDER BY ename) AS seq_no
FROM scott.emp
WHERE deptno = 30
ORDER BY ename
;Output:
ENAME SEQ_NO
ALLEN 1001
BLAKE 1002
JAMES 1003
MARTIN 1004
TURNER 1005
WARD 1006Edited by: Frank Kulash on Nov 25, 2009 1:32 PM -
Urgent Help required in Tunning this query
I have table ACCOUNT SPONSOR HOMESTORE ASH with more than 30 million rows.
My batch daily need to update or insert into this table from a temporary table TEMP_HSTRALCT. The data for temporary table is populated by below query which selects from two tables TRANSACTION POINTS and REDEMPTIONS.However both these tables are partitioned on date time and is run daily and this is running for hours.
Can anyone please help me on tuning this query
INSERT INTO temp_hstralct
(tmp_n_collector_account_num, tmp_v_location_id,
tmp_v_sponsor_id, tmp_v_source_file_name,
tmp_n_psc_insert_ind, tmp_n_psc_update_ind,
tmp_n_transaction_amount, tmp_n_transaction_points,
tmp_n_acc_insert_ind, tmp_n_ash_insert_ind,
tmp_n_col_insert_ind, tmp_n_check_digit,
tmp_n_collector_issue_num, tmp_n_csl_insert_ind,
tmp_v_offer_code, tmp_n_psa_insert_ind)
SELECT DISTINCT trp_n_collector_account_num account_num,
trp_v_location_id location_id,
trp_v_sponsor_id sponsor_id,
trp_c_creation_user batch_id, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0
FROM transaction_points, ACCOUNT, locations_master,homestores
WHERE hsr_v_accrual_allowed = 'Y'
AND trp_n_collector_account_num = ACCOUNT.acc_n_account_num(+)
AND ( ( ( ACCOUNT.acc_v_account_type = 'C'
OR ACCOUNT.acc_v_account_type IS NULL
AND hsr_v_b2c_accounts = 'Y'
OR ( ACCOUNT.acc_v_account_type = 'B'
AND hsr_v_nfb_accounts = 'Y'
OR ( ACCOUNT.acc_v_account_type = 'H'
AND hsr_v_hybrid_accounts = 'Y'
AND trp_d_creation_date_time BETWEEN SYSDATE-3
AND SYSDATE
AND trp_v_sponsor_id = 'JSAINSBURY'
AND trp_v_location_id =
locations_master.lnm_v_location_id
AND locations_master.lnm_v_partner_id = 'JSAINSBURY'
AND ( ( ( (INSTR
(hsr_v_store_status,
locations_master.lnm_c_location_status
) > 0
AND (INSTR
(hsr_v_store_type,
locations_master.lnm_c_location_type
) > 0
AND hsr_v_homestore_assignment = 'ST'
OR ( ( locations_master.lnm_c_homestore_ind =
'Y'
AND (INSTR
(hsr_v_store_status,
locations_master.lnm_c_location_status
) > 0
AND hsr_v_homestore_assignment = 'HS'
UNION ALL
SELECT DISTINCT rdm_n_collector_account_num account_num,
rdm_v_location_id location_id,
rom_v_supplier_id sponsor_id,
rdm_c_creation_user batch_id, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0
FROM redemption_details,
reward_offer_master,
ACCOUNT,
locations_master,
HOMESTORES
WHERE hsr_v_redemption_allowed = 'Y'
AND rdm_n_collector_account_num = ACCOUNT.acc_n_account_num(+)
AND ( ( ( ACCOUNT.acc_v_account_type = 'C'
OR ACCOUNT.acc_v_account_type IS NULL
AND hsr_v_b2c_accounts = 'Y'
OR ( ACCOUNT.acc_v_account_type = 'B'
AND hsr_v_nfb_accounts = 'Y'
OR ( ACCOUNT.acc_v_account_type = 'H'
AND hsr_v_hybrid_accounts = 'Y'
AND rdm_d_creation_date_time BETWEEN SYSDATE-3
AND SYSDATE
AND rom_v_reward_offer_id = rdm_v_reward_id
AND rom_v_supplier_id = 'JSAINSBURY'
AND rdm_v_location_id =
locations_master.lnm_v_location_id
AND locations_master.lnm_v_partner_id ='JSAINSBURY'
AND ( ( ( (INSTR
(hsr_v_store_status,
locations_master.lnm_c_location_status
) > 0
AND (INSTR
(hsr_v_store_type,
locations_master.lnm_c_location_type
) > 0
AND hsr_v_homestore_assignment = 'ST'
OR ( ( locations_master.lnm_c_homestore_ind =
'Y'
AND (INSTR
(hsr_v_store_status,
locations_master.lnm_c_location_status
) > 0
AND hsr_v_homestore_assignment = 'HS'
);I have copied the explain as it is and can you please try pasting in the text pad.Can you let me know whether parallel hint on this will speed up the select queries.
Plan
INSERT STATEMENT CHOOSECost: 410,815 Bytes: 2,798,394 Cardinality: 15,395
32 UNION-ALL
15 SORT UNIQUE Cost: 177,626 Bytes: 2,105,592 Cardinality: 11,896
14 FILTER
13 HASH JOIN Cost: 177,312 Bytes: 2,105,592 Cardinality: 11,896
2 TABLE ACCESS BY INDEX ROWID LMHOLTP.LOCATIONS_MASTER Cost: 37 Bytes: 23,184 Cardinality: 966
1 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_LOCATIONS_MASTER_3 Cost: 3 Cardinality: 1
12 FILTER
11 HASH JOIN OUTER
8 MERGE JOIN CARTESIAN Cost: 155,948 Bytes: 702,656,660 Cardinality: 4,845,908
3 TABLE ACCESS FULL LMHOLTP.HOMESTORES Cost: 2 Bytes: 104 Cardinality: 1
7 BUFFER SORT Cost: 155,946 Bytes: 198,682,228 Cardinality: 4,845,908
6 PARTITION RANGE ITERATOR Partition #: 12
5 TABLE ACCESS BY LOCAL INDEX ROWID LMHOLTP.TRANSACTION_POINTS Cost: 155,946 Bytes: 198,682,228 Cardinality: 4,845,908 Partition #: 12
4 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_TRANSACTION_POINTS_1 Cost: 24,880 Cardinality: 6,978,108 Partition #: 12
10 PARTITION RANGE ALL Partition #: 15 Partitions accessed #1 - #5
9 TABLE ACCESS FULL LMHOLTP.ACCOUNT Cost: 6,928 Bytes: 68,495,680 Cardinality: 8,561,960 Partition #: 15 Partitions accessed #1 - #5
31 SORT UNIQUE Cost: 233,189 Bytes: 692,802 Cardinality: 3,499
30 FILTER
29 FILTER
28 NESTED LOOPS OUTER
24 HASH JOIN Cost: 226,088 Bytes: 664,810 Cardinality: 3,499
16 TABLE ACCESS FULL LMHOLTP.REWARD_OFFER_MASTER Cost: 8 Bytes: 2,280 Cardinality: 114
23 HASH JOIN Cost: 226,079 Bytes: 8,327,280 Cardinality: 48,984
20 TABLE ACCESS BY INDEX ROWID LMHOLTP.LOCATIONS_MASTER Cost: 37 Bytes: 432 Cardinality: 18
19 NESTED LOOPS Cost: 39 Bytes: 2,304 Cardinality: 18
17 TABLE ACCESS FULL LMHOLTP.HOMESTORES Cost: 2 Bytes: 104 Cardinality: 1
18 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_LOCATIONS_MASTER_3 Cost: 3 Cardinality: 966
22 PARTITION RANGE ITERATOR Partition #: 28
21 TABLE ACCESS FULL LMHOLTP.REDEMPTION_DETAILS Cost: 226,019 Bytes: 261,636,270 Cardinality: 6,229,435 Partition #: 28
27 PARTITION RANGE ITERATOR Partition #: 30
26 TABLE ACCESS BY LOCAL INDEX ROWID LMHOLTP.ACCOUNT Cost: 2 Bytes: 8 Cardinality: 1 Partition #: 30
25 INDEX UNIQUE SCAN UNIQUE LMHOLTP.CO_PK_ACCOUNT Cost: 1 Cardinality: 1 Partition #: 30
Maybe you are looking for
-
Adobe 9.2 on Win 7 - shrinks pdf printout to half page size
I am running Adobe Reader 9.2 on Windows 7. The printer is a Xerox Work Center C2424 and is a networked printer- we print through our server, which is running Windows Server 2003 R2. When I try and print any PDF, it prints pages of such a size that t
-
MapLoader 121 - only 1 country at a time?
Since I got a 4gb card I thought I would download more map data for my n95 last night. I selected Belgium, NL, Fr and UK. Whichever way I did it MapLoader didn't seem able to download more than 1 country. Whenever it got to the second it would report
-
I am trying to make a transaction variant for transaction ea20. EA20 is an ISU-CCS transaction which reverses bills. Normally when I create a transaction variant - I go to SHD0 - enter the transaction, give a name of the transaction variant - and cli
-
I have a packing list that I'm trying to convert to excel. When I convert only the top portion, which is the address will convert or the items will be weird letters and symbols. How can I convert so that I can work with the data?
-
Migration failure to new MacBook Pro
have tried using Migration Assistant to transfer content from old MacBook pro to a new 13 inch i5. Seems to go smoothly via Firewire cable and get completion message with all transferred successfully etc. But I get no content for iPhoto, iCal, Addres