Doubt in Looping over a collection...?
Hello,
As i was goin through some collections topics .. i have understood the basics, but i am NOT able to understand this line ... *" l_tab(l_tab.last) := i; "*
DECLARE
TYPE t_tab IS TABLE OF exception_test.id%TYPE;
l_tab t_tab := t_tab();
BEGIN
-- Fill the collection.
FOR i IN 1 .. 100 LOOP
l_tab.extend;
l_tab(l_tab.last) := i;
END LOOP;
End;
Why it is assigning like ' l_tab.LAST '.....?? y not from FIRST place....???
Thanks
Aijaz Mallick wrote:
Tht's Correct ... But why only LAST & why not FIRST....???Perhaps if you look at the contents while you do it, you'll get an idea...
SQL> ed
Wrote file afiedt.buf
1 declare
2 type t_coll is table of integer;
3 v_coll t_coll := t_coll();
4 --
5 procedure show_coll is
6 v_str varchar2(2000);
7 begin
8 for x in 1..v_coll.last
9 loop
10 v_str := ltrim(v_str||','||v_coll(x),',');
11 end loop;
12 dbms_output.put_line('Array Size: '||to_char(v_coll.last,'99')||' : '||v_str);
13 end;
14 --
15 begin
16 for i in 1..10
17 loop
18 v_coll.extend;
19 v_coll(v_coll.last) := i;
20 show_coll;
21 end loop;
22* end;
SQL> /
Array Size: 1 : 1
Array Size: 2 : 1,2
Array Size: 3 : 1,2,3
Array Size: 4 : 1,2,3,4
Array Size: 5 : 1,2,3,4,5
Array Size: 6 : 1,2,3,4,5,6
Array Size: 7 : 1,2,3,4,5,6,7
Array Size: 8 : 1,2,3,4,5,6,7,8
Array Size: 9 : 1,2,3,4,5,6,7,8,9
Array Size: 10 : 1,2,3,4,5,6,7,8,9,10
PL/SQL procedure successfully completed.Whereas, if you where using FIRST instead of LAST, you'd get...
SQL> ed
Wrote file afiedt.buf
1 declare
2 type t_coll is table of integer;
3 v_coll t_coll := t_coll();
4 --
5 procedure show_coll is
6 v_str varchar2(2000);
7 begin
8 for x in 1..v_coll.last
9 loop
10 v_str := ltrim(v_str||','||v_coll(x),',');
11 end loop;
12 dbms_output.put_line('Array Size: '||to_char(v_coll.last,'99')||' : '||v_str);
13 end;
14 --
15 begin
16 for i in 1..10
17 loop
18 v_coll.extend;
19 v_coll(v_coll.first) := i;
20 show_coll;
21 end loop;
22* end;
SQL> /
Array Size: 1 : 1
Array Size: 2 : 2,
Array Size: 3 : 3,,
Array Size: 4 : 4,,,
Array Size: 5 : 5,,,,
Array Size: 6 : 6,,,,,
Array Size: 7 : 7,,,,,,
Array Size: 8 : 8,,,,,,,
Array Size: 9 : 9,,,,,,,,
Array Size: 10 : 10,,,,,,,,,
PL/SQL procedure successfully completed.
SQL>
Similar Messages
-
Looping Over the Collection elements in the BPEL
Hi Everybody,
Note:It appears this thread long paragraph but those are schems structures only.I am giving them to give full depth of my req.
1) First requirement :I have requirement wherein I have to retrieve the Data from Database adapter and modify it according to my requirements like below.
1) Input data from Database Adapter example: (Initial Schema)
<select_arrid_collection xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/Select_Arrid">
<select_arrid>
<arr_id>arr1</arr_id>
</select_arrid>
<select_arrid>
<arr_id>arr2</arr_id>
</select_arrid>
<select_arrid>
<arr_id>arr1</arr_id>
</select_arrid>
<select_arrid>
<arr_id>arr2</arr_id>
</select_arrid>
</select_arrid_collection>
2) I am modifying to get the collection objects based on element same arr_id(If it is arr1,I have to get the all the elements related arr1 into one of the collection Object that is select_arrid_collection.Likewise for any arr_id ,it has to group them into a select_arrid_collection element) like below:
Modified schema:
<root xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/Select_Arrid">
<select_arrid_collection>
<select_arrid>
<arr_id>arr1</arr_id>
</select_arrid>
<select_arrid>
<arr_id>arr1</arr_id>
</select_arrid>
</select_arrid_collection>
<select_arrid_collection>
<select_arrid>
<arr_id>arr2</arr_id>
</select_arrid>
<select_arrid>
<arr_id>arr2</arr_id>
</select_arrid>
</select_arrid_collection>
</root>
Note: root element is added in the schema that is why this modified xml has different namespace
I am using below xsl file to get the above schema to get the solution for first requirement:
<xsl:stylesheet version="2.0" xmlns:ns1="http://www.example.org" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<ns1:root>
<xsl:for-each-group select="*/ns1:Select_Arrid" group-by="ns1:Arr_id">
<xsl:sort select="current-grouping-key()">
<ns1:select_arrid_collection>
<xsl:copy-of select="current-group()">
<xsl:apply-templates/>
</xsl:copy-of>
</ns1:select_arrid_collection>
</xsl:sort>
</xsl:for-each-group>
</ns1:root>
</xsl:template>
</xsl:stylesheet>
2) Second requirement:
After getting the multiple collection elements(select_arrid_collection),I want to loop through each select_arrid_collection element and map the elements in that to another service schema.
I have created the xsd like above required modified schema and assign it to a variable(element type) which takes same modified schema so that I can have a variable on which I want to apply while activity.
But I want to have the idea how to loop through the multiple collection elements(select_arrid_collection) and map the elements of each select_arrid_collection to a input variable of a service.
My problem is I have to get each select_arrid_collection element in the schema where root element is 'root'.I am not able to trace how to get the no of select_arrid_collection elements so that I can loop through in the transofrm activity.
Can anybody help me put in this?
Edited by: 899283 on Jan 9, 2013 1:48 AM
Edited by: 899283 on Jan 9, 2013 1:52 AM
Edited by: 899283 on Jan 9, 2013 1:53 AM
Edited by: 899283 on Jan 9, 2013 2:02 AMCan you please let us know if there are some helpful/correct answers in your previous questions and follow the forum etiquette? https://forums.oracle.com/forums/ann.jspa?annID=893
Where Can I create Staging table in SOA server?
regarding sending response at a time to a WSDL in BPEL
Do we need nodemanager for SOA server installation?
I want to set the time for polling of DB Adapter -
Hello,
Can someone please demonstrate how I would use a cfLoop to
loop over and output the contents of this fictious nested
structure?
Thank You!mletson wrote:
> I figured it out. If anyone has a better solution,
please let me know.
>
> <cfloop from="1" to="#structCount(student)#"
index="x">
>
> <cfset variables.studentID = "student00" & x>
>
> <tr>
>
<td><cfoutput>#student[studentID]["firstName"]#</cfoutput></td>
>
<td><cfoutput>#student[studentID]["lastName"]#</cfoutput></td>
>
<td><cfoutput>#student[studentID]["phone"]#</cfoutput></td>
> </tr>
>
> </cfloop>
>
A slightly simpler version using the structure form of the
<cfloop...>
tag. It also demonstrates both array notation, that you used,
as well
as dot notation. Finally it puts a single <cfoutput...>
block around
the entire loop. This can provide a small but accumulative
performance
improvement.
<cfoutput>
<cfloop collection="#student#" item="aStudent">
<tr>
<td>#aStudent["firstName"]# OR
#aStudent.firstName#</td>
<td>#aStudent["lastName"]# OR
#aStudent.lastName#</td>
<td>#aStudent["phone"]# OR #aStudent.phone#</td>
</tr>
</cfloop>
</cfoutput> -
Hey Guys,
I have a component that returns a structure. The structure is
called ContactQuery. ContactQuery has to elements, one called
Results, and one called Success. Results contains the data I want
to loop over. If you try looping over the ContactQuery by using
CFLoop and specify the ContactQuery as the collection, of course it
only loops twice (once for Results, once for Success). How can I
loop over the Results structure withing ContactQuery? You can see
the dump of the structure at:
http://www.digitalswordsmen.com/cfschedule/admin/Create_Tokens_Table.cfm
Attached is the code I have. I am just unsure of the syntax
for looping over the Results section of the structure.
Thank you.Nope. I am dumb and didn't really think about it. The fact
that it is a query nested in a structure threw me off. The code
that works was
<cfloop query="ContactQuery.Results">
<tr>
<td></td><td>#firstname#</td><td>#lastname#</td><td>#email#</td><td>#randrange(10000,9999 9)#</td>
</tr>
</cfloop>
Thanks for the help, sorry about that dumb question. -
Loop over form values & insert into db
Form
prod_id prod_name prod_price prod_status
001 product 001 1.00 1
002 product 002 2.00 1
003 product 003 3.00 0
004 product 004 4.00 0
Form Dump
prod_name product 001,product 002,product 003,product 004
FIELDNAMES prod_id, prod_name, prod_price, prod_status
prod_price 1.00,2.00,3.00,4.00
prod_status 1,1,0,0
prod_id 001,002,003
I want to update a few fields, prod_price and prod_status. I submit these values to my update page but I'm not sure how to loop over these values and update by the prod_id. In my update page I'm using cfdump and I see the structure of the form, the fieldnames as well as the prod_id, prod_name, etc and their values.
My question is how do I loop over these form values so I'll be able to update by each prod_id? I've played around with looping over the form collection values but no luck.When I do stuff like this, I append the "id" value to the end of each form field. That enables me to ensure the other fields match up.
When processing the form, I generally do something like this:
<cfloop list="#form.fieldnames# index="ThisField">
<cfif left(ThisField, 9) is "prod_name">
<cfscript>
ThisID = removechars(thisfield, 9);
ThisName = form["prod_name" & ThisID];
same for other fields
Then do something with those variables. -
Checkboxes remain set when looping over screen
Hi there,
I have got a problem with some checkboxes on a BSP with MVC.
I am creating an extension for cProjects within a single tabStrip.
My BSP constist of several checkboxes and I want to loop over this screen for some times to collect data. For every call of the BSP I create a new instance, set page attributes and call the view in DO_REQUEST. The page attributes cause some checkboxes to be set. This works fine so far.
My problem is that checkboxes that were selected on the previous screen remain selected.
I think this happens because the checkboxes have the same names as those on previous screens.
How can I disable this behaviour? I would appreciate your help.Hi Raja,
thanks for your friendly welcome!
My BSP is already stateless. It is for assigning test
types to components in a production project and for
assigning standards to these test types. So there are
some nested groups with checkboxes.
First I loop over some existing test types and standards which will be displayed as 'checked' and the checkboxes are disabled. This works great so far.
<%@page language="abap" %>
<%@extension name="bsp" prefix="bsp" %>
<%@extension name="htmlb" prefix="htmlb" %>
<%@extension name="xhtmlb" prefix="xhtmlb" %>
<%@extension name="phtmlb" prefix="phtmlb" %>
<xhtmlb:overflowContainer>
<htmlb:button id = "test_comp_next"
text = "Next"
tooltip = "Go to next step in Task Wizard"
onClick = "test_comp_next"
design = "EMPHASIZED" />
<br />
<htmlb:textView text = "Component Validation"
design = "EMPHASIZED" />
<br />
<htmlb:group>
<htmlb:groupHeader>
<htmlb:textView text = "<%= ms_component-task_descr %>"
design = "EMPHASIZED" />
</htmlb:groupHeader>
<htmlb:groupBody>
<table cellpadding="5" valign="TOP" >
<tr>
<%
mv_counter = 0.
loop at mt_test_types_available into ms_test_type_available.
read table mt_test_types into ms_test_type with key task_type = ms_test_type_available-test_type.
if ms_test_type is not initial.
mv_counter = mv_counter + 1.
%>
<td valign="TOP">
<htmlb:group width="110px" >
<htmlb:groupHeader>
<htmlb:textView text = "<%= ms_test_type-task_type %>"
design = "EMPHASIZED" />
</htmlb:groupHeader>
<htmlb:groupBody>
<%
loop at mt_standards_available into ms_standard_available.
if ms_standard_available-test_type = ms_test_type-task_type and ms_component-task_type = ms_standard_available-task_type.
read table mt_standards into ms_standard with key task_type = ms_standard_available-product_std parent_guid = ms_test_type-task_guid.
if ms_standard is not initial.
%>
<htmlb:checkbox id = "<%= ms_standard-task_type %><%= mv_counter %>"
text = "<%= ms_standard-task_type %>"
checked = "TRUE"
disabled = "TRUE" />
<br />
<%
clear ms_standard.
After displaying the already existing standards I also display other standards that are available for a component and might be selected.
else.
%>
<htmlb:checkbox id = "<%= ms_standard_available-product_std %><%= mv_counter %>"
text = "<%= ms_standard_available-product_std %>"
key = "<%= ms_test_type-task_type %>" />
<br />
<%
endif.
endif.
endloop.
%>
</td>
</htmlb:groupBody>
</htmlb:group>
<%
else.
After that I also loop over test types that are not existing yet. They and their corresponding standards can be selected in addition.
mv_counter = mv_counter + 1.
%>
<td valign="TOP">
<htmlb:group width="110px" >
<htmlb:groupHeader>
<htmlb:textView text = "<%= ms_test_type_available-test_type %>"
design = "EMPHASIZED" />
</htmlb:groupHeader>
<htmlb:groupBody>
<%
loop at mt_standards_available into ms_standard_available.
if ms_standard_available-test_type = ms_test_type_available-test_type and ms_component-task_type = ms_standard_available-task_type.
%>
<htmlb:checkbox id = "<%= ms_standard_available-product_std %><%= mv_counter %>"
text = "<%= ms_standard_available-product_std %>"
key = "<%= ms_test_type_available-test_type %>" />
<br />
<%
endif.
endloop.
%>
</td>
</htmlb:groupBody>
</htmlb:group>
</td>
<%
endif.
endloop.
%>
</tr>
</table>
</htmlb:groupBody>
</htmlb:group>
</xhtmlb:overflowContainer>
Message was edited by:
Stefan Grosskinsky
Message was edited by:
Stefan Grosskinsky
Message was edited by:
Stefan Grosskinsky
Sorry I have got some problems with formatting my code.
Message was edited by:
Stefan Grosskinsky
Message was edited by:
Stefan Grosskinsky -
Looping over a TreeMap with for|foreach
I am a student programmer and am impressed how the APIs for the different collections are very similar if not completely identical.
I used treemap.keySet() to loop over TreeMap<String, MyVeryOwnClass> successfully with a while loop. But it seems impossible to do the same with the newish for-each loop. Or have I missed the point somewhere?
Regards,
HedleyOkay, I've got the for/each loop working its way through my Applicant TreeMap as follows:
public String findApprovedApplcnt()
String applicantKey = "";
for (Map.Entry<String, Applicant> entry : applicantList.entrySet())
Applicant applicant = entry.getValue();
boolean approved = applicant.isApproved();
if (approved);
applicantKey = applicant.getApplcntKey();
// The String key is hashed and stored in an instance variable when object created.
// It is subsequently retrieved and used when the object is added to the tree map.
break;
return applicantKey;
} // findApprovedApplcnt(..)In the Applicant class is the flag 'private boolean approved = false;' (initially), accessed by the method .isApproved(). What the loop is supposed to do is examine each Applicant object applicant in turn, skip over those where approved = false, and grab the key of the first applicant where approved = true, then break out of the loop and return the key.
Trouble is, it is grabbing the key of the first applicant it encounters regardless of whether approved is either true or false! I have gone nuts over this, stepping through in the debugger, inserting println statements to check the value of approved when it is retrieved, attempting to desk check, etc.
So what is the obvious error to which I am completely blind?
Regards,
Sleepless in Melbourne -
I'm doing a scan around a line by sampling data 360 degrees for every value of z(z is the position on the line). So, that mean I have a double for-loop where I collect the data. The problem comes when I try to plot the data. How should I do?
Jonas,
I think what you want is a 3D plot of a cylinder. I have attached an example using a parametric 3D plot.
You will probably want to duplicate the points for the first theta value to close the cylinder. I'm not sure what properties of the graph can be manipulated to make it easier to see.
Bruce
Bruce Ammons
Ammons Engineering
Attachments:
Cylinder_Plot_3D.vi 76 KB -
I have this code:
if (s == "file")
file = false;
for (int i = 0; i < treeViewMS1.SelectedNodes.Count; i++)
DeleteFile(treeViewMS1.SelectedNode.FullPath, file);
I know it's a file and it is working if it's a single file.
On the treeView i click on a file right click in the menu i select delete and it's doing the line:
DeleteFile(treeViewMS1.SelectedNode.FullPath, file);
And it's working no problems.
But i want to do that if i selected some files togeather multiple selection then to delete each file.
So i added the FOR loop but then how do i delete from the SelectedNodes each node ?
The treeView SelectedNodes dosen't have FullPath like SelectedNode also doing SelectedNodes[i] dosen't have the FullPath property.
Same as for if i want to delete a single directory or multiple selected directories:
This is the continue of the code if it"s not a "file" (else) it's null i know it's a directory and doing:
else
file = true;
RemoveDirectoriesRecursive(treeViewMS1.SelectedNode, treeViewMS1.SelectedNode.FullPath);
Also here i'm using SelectedNode but if i marked multiple directories then i how do i loop over the SelectedNodes and send each SelectedNode to the RemoveDirectoriesRecrusive method ?
My problem is how to loop over SelectedNode(multiple selection of files/directories) and send each selected file/directory to it's method like i'm doing now ?foreach (TreeNode n in treeViewMS1.SelectedNodes)
// Remove everything associated with TreeNode n here
I don't think it's any harder than that, is it?
If you can multi-select both an item and one of its descendents in the tree, then you'll have the situation that you may have deleted the parent folder and all of its children by the time you get around to deleting the descendent. But that's not such
a big deal. A file can get deleted externally to your program too - so you'll just have to deal with it having been deleted already (or externally) when you get around to deleting it yourself. -
Hello,
I have a foreach loop in SSIS (as part of Visual Studio 10 and with SQL Server 2012).
It loops over all files in a folder (ForEach File Enumerator).
I set the folder: OK
Traverse Sub folders: OK
I have set up a Variable in Variable Mappings called FileName so it shows User::FileName: OK
Index of variable is 0: OK
It almost works ok. Except that the first file it finds is never considered.
I set a breakpoint then and the first file it finds, is shown in black in the watch variable window. All subsequent files found are shown in red font. When I change the names of the files so another file is the first file found then it skips the other one
which now is the first file.
What is going on here? Why does SSIS skip the first file it finds in a foreach file loop?
Any suggestions highly appreciated.
Thank you
Andi
Andreas"red font - interesting, any example to show us (image)
It would be interesting to share with us whether you use any file masks or expressions.
Arthur
MyBlog
Twitter
It appears a variable value turns red when it changes between breakpoints. It started black for the first value (the first file, obtained BEFORE the execution reached the breakpoint), and then turned red. I was able to reproduce this behavior on a test environment.
However, it did not skip any files.
OP, please set up the test shown in the image below. Create a breakpoint in the sequence container for the "OnPreExecute" event. -
Problem with Message-Mapping: Loop over Elements possible?
Hi all,
I want do create a Message-Mapping for an IDoc-to-File Scenario. In the Source Structure there are some Elements which can appear more than once (1..unbounded). I need a mechanism which loops over these elements and search for specified values. From the Element which contains an element with this specified value the mapping should write a value in the target structure.
Here a simple example (source structure) for better understanding:
<root>
<invoice>
<number> 10 </number>
<sum> 200.00 </sum>
</invoice>
<invoice>
<number> 20 </number>
<sum> 150.00 </sum>
</invoice>
<invoice>
<number> 30 </number>
<sum> 120.00 </sum>
</invoice>
</root>
Now the duty of the Mapping should be to search in the elements <invoice> for the number 30. And then the sum of the invoice with the number 30 should be written in a field of the target structure.
I tried it out with a constant togehter with an equalsS-function and an ifWithoutElse-function, but it is working only then, if the invoice with the number 30 has the first position in the root context.
Can anybody help me? Thanks
With kind regards
ChristopherHi,
Write a UDF to sum the required values and map to target node.
See while writing the UDF select the type as queue.
number -- removecontext-UDF targetnode
sum----removecontext--/
number abd sum or the two inputs
in UDF
int nsum = 0;
for(int i;i < number.length;i++){
if number(i).equals("30") then
nsum = nsum + valueOf(sum(i));
result.addValue(nsum); // convert the nsum into string
Regsrds
Chilla -
Message-Mapping: nested Loops over Elements
Hi Experts,
I have problems with my Message-Mapping in the IR. I have a source and a target structure. In the following I will give you easy examples of these structures:
<u>source structure:</u>
<E1EDP01>
<E1EDP19>
<QUALF> ... </QUALF>
<IDTNR> ... </IDTNR>
</E1EDP19>
<E1EDP19>
<QUALF> ... </QUALF>
<IDTNR> ... </IDTNR>
</E1EDP19>
</E1EDP01>
<E1EDP01>
<E1EDP19>
<QUALF> ... </QUALF>
<IDTNR> ... </IDTNR>
</E1EDP19>
<E1EDP19>
<QUALF> ... </QUALF>
<IDTNR> ... </IDTNR>
</E1EDP19>
</E1EDP01>
<u>target structure:</u>
<LineItem>
<IDTNR></IDTNR>
</LineItem>
<LineItem>
<IDTNR></IDTNR>
</LineItem>
That means:
For every <E1EDP01> in the source structure I create one <LineItem> in the target structure. One E1EDP01-Element can contain more than one E1EDP19-Elements. I have to loop over these E1EDP19-Elements, because I have to locate the Element <QUALF> with a given (fixed) value. The Mapping should put the value from the Element <IDTNR> from the source structure - where the QUALF-Element has this given value - in the IDTNR-Element of the target structure.
I tried it with a UDF, but only the first <IDTNR> in the target structure got filled.
Thanks for your help
ChristopherThank you,
but how I can set the Elements IDTNR and QUALF to the context E1EDP01?
In the splitByValue-Function do I need "each value"?
best regards
Christopher -
Hey Guys,
I am having a problem with cfloop. What I am trying to do is
calculate points on an Oline March Madness Pool. I need to evaluate
if the user picks are equal to the game winners. I can do it if I
manually type each pick # and each game # but I would much rather
loop over a cfset tag since there are 63 picks and games. You can
check out my code below to get a better idea of what I am trying to
do. While I know I can't include the #'s on the right side of the
cfset tag in this way I included them anyways to better illustrate
where I would like to loop it. Is there a way to do this, or will I
have to manually set each pick?<cfif getGames.game#l# EQ
userPoints[#userID#]["pick#l#"]>
I'm going to guess this is line 27 or very near it.
Your actual <cfset> line looks fine to me assuming all
the relevant keys
exist when they need to exist. I would have written it
something like:
<cfset userPoints[userID]["pick" & i] =
variables["pick" & i]>
The if statement should probably look like this:
<cfif getGames["game" & i] EQ
userPoints[userID]["pick" & i]>
All your index variables are the letter "i" and not the
number "1"
aren't they? I don't believe a singe number is a valid CF
variable name. -
Looping over fields from internal table
In a FM I have to check records of two ITABs against each other. Most fields can be checked 1:1 but some must be checked according to some business logic.
I first want to check field-by-field and then I want to deal with exceptions.
Question: How can I loop over fields in an ITAB in such a manner that I can compare fields?Hi, you can loop thru the columns(fields) of an internal table like so.
field-symbols: <fs>.
loop at itab.
do.
* Here you can use the field name instead of SY-INDEX
assign component sy-index of structure itab to <fs>.
if sy-subrc <>.
exit.
endif.
* Now that you have access to the field via field symbol, you can compare
* this value.
Write:/ <fs>.
enddo.
endloop.
Regards,
Rich Heilman -
Why optimizer prefers nested loop over hash join?
What do I look for if I want to find out why the server prefers a nested loop over hash join?
The server is 10.2.0.4.0.
The query is:
SELECT p.*
FROM t1 p, t2 d
WHERE d.emplid = p.id_psoft
AND p.flag_processed = 'N'
AND p.desc_pool = :b1
AND NOT d.name LIKE '%DUPLICATE%'
AND ROWNUM < 2tkprof output is:
Production
call count cpu elapsed disk query current rows
Parse 1 0.01 0.00 0 0 4 0
Execute 1 0.00 0.01 0 4 0 0
Fetch 1 228.83 223.48 0 4264533 0 1
total 3 228.84 223.50 0 4264537 4 1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 108 (SANJEEV)
Rows Row Source Operation
1 COUNT STOPKEY (cr=4264533 pr=0 pw=0 time=223484076 us)
1 NESTED LOOPS (cr=4264533 pr=0 pw=0 time=223484031 us)
10401 TABLE ACCESS FULL T1 (cr=192 pr=0 pw=0 time=228969 us)
1 TABLE ACCESS FULL T2 (cr=4264341 pr=0 pw=0 time=223182508 us)Development
call count cpu elapsed disk query current rows
Parse 1 0.01 0.00 0 0 0 0
Execute 1 0.00 0.01 0 4 0 0
Fetch 1 0.05 0.03 0 512 0 1
total 3 0.06 0.06 0 516 0 1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 113 (SANJEEV)
Rows Row Source Operation
1 COUNT STOPKEY (cr=512 pr=0 pw=0 time=38876 us)
1 HASH JOIN (cr=512 pr=0 pw=0 time=38846 us)
51 TABLE ACCESS FULL T2 (cr=492 pr=0 pw=0 time=30230 us)
861 TABLE ACCESS FULL T1 (cr=20 pr=0 pw=0 time=2746 us)sanjeevchauhan wrote:
What do I look for if I want to find out why the server prefers a nested loop over hash join?
The server is 10.2.0.4.0.
The query is:
SELECT p.*
FROM t1 p, t2 d
WHERE d.emplid = p.id_psoft
AND p.flag_processed = 'N'
AND p.desc_pool = :b1
AND NOT d.name LIKE '%DUPLICATE%'
AND ROWNUM < 2
You've got already some suggestions, but the most straightforward way is to run the unhinted statement in both environments and then force the join and access methods you would like to see using hints, in your case probably "USE_HASH(P D)" in your production environment and "FULL(P) FULL(D) USE_NL(P D)" in your development environment should be sufficient to see the costs and estimates returned by the optimizer when using the alternate access and join patterns.
This give you a first indication why the optimizer thinks that the chosen access path seems to be cheaper than the obviously less efficient plan selected in production.
As already mentioned by Hemant using bind variables complicates things a bit since EXPLAIN PLAN is not reliable due to bind variable peeking performed when executing the statement, but not when explaining.
Since you're already on 10g you can get the actual execution plan used for all four variants using DBMS_XPLAN.DISPLAY_CURSOR which tells you more than the TKPROF output in the "Row Source Operation" section regarding the estimates and costs assigned.
Of course the result of your whole exercise might be highly dependent on the actual bind variable value used.
By the way, your statement is questionable in principle since you're querying for the first row of an indeterministic result set. It's not deterministic since you've defined no particular order so depending on the way Oracle executes the statement and the physical storage of your data this query might return different results on different runs.
This is either an indication of a bad design (If the query is supposed to return exactly one row then you don't need the ROWNUM restriction) or an incorrect attempt of a Top 1 query which requires you to specify somehow an order, either by adding a ORDER BY to the statement and wrapping it into an inline view, or e.g. using some analytic functions that allow you specify a RANK by a defined ORDER.
This is an example of how a deterministic Top N query could look like:
SELECT
FROM
SELECT p.*
FROM t1 p, t2 d
WHERE d.emplid = p.id_psoft
AND p.flag_processed = 'N'
AND p.desc_pool = :b1
AND NOT d.name LIKE '%DUPLICATE%'
ORDER BY <order_criteria>
WHERE ROWNUM <= 1;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/
Maybe you are looking for
-
Auto allocation for a move order with an expired lot doesn't work
Hello everyone, We are facing a major problem regarding the use of move orders for issuing expired lots. Scenario: 1. Create a move order. Fill in: Item, Qty, Source Subinv and Lot. Lot is expired. 2. Approve move order. 3. Run "Move Order Pick Slip"
-
Inventory management in BW7.0
Hi, We have implemented 0IC_C03 in 7.X flow. We are facing a issue with the 2lis_03_BX load. Usually when this is loaded to the cube it gets loaded with record type '1' in 3.x flow but in 7.0 flow this gets loaded with record type 0 and when i do m
-
I am trying to upgrade to Lion. I need to go through Mac App store to buy it. I need to get the Mac App store icon in my dock. I have run Update Software several times, trying to get the Mac App store onto my iMac, but with no luck. It doesn't show u
-
I don't know if anyone else has had this experience but here is mine. By the way, I have tried repeatedly to contact Apple about this with no luck whatsoever. Beware! And, if you are Apple, please contact me, I've tried to contact you and am getting
-
Safari won't open web page that Firefox will open
Hello, I have a specific page on my website that Safari will not display but Firefox will. I have cleared the cache, cookies. Shut down everything, started up...no help. Any suggestions? Thanks in advance G5 iMac Mac OS X (10.4.6)