Rewrite the query
HelloI have a standard report oracle question which i've drawn from the data model
is it possible to rewrite this query without the bind variable, also the data provided as output is appropriate even when rewritten
WHT does & C_vendor_dynamic_SQL stand
SELECT /*+ ORDERED_PREDICATES */ DISTINCT (v.vendor_id) C_vendor_id,
v.vendor_name C_vendor_name,
DECODE(:SORT_BY_ALTERNATE, 'Y', UPPER(v.vendor_name_alt),
UPPER(v.vendor_name)) C_sort_vendor_name,
v.segment1 C_vendor_num
FROM ap_invoices i, po_vendors v
WHERE 0 < (SELECT SUM(nvl(prepay_amount_remaining,amount))
FROM ap_invoice_distributions aid
WHERE aid.invoice_id = i.invoice_id
AND aid.line_type_lookup_code IN ('ITEM','TAX')
AND nvl(aid.reversal_flag,'N') <> 'Y')
AND v.vendor_id = i.vendor_id
AND i.invoice_type_lookup_code = 'PREPAYMENT'
AND i.cancelled_date IS NULL
&C_vendor_dynamic_SQL
ORDER BY DECODE(:SORT_BY_ALTERNATE, 'Y', UPPER(v.vendor_name_alt), UPPER(v.vendor_name))
thanking in advancePublished by: makdutakdu on June 21, 2010 10:54
I guess then this fine shud work, so was that, in the cud of user earlier request, give then here with the two bind and lexical values ignored the user cannot enter, but even of output?
Yes, the output will be the same.
The user can always have enter the values if you have not deleted the user settings, but even if the user enters the values the report output will be same each time.
Tags: Oracle Development
Similar Questions
-
How can rewrite the query statement effectively
Hi gurus,
BANNER
----------------------------------------------------------------
Oracle Database 10g Release 10.2.0.4.0 - Production 64-bit
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
AMT for Linux: release 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
Table scripts
CREATE TABLE WAREHOUSE
(
IDZONE VARCHAR2 (6 BYTE) NOT NULL,
ZONE_CREATEDATE DATE NOT NULL,
DATE OF DT_WAREHOUSE,
DATE OF DT_POSTING
)
AREA ID, ZONE_CREATEDATE is PK
CREATE TABLE ZONE_VIEW
(
IDZONE VARCHAR2 (6 BYTE) NOT NULL,
ZONE_CREATEDATE DATE NOT NULL,
ZONE_NUM NUMBER (2) NOT NULL,
DATE OF TRANX_DATE
)
ID of the AREA, ZONE_CREATEDATE, ZONE_NUM is PK
Query
SELECT ID area, zone_createdate
Of
(
SELECT ID area, zone_createdate,
MAX (CASE WHEN zone_num = 18 AND tranx_date 'n' IS NOT NULL, THEN 1 TIME zone_num = 18 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_18,.
MAX (CASE WHEN zone_num = 110 AND not IS NOT NULL, THEN 1 TIME = 110 zone_num tranx_date AND tranx_date IS NULL THEN 0 ELSE-1 END) region_110,.
MAX (CASE WHEN zone_num = 135 AND tranx_date no IS NOT NULL, THEN 1 TIMES zone_num = 135 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_135,.
MAX (CASE WHEN zone_num = 140 AND tranx_date 'n' IS NOT NULL, THEN 1 TIME zone_num = 140 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_140
OF zone_view
GROUP BY IDZone, zone_createdate
) zrn
WHERE zrn.region_18 <>0
AND (((zrn.region_110 = 1) OR (zrn.region_110 = - 1)) AND (there IS NOT (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_warehouse IS NULL)))
AND (((zrn.region_135 = 1) AND (there IS NOT (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_posting IS NULL))) OR (zrn.region_140 = 1))
OR ((zrn.region_18 >-1) AND (zrn.region_135 = - 1) AND (zrn.region_140 < 1))
OR ((zrn.region_110 = 1) AND (zrn.region_135 = - 1) AND (zrn.region_140, <>, 0))
);
Top query runs too slowly on the real data set. Is there an effective way to rewrite the query which can perform the dough?
Any help or suggestion would be appreciated
Thanks in advance
At the time where the application may not throw anything until after he has retrieved and grouped all the ranks of zone_view. His estimate of 7.5 minutes to scan millions 639 lines really fast enough - it's 85 million lines per minute.
This seems to be where the time went. The only way that the query can be accelerated is to recover some of the conditions that must be applied before the grouping. The only obvious possibilities for this are
(a) filter values of zone_num
(b) move the audit only
NOT EXISTS (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_warehouse IS NULL)
within the group, because this condition is applied regardless of the values in calculated fields. The AREA ID, ZONE_CREATEDATE are not null, so I suggest to try:
SELECT ID area, zone_createdate
Of
(
SELECT ID area, zone_createdate,
MAX (CASE WHEN zone_num = 18 AND tranx_date 'n' IS NOT NULL, THEN 1 TIME zone_num = 18 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_18,.
MAX (CASE WHEN zone_num = 110 AND not IS NOT NULL, THEN 1 TIME = 110 zone_num tranx_date AND tranx_date IS NULL THEN 0 ELSE-1 END) region_110,.
MAX (CASE WHEN zone_num = 135 AND tranx_date no IS NOT NULL, THEN 1 TIMES zone_num = 135 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_135,.
MAX (CASE WHEN zone_num = 140 AND tranx_date 'n' IS NOT NULL, THEN 1 TIME zone_num = 140 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_140
OF zone_view
where (IDZone, zone_createdate) NOT IN (select the zone ID, w warehouse zone_createdate WHERE w.dt_warehouse IS NULL)
and zone_num (18, 110, 135, 140)
GROUP BY IDZone, zone_createdate
) zrn
WHERE zrn.region_18 <> 0
AND ((zrn.region_110 = 1) OR (zrn.region_110 = - 1))
AND (((zrn.region_135 = 1) AND (there IS NOT (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_posting IS NULL))) OR (zrn.region_140 = 1))
OR ((zrn.region_18 >-1) AND (zrn.region_135 = - 1) AND (zrn.region_140)<>
OR ((zrn.region_110 = 1) AND (zrn.region_135 = - 1) AND (zrn.region_140 <> 0))
)
Unfortunately, if the plan of the query time estimates are correct, most of the duration of the query is spent doing a reading zone_view in a full analysis, and which will not be changed by this query.
If there are many rows for each (IDZone, zone_createdate) zone_view pair, then it is possible that an index on (area ID, zone_num, zone_createdate) would contribute to this request, especially if most (IDZone, zone_createdate) pairs are filtered with the NOT IN (select the zone ID, zone_createdate w warehouse WHERE w.dt_warehouse IS NULL). More radical but probably effective measure would be a functional on index
zone_view (zone_num, IDZone, zone_createdate, case when tranx_date is null then 0 otherwise 1 end)
and using the expression in the query box:
SELECT ID area, zone_createdate
Of
(
SELECT ID area, zone_createdate,
NVL (MAX (CASE WHEN zone_num = 18 then case when tranx_date is null, then 0 or 1 end end),-1) region_18,.
NVL (MAX (CASE WHEN zone_num = 110 then case when tranx_date is null, then 0 or 1 end end),-1) region_110,.
NVL (MAX (CASE WHEN zone_num = 135 then case when tranx_date is null, then 0 or 1 end end),-1) region_135,.
NVL (MAX (CASE WHEN zone_num = 140 then case when tranx_date is null, then 0 or 1 end end),-1) region_140
OF zone_view
where (IDZone, zone_createdate) NOT IN (select the zone ID, w warehouse zone_createdate WHERE w.dt_warehouse IS NULL)
and zone_num (18, 110, 135, 140)
GROUP BY IDZone, zone_createdate
) zrn
WHERE zrn.region_18 <> 0
AND ((zrn.region_110 = 1) OR (zrn.region_110 = - 1))
AND (((zrn.region_135 = 1) AND (there IS NOT (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_posting IS NULL))) OR (zrn.region_140 = 1))
OR ((zrn.region_18 >-1) AND (zrn.region_135 = - 1) AND (zrn.region_140)<>
OR ((zrn.region_110 = 1) AND (zrn.region_135 = - 1) AND (zrn.region_140 <> 0))
)
This gives a very different plan on my database, by performing an iteration on relevant areas of performance status:
---------------------------------------------------------
| ID | Operation | Name |
---------------------------------------------------------
| 0 | SELECT STATEMENT | |
|* 1 | FILTER | |
| 2. VIEW | |
|* 3 | FILTER | |
| 4. HASH GROUP BY. |
| 5. ANTI NESTED LOOPS. |
| 6. INLIST ITERATOR. |
|* 7 | INDEX RANGE SCAN | ZV_F1 |
|* 8 | TABLE ACCESS BY INDEX ROWID | WAREHOUSE |
|* 9 | INDEX UNIQUE SCAN | WAREHOUSE_PK |
| * 10 | TABLE ACCESS BY INDEX ROWID | WAREHOUSE |
| * 11 | INDEX UNIQUE SCAN | WAREHOUSE_PK |
---------------------------------------------------------
Your plan will be different because you have data volumes (I didn't create millions of lines of test data)
It would be useful to know how many rows there are in the WAREHOUSE, how many distinct (IDZone, zone_createdate) pairs there are in zone_view and the number of rows actually returns the query, and how much is NOT IN (select the zone ID, w zone_createdate warehouse WHERE w.dt_warehouse IS NULL) because these relative numbers determine how these approaches are.
If there is a table containing all of the (area ID, zone_createdate) pairs which could take place in zone_view, which would have may another possible approach:
First filter possible pairs against NOT IN (select the zone ID, w warehouse zone_createdate WHERE w.dt_warehouse IS NULL)
Then attach them to the zone_view to retrieve only the rows in the filtered (IDZone, zone_createdate) pairs.
Good luck.
-
Rewrite the query, select below or try to get the necessary O/P
Hello..
My example of data.,.
Create table customer (name varchar2 (10), telephone1 telephone2 number (10), number of phone3 (10), (10) number, bitwisephone number (10));
Insert into customer values('a',23456,67890,null,12345);
Insert into customer values ('b', 67459,89760,null, 37689);
create table do_not_call (dont_call number (10));
insert into do_not_call values (67890);
insert into do_not_call values (37689);
Question: -.
--------------
Customer 'a' has value of numbers1 as 23456.check if telephone1 exists in the do_not_call table.
In fact there is no, so set the bit for numbers1 as "o" like wise search telephone2
& phone3.after update of the bitwisephone for each client should be as the output below.
Need to O/P: -.
-------------------
name bitwisephone
a 010
b 001
For that matter... I use "any" operator...
SELECT name, case when numbers1 = all (SELECT dont_call FROM do_not_call) and then put an end to '1' other '0'.
-case when telephone2 = all (SELECT dont_call FROM do_not_call) and then put an end to '1' other '0'.
-case when phone3 = all (SELECT dont_call FROM do_not_call) then '1' other '0' end 'Bits '.
OF THE customer;
Is there any other way to get the necessary O/P?
Thank you!!
Kind regards
VijayRajaram.Looks like one already answered Re: rewrite the query, select below or try to get the necessary O/P
with customer(name,phone1,phone2,phone3,bitwisephone) as (select 'a',23456,67890,12345,null from dual union all select 'b',67459,89760,37689,null from dual ), do_not_call(dont_call) as (select 67890 from dual union all select 23456 from dual union all select 37689 from dual ) select name, to_char(mod(trunc(sum(weight)/4),2))|| to_char(mod(trunc(sum(weight)/2),2))|| to_char(mod(sum(weight),2)) bitwisephone from (select name,phone1 phone,4 weight from customer union all select name,phone2,2 from customer union all select name,phone3,1 from customer ) c, do_not_call d where c.phone = d.dont_call(+) and d.dont_call is not null group by name
Please do not duplicate messages
Concerning
Etbin
-
Rewrite the query with joins, and group by
Hello
It's an interview question.
Table names: bookshelf_checkout
virtual library
And the join condition between these two tables is title
We need to rewrite under request without using the join condition and group by clause?
When I was in College, I read most of SELECT statements can be replaced by operations base SQL (DEFINE the OPERATORS). Now, I am rewriting the query with SET operators, but not able to get the exact result.SELECT b.title,max(bc.returned_date - bc.checkout_date) "Most Days Out" FROM bookshelf_checkout bc,bookshelf b WHERE bc.title(+)=b.title GROUP BY b.title;
Kindly help me on this.
Thank you
SuriSomething like that?
1 WITH books AS ( 2 SELECT 'title 1' title FROM dual UNION ALL 3 SELECT 'title 2' FROM dual UNION ALL 4 SELECT 'title 3' FROM dual ), 5 bookshelf AS ( 6 SELECT 'title 1' title, DATE '2012-05-01' checkout_date, DATE '2012-05-15' returned_date FROM dual UNION ALL 7 SELECT 'title 1' title, DATE '2012-05-16' checkout_date, DATE '2012-05-20' returned_date FROM dual UNION ALL 8 SELECT 'title 2' title, DATE '2012-04-01' checkout_date, DATE '2012-05-15' returned_date FROM dual ) 9 SELECT bs.title, MAX(bs.returned_date - bs.checkout_date) OVER (PARTITION BY title) FROM bookshelf bs 10 UNION 11 (SELECT b.title, NULL FROM books b 12 MINUS 13* SELECT bs.title, NULL FROM bookshelf bs) SQL> / TITLE MAX(BS.RETURNED_DATE-BS.CHECKOUT_DATE)OVER(PARTITIONBYTITLE) ------- ------------------------------------------------------------ title 1 14 title 2 44 title 3
Lukasz
-
Rewrite the query without views
I remember seeing a function in oracle PL/SQL package, which would be to rewrite a query as it contained no views more (but the only real tables)... but I don't remember the name of the function.
What function/package for this?
Hello
looking for the new feature of 12 c DBMS_UTILITY. EXPAND_SQL_TEXT?
Concerning
Marcus
-
Hello
Can anyone suggest an idea to rewrite this query? This query takes longer than expected, probably
they way the application is made is not fair? Thanks in advance! I use 11g
SELECT brand_id, region_id, sku_base_id, desc_key, (SELECT MAX (cps.product_code) FROM cat_prod_sku_vw cps WHERE cps.brand_id = srl.brand_id AND cps.region_id = srl.region_id AND cps.brand_id = 4 AND cps.region_id = 0 AND ( cps.parent_cat_id || 'PROD' || cps.prod_base_id) = srl.desc_text) AS desc_text FROM sku_rgn_lang_vw srl WHERE brand_id = 4 AND region_id = 0 AND desc_key LIKE 'www_pcode_%' AND LENGTH (desc_text) > 6 AND desc_text LIKE 'CAT%' ;
You should look at this thread {message identifier: = 9360003} to get an idea of what other information is required.
However, I'd be inclined to re - write as an (external) join instead of a scalar select statement. Something more like:
SELECT srl.brand_id, srl.region_id, srl.sku_base_id, srl.desc_key, cps.desc_text FROM sku_rgn_lang_vw srl left join (SELECT brand_id, region_id, parent_cat_id||'PROD'||prod_base_id desc_text MAX (product_code) product_code FROM cat_prod_sku_vw cps WHERE brand_id = 4 AND region_id = 0 GROUP BY brand_id, region_id, parent_cat_id||'PROD'||prod_base_id) cps on cps.brand_id = srl.brand_id AND cps.region_id = srl.region_id AND cps.parent_cat_id||'PROD'||cps.prod_base_id = srl.desc_text WHERE srl.brand_id = 4 AND srl.region_id = 0 AND srl.desc_key LIKE 'www_pcode_%' AND LENGTH (cps.desc_text) > 6 AND cps.desc_text LIKE 'CAT%' ;
Although I'm not entirely sure, I had all the correct alias.
John
-
Rewrite the query to improve the performance and the optimized below cost.
Oracle 10g.
----------------------
Query
UPDATE FACETS_CUSTOM. MMR_DTL
SET
CAPITN_PRCS_IND = 2,
FIL_RUN_DT = Current_fil_run_dt,
ROW_UPDT_DT = dta_cltn_end_dttm
WHERE CAPITN_PRCS_IND = 5
AND HSPC_IND = 'Y '.
AND EXISTS (SELECT 1
OF FACETS_STAGE. CRME_FUND_DTL_STG STG_CRME
WHERE STG_CRME. MBR_CK = MMR_DTL. MBRSHP_CK
AND MMR_DTL. PMT_MSA_STRT_DT BETWEEN STG_CRME. ERN_FROM_DT AND STG_CRME. ERN_THRU_DT
AND STG_CRME. FUND_ID IN ('AAB1', '1AA2', '1BA2', 'AAB2', '1AA3', '1BA3', ' 1 B 80 ', ' 1 HAS 80 '))
AND EXISTS (SELECT 1
OF FACETS_CUSTOM. FCTS_TMS_MBRID_XWLK XWLK
WHERE XWLK. MBR_CK = MMR_DTL. MBRSHP_CK
AND MMR_DTL. PMT_MSA_STRT_DT BETWEEN XWLK. HSPC_EVNT_EFF_DT AND XWLK. HSPC_EVNT_TERM_DT);
Explain the plan of the query
-----------------------------------------------
Hash value of plan: 3109991485
-------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
-------------------------------------------------------------------------------------------------------
| 0 | UPDATE STATEMENT. | 1. 148. 12431 (2) | 00:02:30 |
| 1. UPDATE | MMR_DTL | | | | |
| 2. SEMI NESTED LOOPS. | 1. 148. 12431 (2) | 00:02:30 |
|* 3 | HASH JOIN RIGHT SEMI | | 49. 5488. 12375 (2) | 00:02:29 |
| 4. TABLE ACCESS FULL | FCTS_TMS_MBRID_XWLK | 6494 | 64940 | 24 (0) | 00:00:01 |
|* 5 | TABLE ACCESS FULL | MMR_DTL | 304K | 29 M | 12347 (2) | 00:02:29 |
|* 6 | TABLE ACCESS BY INDEX ROWID | CRME_FUND_DTL_STG | 1. 36. 5 (0) | 00:00:01 |
|* 7 | INDEX RANGE SCAN | IE1_CRME_FUND_DTL_STG | 8. | 1 (0) | 00:00:01 |
-------------------------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
3 - access("XWLK".") MBR_CK "=" MMR_DTL. " ("' MBRSHP_CK")
filter ("XWLK". "HSPC_EVNT_EFF_DT" < = INTERNAL_FUNCTION ("MMR_DTL". " PMT_MSA_STRT_DT') AND
'XWLK '. "" HSPC_EVNT_TERM_DT "> = INTERNAL_FUNCTION ("MMR_DTL". "PMT_MSA_STRT_DT")) "
5 - filter("CAPITN_PRCS_IND"=5 AND "HSPC_IND"='Y')
6 filter (("STG_CRME". "FUND_ID" = "1 HAS 80 ' OR 'STG_CRME'." " FUND_ID "="1AA2"OR"
'STG_CRME '. "FUND_ID"= '1AA3' OR 'STG_CRME'. "FUND_ID" = "1 B 80 ' OR 'STG_CRME'. '. "FUND_ID" = "1BA2" OR "
'STG_CRME '. "FUND_ID"= "1BA3" OR "STG_CRME". "FUND_ID"= "AAB1" OR "STG_CRME". ("FUND_ID"="AAB2") AND
'STG_CRME '. "" ERN_FROM_DT "< = INTERNAL_FUNCTION ("MMR_DTL". "PMT_MSA_STRT_DT") AND "
'STG_CRME '. "" ERN_THRU_DT "> = INTERNAL_FUNCTION ("MMR_DTL". "PMT_MSA_STRT_DT")) "
7 - access("STG_CRME".") MBR_CK "=" MMR_DTL. " ("' MBRSHP_CK")
I could not optimize this query for best performance and optimized the cost... Can someone guide me on this.
Thank you
DS
You think you're going to lines updates 85K, Oracle think it will update a line.
At the time where the existence of the first test runs that oracle think already up to 49 lines, which is probably why he uses the loop join nested for the second test. (In your version of Oracle, the subquery introduced existence a very bad assumption (small) on the amount of data will survive).
It is possible that you will get better performance if you hint Oracle using a hash join for testing the existence - and you might want to think what test will eliminate most of the data and that we can first force.
Having said that, however, note that MMR_DTL research is a considerable fraction of the cost of the query - and an analysis is an easy thing for Oracle cost properly - if, despite your comments on update a column with a clue to this topic, you will find that the query can be more effective if you use an index. This is more likely to be the case if data ' WHERE CAPITN_PRCS_IND = 5 AND HSPC_IND = 'Y' "is well grouped (perhaps the latest data added to the table).". " You could then reduce the cost of maintaining this index by creating an index based on a feature that indexes only the lines where the predicate are both true so that the 2 update deletes the index entries and allows the index remain as thin as possible.
Concerning
Jonathan Lewis
-
Rewrite the query without a clause EXISTS
I would like to know another way to write the query without the EXISTS clause below. The main problem is with the inner query not allowing Java Hibernate to cache the results of the query.
Select max (wt.wtime) wttme
x wt.
PIA,
z g
where wt.vid = v.vid and
v.GID = g.gid and
g.gname = "XXX" and
not exists (select *)
x wt1.
y v1,.
z g1
where wt1.vid = v1.vid and
v1. GID = g1.gid and
G1.gname = "XXX" and
(wt1.last_updated < (sysdate-. 0013) or)
Upper (WT1. Error) '= t'
)
)
z / / DESC;
Name of Type Null
GID NOT NULL NUMBER
GNAME NOT NULL VARCHAR2 (100)
ACTIVE NON-NULL CHAR (1)
DATE OF UPDATE_DATE
UPDATED_BY VARCHAR2 (50)
GID GNAME UPDATE_DATE ACTIVE UPDATED_BY
1 XXX Y 6 July 09 14:50:24 Test
y / / DESC;
Name of Type Null
VID NOT NULL NUMBER
VNAME NOT NULL VARCHAR2 (100)
GID NOT NULL NUMBER
ACTIVE NON-NULL CHAR (1)
DATE OF UPDATE_DATE
UPDATED_BY VARCHAR2 (50)
VID VNAME GID UPDATE_DATE ACTIVE UPDATED_BY
1 ICT 1 Y 6 July 09 14:50:24 Test
arvato 2 1 O 6 July 09 14:50:24 Test
/ / DESC x;
Name of Type Null
VID NOT NULL NUMBER
NUMBER OF WTIME
ERROR VARCHAR2 (4000)
NOT CLOSED NULL CHAR (1)
LAST_UPDATED DATE
VID WTIME LAST_UPDATED CLOSED ERROR
1 65 N N 10 JUNE 09 00:00:00
2 23 N N AUGUST 10 09 00:00:00Ken R says:
What I would like to have is a query WITHOUT a clause EXISTS and to implement INSIDE logical query * (wt1.last_updated< (sysdate="" -="" .0013)="" or="" upper(wt1.error)='T' )*="" in="" the="" outer="">Well have a look at the two queries above then.
-
How to rewrite the query without inline query
Hello people,
I have this request trying to rewrite with a single outer join. As previously with the inline its taking too much time (one day). I was wondering if this is how I rewrite. Thanks to a bouquet. I know there must be indexed on the event.
Published by: user11961230 on May 2, 2012 12:28original : select e.event_id, EVENT_STATUS_CODE, EVENT_TYPE_CODE, c.client_code, trunc(DATE_EXTRACTED), trunc(DATE_SUBMITTED), trunc(CLS.DATE_RETURNED), trunc(DATE_TYPED), trunc(REJECT_DATE), SUM_BILLED "bill_ttl", SUM_PAID, SUM_AMOUNT "Recoveries", trunc(DATE_OF_INCIDENT), recspec.USER_REAL_NAME, recspec.LEVEL_B_CODE, trunc(STAGE_CREATED_DATE), REJECT_CODE, ISO_ERROR FROM EVENT E, CLIENT C, MV_RECOVERYDET_EVENT_SUM MV_R, CLS_SEND CLS, MV_BILLDETAIL_EVENT_SUM MV_BDE, (SELECT EVENT_ID, USER_REAL_NAME, LEVEL_B_CODE FROM END_USER EU, EVENT_END_USER EEU WHERE EEU.END_USER_ID = EU.END_USER_ID AND OWNER_FLAG = 'Y') recspec WHERE E.EVENT_ID = MV_R.EVENT_ID(+) AND E.EVENT_ID = MV_BDE.EVENT_ID(+) AND E.EVENT_ID = recspec.EVENT_ID(+) AND E.EVENT_ID = CLS.EVENT_ID(+) AND E.CLIENT_ID = C.CLIENT_ID AND E.CLIENT_ID = '1078'; After rewritting select e.event_id, EVENT_STATUS_CODE, EVENT_TYPE_CODE, c.client_code, trunc(DATE_EXTRACTED), trunc(DATE_SUBMITTED), trunc(CLS.DATE_RETURNED), trunc(DATE_TYPED), trunc(REJECT_DATE), SUM_BILLED "bill_ttl", SUM_PAID, SUM_AMOUNT "Recoveries", trunc(DATE_OF_INCIDENT), EU.USER_REAL_NAME, EU.LEVEL_B_CODE, EU.USER_REAL_NAME, EU.LEVEL_B_CODE, trunc(STAGE_CREATED_DATE), REJECT_CODE, ISO_ERROR FROM EVENT E, CLIENT C, MV_RECOVERYDET_EVENT_SUM MV_R, CLS_SEND CLS, MV_BILLDETAIL_EVENT_SUM MV_BDE, END_USER EU, EVENT_END_USER EEU WHERE E.EVENT_ID = MV_R.EVENT_ID(+) AND E.EVENT_ID = MV_BDE.EVENT_ID(+) --AND E.EVENT_ID = recspec.EVENT_ID(+) AND E.EVENT_ID = CLS.EVENT_ID(+) AND E.CLIENT_ID = C.CLIENT_ID AND EEU.END_USER_ID = EU.END_USER_ID AND EEU.EVENT_ID(+) = E.EVENT_ID AND OWNER_FLAG = 'Y' AND E.CLIENT_ID = '1078'; ?
PX stuff, it's just the 'pipes' oracle uses to divide your table into pieces and the pieces of transformation. You don't have much control that beyond doing Oracle use parallel queries or not. I guess that you can specify a degree, but this isn't your problem, anyway. But if you're curious, PX is mentioned here. http://docs.Oracle.com/CD/B12037_01/server.101/b10752/ex_plan.htm
Using index becomes a little more complicated with outer joins, because they return the rows that do not match the table conduct. If the index will be useful on the tables of conduct. It is possible to what I was looking to take advantage of the index because each row of the table is returned to the outer join. If you want to limit who then you need some sort of filter condition and an index on that column filter would be useful.
Published by: watch on 2 may 2012 17:20
-
Impossible to activate the rewrite of the query, no error
Hello
I created a simple MV with activated query rewrite, and it works well. The MV is very simple:
Mv_sales CREATE MATERIALIZED VIEW
NOLOGGING
REFRESH THE STRENGTH TO DEMAND
ACTIVATE THE QUERY REWRITING
AS
SELECT
s.cust_id,
Sum (s.QUANTITY_SOLD) sold_qty,
Sum (s.AMOUNT_SOLD) sold_amt
S SALES
GROUP BY s.cust_id
;
I tested the mechanism of query rewriting, and everything works as expected.
Now, I created an another MV with a motion very similar to the one above, but with several tables.
An excerpt from the new query:
SELECT...
Of
FACT_SALES_AND_MARKDOWNS FSM
DIM_PRODUCT DP
DIM_LOCATION DL
DIM_DATE DD
WHERE WSF. DIM_PRODUCT_KEY = DP. DIM_PRODUCT_KEY
AND WSF. DIM_LOCATION_KEY = DL. DIM_LOCATION_KEY
AND WSF. DIM_SALE_DATE_KEY = DD. DIM_DATE_KEY
GROUP BY
DD MERCH_YEAR_ID.
DD. MERCH_YEAR_START_DATE...
I can create the MV, but the query rewriting will not activate!
If I execute ALTER materialized view mv_test ALLOW to REWRITE the QUERY. It runs without giving me an error, but the MV is not always activate the rewrite of the query.
Am I missing something? Can we not have Query Rewrite on a MV with several tables in the query?
Thank you
Joao Moreira
Hello
Please provide the results of these queries:
Select MVIEW_NAME, REWRITE_ENABLED
of DBA_MVIEWS
where MVIEW_NAME = '
'; Kind regards.
-
Hello
I need a few entries to grant the request below I'm not good in the part of tuning
platform = x 2-2 qurter rack exadata, linux
Scenario-> we have converted the non table(100gb) partition to the partition table using online redefinition and the sub query takes a long time (4 min), appreciated the inputs by rewriting the query to improve performance
Select * from ODS_RBS #MOBCDR where trunc(ods_rbs#mobcdr_dst) = to_date ('01-25-2015', ' dd-mm-yyyy');
Execution plan
----------------------------------------------------------
Hash value of plan: 291412148--------------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time | Pstart. Pstop |
--------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 25 M | 4580M | 3934K (29) | 00:02:10 | | |
| 1. RANGE OF PARTITION ALL THE | | 25 M | 4580M | 3934K (29) | 00:02:10 | 1. 428.
| 2. HASH PARTITION ALL | | 25 M | 4580M | 3934K (29) | 00:02:10 | 1. 2.
|* 3 | STORE TABLE FULL ACCESS | ODS_RBS #MOBCDR | 25 M | 4580M | 3934K (29) | 00:02:10 | 1. 856.
--------------------------------------------------------------------------------------------------------------Information of predicates (identified by the operation identity card):
---------------------------------------------------3 - storage (TRUNC (INTERNAL_FUNCTION("ODS_RBS#MOBCDR_DST")) = TO_DATE (' 2015-01-25 00:00:00 ',))
'syyyy-mm-dd hh24:mi:ss"))
Filter (trunc (INTERNAL_FUNCTION("ODS_RBS#MOBCDR_DST")) = TO_DATE (' 2015-01-25 00:00:00 ',))
'syyyy-mm-dd hh24:mi:ss"))
Statistics
----------------------------------------------------------
0 recursive calls
0 db block Gets
7024253 compatible Gets
7022727 physical reads
0 redo size
679097582 bytes sent via SQL * Net to client
3702904 bytes received via SQL * Net from client
336582 SQL * Net back and forth to and from the client
0 sorts (memory)
0 sorts (disk)
5048706 rows processedBR
PMP
Hi, PMP,
you have a clue about your date column?
Maybe a component base snap on 'trunc(ods_rbs#mobcdr_dst)' can help.
concerning
Kay -
2.1 EA1: Query Builder does not update the query to display the results
When using the query designer, if you click view results to see the results of the current query, then return to "Select columns" or the tabs 'Create a Where Clause' change the query, the "View results" tab shows again the results of the original query, even if no tables or columns of the original query occurs. By clicking on the button run the report or by setting a refresh interval has no effect.
On another note, the query designer again is not reentrant, because you cannot select (highlight a part where cursor in) a query, and then open the query for this request of change graphically Designer.Sentinel,
The problem is known and is listed in the known issues in the release notes for the first users. We hope to have this sent to production.
Returning Query Builder is always on our list of things to do. We intend to rewrite the Query Builder and examine a number of requests related to this function. I'm hoping to make it a priority for the next release.
Sue
-
How to rewrite the sql statement?
Hello my query goes like this:
Select a, b, c
from (select 5A, b null, null double c
Union of all the
Select null, 4, the double null
Union of all the
Select 10, 3, double null) test_tab;
and I want to get the result
5 null null
null null 4
10 null null
3 null null
How can I rewrite the query without changing the structure of a table?
Kind regards
IgorHello
A way
select a, null b, null c from test_tab where a is not null union all select null, b, null from test_tab where b is not null union all select null, null, c from test_tab where c is not null
Concerning
Anurag -
How we force a query to use transparently a hint, even if the index is not given in the query as a query rewriting.
For example:
If the user runs a query select deptno, avg (sal) from emp group by deptno;
We want the optimizer to use a hint of result_cache with this request, and it should be transparent to the user.
Query should be rewritten to seamlessly
Select / * + result_cache * / deptno, avg (sal)
WCP
Group of deptno;
How can this feature we make? Please advice.
I checked the possibility of SPM and contours, but it is not clear if this rewrite is possible here.
Thank you and best regards,
Vikas Krishna
Surely dbms_advanced_rewrite is designed for this situation?
-
Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production version
Hello
I want to rewrite a query in a PL/SQL function that I inherited, which returns a list of e-mail addresses to send a notification by e-mail to.
The function as it is currently written is:
DECLARE reporttype NUMBER; count1 NUMBER; count2 NUMBER; email_addr VARCHAR( 255 ); BEGIN SELECT COUNT( * ) INTO count1 FROM project_report_type WHERE project_id = :P51_PROJ_ID AND type_id IN (SELECT type_id FROM report_type); IF (count1 != 0) THEN SELECT COUNT( * ) INTO count2 FROM report_admin WHERE type_id IN (SELECT type_id FROM report_type); IF (count2 != 0) THEN SELECT listagg(TO_CHAR(resources.resource_email), ', ') WITHIN GROUP (ORDER BY resources.resource_email) INTO email_addr FROM report_admin LEFT JOIN resources ON resources.resource_onepass_id = report_admin.user_onepass_id WHERE report_admin.type_id IN (SELECT project_report_type.type_id FROM project_report_type WHERE project_report_type.project_id = :P51_PROJ_ID AND project_report_type.type_id IN (SELECT report_type.type_id FROM report_type) ); RETURN email_addr; END IF; END IF; END;
I'm sure this can be written much more effectively, but I don't know how.
The first charge is to determine if a record exists in the table PROJECT_REPORT_TYPE for the project from the front end page and the PROJECT_REPORT_TYPE. TYPE_ID exists in the REPORT_TYPE table.
If at least one record exists then determine if a record exists in the REPORT_ADMIN table where the REPORT_ADMIN TYPE_ID exists in the REPORT_TYPE table.
If there is at least one record of that result, then create a list of e-mail addresses of RESOURCE table join again on the table REPORT_ADMIN, where REPORT_ADMIN TYPE_ID exists in the PROJECT_REPORT_TYPE table.
I thought of two queries that don't COUNT (*) I could join these two tables together for the values of the query online, SELECT type_id FROM report_type, is a glance toward the top of the table. Therefore, values for TYPE_ID columns must come from the REPORT_TYPE table.
So, I thought that maybe:
SELECT count (*) FROM project_report_type INNER JOIN report_admin count1 ON project_report_type.type_id = report_admin.type_id WHERE project_report_type.project_id =: P51_PROJ_ID;If I had all the records in this query, then get a list of e-mail addresses?
Can what information I provide?
Thank you
Joe
Hi, Joe,
It depends on what you want to do when no line is detected.
If you want that the function returns NULL if no line is detected, then simply:
Email_address RETURN;
If you want the function to return a fixed string, then you can do something like
RETURN NVL (email_address, '(aucune donnée trouvée) ");
Just what you want, you must execute a RETURN statement, so it would be unwise to put the RETURN statement in an IF block.
Maybe you are looking for
-
Scrolling does not work on Satellite Z30-A-1DJ
Hello Summer on the internet trying to find an answer for my problem; How to make scrolling, pinching etc on my touchpad? Scrolling never works with this laptop (2 months) and up to now, even moving cursor was not reliable, since sometimes when start
-
Slow computer XP get error codes, 0 x 80092003, 0 x 80070002 and 0 x 80040154
I did a scan which said I had over 1200 issues with my computer. I went to Ms. fixit and everything I tried to download said: he couldn't start the troubleshooter due to a runtime error. I tried to download different things gave me these error codes,
-
any info on this would be great thank you
-
When my daughter downloads photos they are available in the public record. Why?
-
BlackBerry Smartphones Apps to transfer to the new phone.
If I buy a few applications, they will transfer to a new phone when I receive one?