Tuning query without using hint
Hi,
i want to change the plan of a query without using hint.
Also i want to use the plan that hint generate in my original query.
My db is a 11g.
How can i do this?
tnx
You can use SQL Plan Manager. You might find this interesting:
http://blogs.oracle.com/optimizer/entry/what_should_i_do_with_old_hints_in_my_workload
The link above basically suggests these steps:
1. Run the query with the hints, then
2. Take the plan from #1 and associate its SQL plan baseline with the query with no hints
3. Remove the hints for that query in the code and start capturing and evolving plans for the un-hinted query
Similar Messages
-
How to write a SQL Query without using group by clause
Hi,
Can anyone help me to find out if there is a approach to build a SQL Query without using group by clause.
Please site an example if is it so,
RegardsI hope this example could illuminate danepc on is problem.
CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
CREATE OR REPLACE FUNCTION GET_ARR return my_array
as
arr my_array;
begin
arr := my_array();
for i in 1..10 loop
arr.extend;
arr(i) := i mod 7;
end loop;
return arr;
end;
select column_value
from table(get_arr)
order by column_value;
select column_value,count(*) occurences
from table(get_arr)
group by column_value
order by column_value;And the output should be something like this:
SQL> CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
2 /
Tipo creato.
SQL>
SQL> CREATE OR REPLACE FUNCTION GET_ARR return my_array
2 as
3 arr my_array;
4 begin
5 arr := my_array();
6 for i in 1..10 loop
7 arr.extend;
8 arr(i) := i mod 7;
9 end loop;
10 return arr;
11 end;
12 /
Funzione creata.
SQL>
SQL>
SQL> select column_value
2 from table(get_arr)
3 order by column_value;
COLUMN_VALUE
0
1
1
2
2
3
3
4
5
6
Selezionate 10 righe.
SQL>
SQL> select column_value,count(*) occurences
2 from table(get_arr)
3 group by column_value
4 order by column_value;
COLUMN_VALUE OCCURENCES
0 1
1 2
2 2
3 2
4 1
5 1
6 1
Selezionate 7 righe.
SQL> Bye Alessandro -
Needs help to retrive the last row in a select query without using rownum
Hi ,
i need to retrive the last row from the select sub query without using rownum.
is there any other way to retrive the last row other than the below query.
is that the ROWNUM=1 will always retrive the 1 row of the select query ?
select from*
*(select ename from employee where dept_id=5 order by desc) where rownum=1;*
Please advise.
thanks for your help advance,
regards,
Senthur957595 wrote:
Actually my problem is ithat while selecting the parents hiearchy of the child data using
CONNECT BY PRIOIR query
I need the immediate parent of my child data.
For example my connect BY query returns
AAA --- ROOT
BBB --PARENT -2
CCC --PARENT-1
DDD IS my input child to the connect by query
Immediate parent of my child data "DDD" ---> CCC(parent -1)
i want the data "CCC" from the select query,for that i am taking the last row of the query with rownum.
I got to hear that using ROWNUM to retrive the data will leads to some problem.It is a like a magic number.I am not sure what the problem will be.
So confusing with using this rownum in my query.
Please advice!!!It's not quite clear what you're wanting, but perhaps this may help?
you can select the PRIOR values to get the parent details if you want...
SQL> ed
Wrote file afiedt.buf
1 select empno, lpad(' ',(level-1)*2,' ')||ename as ename, prior empno as mgr
2 from emp
3 connect by mgr = prior empno
4* start with mgr is null
SQL> /
EMPNO ENAME MGR
7839 KING
7566 JONES 7839
7788 SCOTT 7566
7876 ADAMS 7788
7902 FORD 7566
7369 SMITH 7902
7698 BLAKE 7839
7499 ALLEN 7698
7521 WARD 7698
7654 MARTIN 7698
7844 TURNER 7698
7900 JAMES 7698
7782 CLARK 7839
7934 MILLER 7782
14 rows selected.(ok, not the best of examples as the mgr is already known for a row, but it demonstrates you can select prior data) -
Hello every one, can I rewrite the following query without using the 'ROW_NUMBER() OVER ' part.
The query is supposed to pull out the records whose CODE is not NULL and has most
recent date for UPDATE_DATE . The reason I wanted to do this is, When I embed this query
in between many other queries along with JOINs, My oracle server is unable to execute. So, I thought
its better to supplant 'ROW_NUMBER() OVER ' logic with something else and try it. .
SELECT a.* FROM
(SELECT b.*, ROW_NUMBER() OVER (PARTITION BY b.PIDM
ORDER BY b.UPDATE_DATE DESC) AS Rno
FROM
SELECT *
FROM SHYNCRO WHERE CODE IS NOT NULL
)b
)a
WHERE a.Rno = 1Hi,
You didn't write over 150 lines of code and then start testing it, did you?
Don't.
Take baby steps. Write as little as pssiblem test that. Debug and test again until you have something that does exactly what you want it to do.
When you have somehting that works perfectly, take one baby step. Add a tiny amount of code, maybe 1 or 2 lines more, and test again.
When you do get an error, or wrong results, you'll have a much better idea of where the problem is. also, you won't be building code on a flimsy foundation.
If you need help, post the last working version and the new version with the error. Explain what you're trying to do in the new version.
The error message indicates line 133. It looks like line 133 of your code is blank. Does your front end allow completely blank lines in the middle of a query? SQL*Plus doesn't by default; you have to say
SET SQLBLANKLINES ONto have a completely blank line in SQL*Plus. (However, lines containing nothing but at commnet are always allowed.)
You may have noticed that this site normally doesn't display multiple spaces in a row.
Whenever you post formatted text (such as indented code) on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
The 4 people who posted small code fragments for you to read all did this. It would be so much easier for people to read your humongeous query if it were formatted. -
How can i fetch records from 3 tables in a single query without using join
Hi.
Can any body please tell me <b>How can i fetch records from 3 tables with a single query without using joins</b>
Thanx
prabhuduttaHi Prabgudutta,
We can fetch the data by using the views concept.
Go throuth this info we can know the how to create view and same like database table only we can fetch the data.
Views conatin the data at runtime only.
Four different view types are supported. These differ in the
way in which the view is implemented and in the methods
permitted for accessing the view data.
Database views are implemented with an equivalent view on
the database.
Projection views are used to hide fields of a table (only
projection).
Help views can be used as selection method in search helps.
Maintenance views permit you to maintain the data
distributed
on several tables for one application object at one time.
step by step creation of Maintenance view:
With the help of the table maintenance generator, you are able to maintain the ENTRIES of the table in SM30 transaction.
It can be set in transaction SE11 - Tools - Table maintenance generator.
Table maintanance Generator is used to manually input values using transaction sm30
follow below steps
1) go to se11 check table maintanance check box under attributes tab
2) utilities-table maintanance Generator-> create function group and assign it under
function group input box. Also assign authorization group default &NC& .
3) select standard recording routine radio in table table mainitainence generator to move table
contents to quality and production by assigning it to request.
4) select maintaience type as single step.
5) maintainence screen as system generated numbers this dialog box appears when you click on create button
6) save and activate table
One step, two step in Table Maintenance Generator
Single step: Only overview screen is created i.e. the Table Maintenance Program will have only one screen where you can add, delete or edit records.
Two step: Two screens namely the overview screen and Single screen are created. The user can see the key fields in the first screen and can further go on to edit further details.
SM30 is used for table maintenance(addition or deletion of records),
For all the tables in SE11 for which Table maintenance is selected , they can be maintained in SM30
Sm30 is used to maintain the table ,i.e to delete ,insert or modify the field values and all..
It creates the maintenance screen for u for the aprticular table as the maintenance is not allowed for the table..
In the SE11 delivery and maintenance tab, keep the maintenance allowed..
Then come to the SM30 and then enter the table name and press maintain..,
Give the authorization group if necessary and give the function group and then select maintenance type as one step and give the screen numbers as system specified..
Then create,,,
Then u will able to see the maintenance view for the table in which u can able to insert and delete the table values...
We use SM30 transaction for entering values into any DB table.
First we create a table in SE11 and create the table maintenance generator for that Table using (utilities-> table maintenance generator) and create it.
Then it will create a View.
After that from SM30, enter the table name and Maintain, create new entries, change the existing entries for that table.
Hope this resolves your query.
Reward all the helpful answers.
Rgds,
P.Naganjana Reddy -
I want single update query without use the function.
I want to update sells_table selling_code field with max date product_code from product table.
In product table there is multiple product_code date wise.
I have been done it with below quey with the use of function but can we do it in only one update query
without use the function.
UPDATE sells_table
SET selling_code = MAXDATEPRODUCT(ctd_vpk_product_code)
WHERE NVL(update_product_flag,0) = 0 ;
CREATE OR REPLACE FUNCTION HVL.maxdateproduct (p_product IN VARCHAR2) RETURN NUMBER
IS
max_date_product VARCHAR2 (100);
BEGIN
BEGIN
SELECT NVL (TRIM (product_code), 0)
INTO max_date_product
FROM (SELECT product_code, xref_end_dt
FROM product
WHERE TO_NUMBER (p_product) = pr.item_id
ORDER BY xref_end_dt DESC)
WHERE ROWNUM = 1; -- It will return only one row - max date product code
EXCEPTION
WHEN OTHERS
THEN
RETURN 0;
END;
RETURN max_date_product;
END maxdateproduct;
Thanks in Advance.Hi,
Something like this.
update setlls_table st
set selling_code =(select nvl(trim(product_code)) from
(select product_code
, rank() over (partition by item_id order by xref_end_dt DESC) rn
from product
) pr
where rn =1
and pr.item_id = st.ctd_vpk_product_code
) where NVL(update_product_flag,0) = 0 ;As such not tested due to lack of input sample.
Regards
Anurag Tibrewal. -
Can u write the following query without using group by clause
select sp.sid, p.pid, p.name from product p, supp_prod sp
where sp.pid= p.pid and
sp.sid = ( select sid from supp_prod group by sid
having count(*) =(select count(*) from product));
thru this, we retrieving all the products delivered by the supplier.
Can you write the following query without using the group by clauseselect sp.sid, p.pid, p.name
from product p, supp_prod sp
where sp.pid= p.pid the above query will still retrieve all the products supplied by the supplier. sub-query is not necessary.
maybe if you can post some sample data and output will help us understand what you want to achieve. -
How to design a query without using Net Weaver Query Designer
Does anyone know if any alternative way to <b>design an query without using Net weaver GUI</b>? in order to reduce the time consuming, I am wondering if there have any method which can define/modify a stack of cells, characteristics and structures without work through the GUI.
Deeply thank for any of your advices.Can you give an example?
Just from what you write, I would assume that you talk about something like a mass-property-changer. As far as I know the BEx this is not really possible, but what I do normally is building one query and then either using query-views (saving more or less the navigation state) or by copying and changing the properties of the few characteristics and key figures.
But without a specific example it's difficult to exactly understand what you exactly need.
Mario -
SQL Query without using Pivot...
Hi Guys,
Need help with a query... I think pivot table is the way to go but don't wanna to use it as it is not supported in Oracle 10g.
Sample data set...
Part
Section
A001
AC
A001
AY
A001
AN
A001
AX
A015
AC
A015
AR
A007
AC
A008
AN
A008
AX
A008
AE
A008
AT
A008
AY
Required output... (Please note that I cannot hard code the Section column as the data is dynamic)
Part
AC
AY
AN
AX
AR
AE
AT
A001
Y
Y
Y
Y
A015
Y
Y
A007
Y
A008
Y
Y
Y
Y
Y
Can you help me out with this without using pivot tables?
Thanks,
NapsterHi Napster, Try this
select part,
max(decode(section,'AC','Y',NULL)) AC,
max(decode(section,'AY','Y',NULL)) AY,
max(decode(section,'AN','Y',NULL)) AN,
max(decode(section,'AX','Y',NULL)) AX,
max(decode(section,'AC','Y',NULL)) AC,
max(decode(section,'AR','Y',NULL)) AR,
max(decode(section,'AT','Y',NULL)) AT
from sple group by part
SQL> /
Output will be
PART A A A A A A A
A001 Y Y Y Y Y
A007 Y Y
A008 Y Y Y Y
A015 Y Y Y -
Query:without using union
hai every one,
ihave atable like this:
table1
id emp1 emp2 emp3
1 100 200 300
2 90 295 977
3 150 299 500
and i need the result like this:
100
90
150
200
295
299
300
977
500
the result is just union of emp1,emp2 and emp3
i.e, this type of result we can produce with this:
select emp1 from table1 union select emp2 from table1 union select emp3 from table1
but i need a query having the same result as above without using the union statement
thanks in advance...
Edited by: jp_valapad on Sep 12, 2008 2:38 AM
Edited by: jp_valapad on Sep 12, 2008 2:39 AMKarthick_Arp wrote:
...but may not be the best way.Well, on my example, using your method:
with my_tab as (select 1 id, 1 col1, 2 col2 from dual union all
select 2 id, 3 col1, 4 col2 from dual union all
select 3 id, 5 col1, 6 col2 from dual)
select mt.id,
decode(dt.id, 1, mt.col1, 2, mt.col2) col_val,
dt.id dummy_id
from my_tab mt,
(select level id
from dual
connect by level <= (select max(id) from my_tab)) dt
order by dt.id, mt.id
ID COL_VAL DUMMY_ID
1 1 1
2 3 1
3 5 1
1 2 2
2 4 2
3 6 2
1 3
2 3
3 3So, clearly not the best way!
Your dummy table needs to contain the same number of rows as the number of columns that are to be unpivoted - in my example 2, in the OP's example 3. It's just a fluke that yours worked, as the OP's test data had 3 id's! -
How can i construct this query without using CASE statement?
I've a following code. I'm using this script in Hibernet. So, i cannot use CASE there. Because, hibernet doesn't support case in select statement. How can i construct the same thing which will give me the same result without using CASE?
SELECT ofc.FLT_LCL_ORIG_DT
, ofc.CARR_IATA_CD
, ofc.FLT_NBR
, ofc.ORIG_ARPT_CD
, ofc.DEST_ARPT_CD
, sum( ofc.CNCT_PSGR_CNT) AS BOOKED_CNCT_PSGR_CNT
, sum( CASE WHEN o.fsdr_mrkt_cd = 'D' AND d.fsdr_mrkt_cd = 'D' THEN '0'
ELSE to_char(ofc.CNCT_PSGR_CNT,'99') END ) AS BOOKED_INTL_CNCT_PSGR_CNT
, sum(CASE WHEN o.fsdr_mrkt_cd||d.fsdr_mrkt_cd = 'DD'
THEN '0'
ELSE to_char(ofc.CNCT_PSGR_CNT,'99')
END) AS NEW_BCNT
FROM OPS_FLT_CNCT ofc
, STN o
, STN d
WHERE ofc.CNCT_ORIG_ARPT_CD = o.STN_CD
AND ofc.CNCT_DEST_ARPT_CD = d.STN_CD
-- AND TRUNC(ofc.FLT_LCL_ORIG_DT) = trunc(to_date('22-MAY-2007','DD-MON-YYYY'))
AND ofc.CARR_IATA_CD = 'UA'
AND ofc.FLT_NBR = '1218'
AND ofc.ORIG_ARPT_CD = upper('DEN') AND ofc.DEST_ARPT_CD = upper('IAD') GROUP BY ofc.FLT_LCL_ORIG_DT
, ofc.CARR_IATA_CD
, ofc.FLT_NBR
, ofc.ORIG_ARPT_CD
, ofc.DEST_ARPT_CD ;And, the output look like this --
FLT_LCL_O CARR FLT_N ORI DES BOOKED_CNCT_PSGR_CNT BOOKED_INTL_CNCT_PSGR_CNT NEW_BCNT
22-MAY-07 UA 1218 DEN IAD 9 0 0
23-MAY-07 UA 1218 DEN IAD 1 0 0
24-MAY-07 UA 1218 DEN IAD 2 1 1
25-MAY-07 UA 1218 DEN IAD 1 0 0Thnaks in advance for reply.
Regards.
Satyaki De.
#####2 ideas:
1. Inline function to perform the CASE funcionaltity for you
2. Piplelined function to generate the entire dataset
Both will be slower than just using CASE in a query, but we're working around big constraints -
Query without using connect by
Hi Guys,
I need to rewrite the following query without a connect by command. Is there a way to do this?
[code]
SELECT DISTINCT *
FROM serial_structure_table str,
serial_catalog_table psc,
serial_table sop,
life_serials_table lls,
part_table mp,
serial_parts_table vs,
events_table pe,
task_table lmt
WHERE str.part_no = psc.part_no
AND str.serial_no = psc.serial_no
AND str.part_no = sop.part_no(+)
AND str.serial_no = sop.serial_no(+)
AND str.part_no = lls.part_no(+)
AND str.serial_no = lls.serial_no(+)
AND str.part_no = vs.part_no
AND str.serial_no = vs.serial_no
AND mp.maint_prog = vs.maint_prog_id(+)
AND mp.maint_prog = vs.maint_prog_rev(+)
AND mp.part_no = vs.part_no(+)
AND mp.maint_group = vs.maint_group(+)
AND str.part_no = pe.part_no(+)
AND str.serial_no = pe.serial_no(+)
AND str.serial_no = lmt.serial_no(+)
AND str.part_no = lmt.part_no(+)
AND mp.maint_code = lmt.maint_code
AND str.parent_seq_no IS NOT NULL
AND str.seq_no IN (SELECT seq_no FROM serial_table
START WITH seq_no = (SELECT vss.seq_no
FROM serial_structure_table vss, vehicle_serial_table vehicle
WHERE vss.part_no = vehicle.part_no
AND vss.serial_no = vehicle.serial_no
AND vehicle.vehicle_id = '120')
CONNECT BY PRIOR seq_no = parent_seq_no)
[/code]
Many Thanks,
NapsterHi Frank,
This query which fetches a data set to a report... So when executing this query in the report I will need to have a sql expression something like below...
select *
from MY_VIEW
where vehicle.vehicle_id = '&Vehicle_Id'
When the above is run user will be asked to insert a vehicle id and that will be the user input for my sql statement... (I inserted the value 120 here just for the testing purpose). In here I will need to create a view (something like MY_VIEW which consist of the entire sql expression) as long sql expressions are not supported in our tool. So I have to compile a view with the results set without the connect by clause...
Just let me know if it is still not clear..
Thanks
Napster -
Recursive Query without using connect_by
Hi All,
I have to find all the nodes related to a given node in a huge database table(billions of rows). Each node contains the following fields:
nodeID
TargetID
SourceID
TypeOfNode
Some XML metadata
The nodeID is the id for each node. My task is given a nodeID say 10 would be to retrieve this node from the database get the TargetID of this node. Then find all the nodes in the database that have their sourceID or targetID that equals this nodes TargetID. I have to do that recursively on each node that I found in the last query till I have the complete graph of all the nodes that are related to the node provided.
The method of how I am currently doing it is that I use the "connect_by" query in Oracle to find the tree of relationships in one direction then take the leaves of the tree and do a "connect by" in the opposite direction if I find any new roots I do a query in the reverse direction ..I keep doing that till I find no new roots or leaves. This works when the data is small but with the size of the data that I am quering at, I genrally end up with a OutOfMemory error and/otherwise get data back in about 4-5 days.
I was looking over the following SQL99 facility that I was hoping to use in order to get a controlled recursion on the data to do a transitive closure for graphs.
According to Stefan Wagner
"The last ISO standard for SQL, called SQL99 , provides a facility called recursive query. Writing a recursive query involves writing the query expression that one wants to recurse on and giving it a name as a temporary view, then using that name in an associated query expression.
WITH RECURSIVE
Q1 AS SELECT ... FROM ... WHERE ...,
Q2 AS SELECT ... FROM ... WHERE ...
SELECT ... FROM Q1, Q2, WHERE ... "
Do you know if we can do this in Oracle 9i or 10g. The reason why I am not really fond of "connect by" is that it allows us a very limited control on the recursion specially the type we need for a transitive closure for graphs.
I would be really gratful if you could provide some tips on how to go about solving this problem.
Thanking You,
SumitThanks For the reply..but the problem is not that easy:)... ok Ill try and explain it with an example...Here is a table (P.N. I have just put all the data to be retrieved from a table adjecent ..in real this data will be scattered over a large table..so I can not do select * from...:) )=
nodeID | TagetID | SourceID
1 | a | b
2 | a | c
3 | b | d
4 | b | e
5 | c | f
6 | c | aa
7 | f | ab
8 | f | ac
9 | aa | ad
10 | aa | ae
11 | af | d
12 | af | ba
13 | bb | af
14 | ba | bc
15 | cd | a
16 | ce | a
17 | bf | bd
18 | be | bd
19 | bd | aa
20 | cb | ca
21 | cc | ca
22 | ca | ae
23 | ca | aeWhat I need to do is given a nodeID 10..I will need to retrieve all the above rows from a table...thus the result of my SQL or recursive SQL should give me 23 rows...If you draw the above on paper you will see that the source and the target ids will make a graph.
Any Thoughts?
-Sumit -
How to precalculate a Query without using a fixed variable in I Broad C?
Hello,
The query should be precalculate with dynamic values of a variable which are investigated during runtime. The broadcaster forces fixed values of a variable.
Does anybody knows, how to avoid the using of a fixed variable in the Information Broadcaster?
Thank you in advance.
Best RegardsHi,
Can you tell me where in the system have you changed this setting. I searched in SPRO but there is nothing about the language. I am also facing similar situation. And if you have worked with PDF files in the broadcaster can you tell me how to change the PDF file names when I run the broadcaster for 6 to 7 variables(I mean VAR1,VAR2,...) The main folder where these PDF files get stored I can define but dont know how to change the PDF file names which fall into this folder.
Thanks,
Kal -
Solution for this but in single query without using subquery and all
My Table Structure be like this
empid sal
100 5000
200 3000
300 2000
400 1000
I want the ouput like this
empid sal Running Total
100 5000 5000
200 3000 8000
300 2000 10000
400 1000 11000You mean something like
select empno, sal, sum(sal) over (order by empno) from emp order by empno
EMPNO,SAL,SUM(SAL)OVER(ORDERBYEMPNO)
4444,,
7369,100,100
7499,200,300
7521,100,400
7566,100,500
7654,1250,1750
7698,2850,4600
7782,2450,7050
7788,100,7150
7839,5000,12150
7844,1500,13650
7876,1100,14750
7900,950,15700
7902,3000,18700
7934,1300,20000
Maybe you are looking for
-
Bad reporting performance after compressing infocubes
Hi, as I learned, we should compress requests in our infocubes. And since we're using Oracle 9.2.0.7 as database, we can use partitioning on the E-facttable to still increase reporting performance. So far all theory... After getting complaints about
-
Ical not publishing to dotmac--new information
Hello, I have been having a hard time with icalendar not publishing on dotmac. It started happening suddenly on my upgrade to 10.5.2. The dotmac support people have been responding to my inquiries with the following suggestions (eached bumped to a hi
-
Repair HD OSX 10.5.8
I recently tried downloading XBMC onto my macbook and instead of launching, it continues to "quit unexpectedly". After downloading several different versions of the program, I decided to run a diagnostic on my disk drive in Disk Utility. The result w
-
Can't boot after system update: unknown filesystem type
After running a system update, including updating the kernel, I can't boot to the new kernel. On booting, grub loads the kernel image, runs/loads udev, but then fails to mount the root partition with error: mount: unknown filesystem type 'ext4' I hav
-
Filtering Tuples at Syndicator
Hi, I want to syndicate only the specific tuple values at syndicatorbased on the remote system Example : I have 2 remote systems R1, R2 and tuple with 5 fileds . Key tuple field contains 2 values T1- Specific to R1, T2 - Specific to R2 The record con