How to loop through dates using For Loop?
Hi All,
I assume the For Loop is the best way to loop through days in a date range, but I can't figure out how to add a day in the "AssignExpression" box. The following gets the errors "The expression contains unrecognized token 'DAY'",
and "Attempt to parse the expression 'DATEADD(DAY, 1, @CounterPlayer)' failed and returned error code 0xC00470A4."
InitExpression: @CounterPlayer = @DownloadFileDatePlayer
EvalExpression: @CounterPlayer <= @Today
AssignExpression: @CounterPlayer = DATEADD(DAY, 1, @CounterPlayer)
I need to step through days, not through files. What am I doing wrong here? I changed "DAY" to "Day," but that didn't fix it.
Thanks,
Eric
DOH! It just needed properly placed quotes. Here's the answer:
AssignExpression: @CounterPlayer = DATEADD("DAY", 1, @CounterPlayer)
Similar Messages
-
How to update multiple records using for loop
Hi I want to update a particular column of few rows in database i had written followin code after that few lines of code and calling action from the task which having commit return ,still it's not updating particular colum.I had debug the code loop is running fine but still changes are not reflecting to database.Let me know if there is any prob with following code snippet.
RealEstatePropertyUnitDetailsVOImpl realEstatePropertyUnitDetailsVO = RealEstatePropertyUnitDetailsVOImpl)realEstateService.getRealEstatePropertyUnitDetailsVO();
for(Row row : realEstatePropertyUnitDetailsVO.getAllRowsInRange())
if("N".equalsIgnoreCase((String)row.getAttribute("RlstdSellYn"))
|| "false".equalsIgnoreCase((String)row.getAttribute("RlstdSellYn")))
row.setAttribute("RlstdAvlblYn", "Y" );
System.out.println("RlsthId "+row.getAttribute("RlstdRlsthId"));
System.out.println("AvlbYN "+row.getAttribute("RlstdAvlblYn"));
System.out.println("RlstdUnitId "+row.getAttribute("RlstdUnitId"));
}Vishwesh,
I'd start with something along the lines of ...
RowSet vo = (RowSet)getRealEstatePropertyUnitDetailsVO();
vo.reset();
while (vo.hasNext())
Row row = vo.next();
row.setAttribute("Attribute", value);
}getAllRowsInRange() may exclude some rows outside the "range". Also, the vo.reset is needed since your View Object currency may not be at the beginning of your RowSet.
Hope that helps.
Will -
How do I use For loop to check each node and import them to a new document?
In my function I would like to use a For loop to get all the statutes (xml) inside the object
objXmlBcaResponseDoc. In my case there are 2 statutes. I would like the output to look like the one I have posted here below. I am not sure how to do the For loop. The commented For loop is from another function but it is not working inside
this function.
The output is added into the **objXmlResponseMessageDoc** object and should look like this with 2 statutes (ns1:Statute) and a totalCount=2
<BasicSearchQueryResponse xmlns="http://crimnet.state.mn.us/mnjustice/statute/service/4.0">
<StatutesXml>
<Statutes runType="Request" runDateTime="2015-03-17T10:23:04" totalCount="2">
<ns1:Statute xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0">
<StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">8471</StatuteId>
<Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">60</Chapter>
<Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">55</Section>
<Subdivision xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
</ns1:Statute>
<ns1:Statute>
<StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">9722</StatuteId>
<Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">90</Chapter>
<Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">25</Section>
<Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
</ns1:Statute>
</Statutes>
</StatutesXml>
</BasicSearchQueryResponse>
My xml doc is found inside objXmlBcaResponseDoc Here is xml inside
objXmlBcaResponseDoc object
<BasicSearchQueryResponse xmlns="http://crimnet.state.mn.us/mnjustice/statute/service/4.0">
<ns1:Statutes xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0">
<ns1:Statute>
<StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">8471</StatuteId>
<Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">60</Chapter>
<Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">55</Section>
<Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
</ns1:Statute>
<ns1:Statute>
<StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">9722</StatuteId>
<Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">90</Chapter>
<Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">25</Section>
<Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
</ns1:Statute>
</BasicSearchQueryResponse>
Here is my function
Function GetStatutesByChapter(ByVal aobjXmlGetStatuteRequestNode As XmlNode, ByVal aobjXMLNameSpaceManager As XmlNamespaceManager, ByVal aobjBroker As ServiceCatalog.Library.v4.Broker) As XmlDocument
Dim objXmlRequestMessageDoc As XmlDocument
Dim objXmlResponseMessageDoc As XmlDocument
Dim intCount As Integer
aobjBroker.PostMessageWarehouseInformationalMessage("Chapter found.", 1)
objXmlResponseMessageDoc = New XmlDocument
'Add the first element into the document GetStatuteByChapter with its namespace
objXmlResponseMessageDoc.AppendChild(objXmlResponseMessageDoc.CreateElement("BasicSearchQueryResponse", "http://crimnet.state.mn.us/mnjustice/statute/service/4.0"))
'Build the initial response document
objXmlResponseMessageDoc = New XmlDocument
'Add the first element into the document GetStatutesResponse with its namespace
objXmlResponseMessageDoc.AppendChild(objXmlResponseMessageDoc.CreateElement("GetStatutesResponse", "http://www.courts.state.mn.us/StatuteService/1.0"))
'Add a child node to the GetStatutesResponse node
objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.CreateElement("StatutesXml", "http://www.courts.state.mn.us/StatuteService/1.0"))
objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.CreateElement("Statutes", "http://www.courts.state.mn.us/StatuteService/1.0"))
'Convert the node Statutes into an element and set the runType attribute (runType="Request") by adding it's value Request
CType(objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("runType", "Request")
'Convert the node Statutes into an element and set the attribute (runDateTime="2015-03-05T10:29:40") by adding it
CType(objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("runDateTime", Format(Now, "yyyy-MM-ddTHH:mm:ss"))
'Create the BCA request message
objXmlRequestMessageDoc = New XmlDocument
objXmlRequestMessageDoc.AppendChild(objXmlRequestMessageDoc.CreateElement("ns:BasicSearchQueryRequest", aobjXMLNameSpaceManager.LookupNamespace("ns")))
objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns1:BasicSearchCriteria", aobjXMLNameSpaceManager.LookupNamespace("ns1")))
objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Chapter", aobjXMLNameSpaceManager.LookupNamespace("st")))
objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Section", aobjXMLNameSpaceManager.LookupNamespace("st")))
objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Subdivision", aobjXMLNameSpaceManager.LookupNamespace("st")))
'Uncomment last working section below
objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Chapter", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Chapter", aobjXMLNameSpaceManager).InnerText
'check if there is a section and or subdivision if it is there then set the value
If Not (aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager) Is Nothing) Then
objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Section", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager).InnerText
End If
If Not (aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Subdivision", aobjXMLNameSpaceManager) Is Nothing) Then
objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Subdivision", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Subdivision", aobjXMLNameSpaceManager).InnerText
End If
'check if there is a section and or subdivision if it is there then set the value
aobjBroker.PostMessageWarehouseSnapshot(objXmlRequestMessageDoc.OuterXml, "Request Message", 1)
'Call the BCA service
intCount = 0
'This is where I want to use a For loop to check for the statutes found using the Chapter
'Loop through each Id
'For Each objXmlStatuteIdNode In aobjXmlGetStatuteRequestNode.SelectNodes("ss:Statute/ss:StatuteId/ss:Id[string-length(.)>0]", aobjXMLNameSpaceManager)
'Create the BCA request message
'objXmlRequestMessageDoc = New XmlDocument
'objXmlRequestMessageDoc.AppendChild(objXmlRequestMessageDoc.CreateElement("ns:SingleStatuteRequest", aobjXMLNameSpaceManager.LookupNamespace("ns")))
'objXmlRequestMessageDoc.SelectSingleNode("ns:SingleStatuteRequest", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns:statuteId", aobjXMLNameSpaceManager.LookupNamespace("ns")))
'objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns:statuteId", aobjXMLNameSpaceManager).InnerText = objXmlStatuteIdNode.InnerText aobjBroker.PostMessageWarehouseSnapshot(objXmlRequestMessageDoc.OuterXml, "Request Message", 1)
'intCount = intCount + 1
'objXmlBcaResponseDoc = New XmlDocument
'File name is BCASearchQueryResponse.xml
'objXmlBcaResponseDoc.Load("\\j00000swebint\mscapps\deve\appfiles\temp\BCASearchQueryResponse.xml")
'objXmlResponseMessageDoc.DocumentElement.SelectSingleNode("ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.ImportNode(objXmlBcaResponseDoc.DocumentElement.SelectSingleNode("ns1:Statute", aobjXMLNameSpaceManager), True))
'Next
'Count how many Statute nodes found
CType(objXmlResponseMessageDoc.SelectSingleNode("ss:BasicSearchQueryResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("totalCount", CStr(intCount))
Return objXmlResponseMessageDoc
End FunctionWhat is XPath and what does it do that you're impressed with?
Yes, I see your link, but give me the abbreviated elevator speech on what it is please. It has me curious.
http://searchsoa.techtarget.com/definition/XPath
http://www.techrepublic.com/article/easily-navigate-xml-with-vbnet-and-xpath/
http://www.techrepublic.com/article/using-xpath-string-functions-in-xslt-templates/
The way that all this is being used by me now on a project is the HTML controls on the screen are built by XML not only about what the controls are and their attributes, but the data from from the database is XML too with both going through transfermations
vis XSLT as the HTML controls are built dynamically by XML data for the controls and the XML database data with decision being made in the transfermation on the fly.
There are many usages with Xpath not just this one I am talking about with Xpath. You can do the same kind of thing with XAML and WPF forms as they are dynamically built. But it goes well beyond what I am talking about and the usage of Xpath. Xpath 3.0
is the latest version.
http://www.balisage.net/Proceedings/vol10/html/Novatchev01/BalisageVol10-Novatchev01.html
Thanks - I'll look into that at some point.
Still lost in code, just at a little higher level. -
How do i sweep two voltage at the same time by using for loop ?
Hello, Can anyone help me on this topic ?
My problem is to sweep Vds and Vgs as same time vs Id in MOSFET by using for loop. I also use the Agilent power supply source. Let me tell a litle bit about what i'm doing. For different value of Vds, i will get Vgs vs Id curve. (The x axis is Vgs, the y-axis is Id).
I started to create two for-loop, the inner to sweep Vgs, and the outer one to sweep Vds. My problem is don't know how to connect all the wire in the for loop.
In the for loop i saw N, i icon. Suppose I have the two variable for Vgs such as Vgs start and Vgs_stop. Should the Vgs_start( or Vgs_stop) be connected to N or leave it in the for_loop ?
for example: I want to sweep Vgs from 0(for Vgs_start) to 5(Vgs_strop) V, and the step increment is .5V how do i connect these variables in the for loop ?
Thank you for your time
Ti NguyenIt is easier to use a while loop. Dennis beat me to the punch. Here is my solution:
You can remove the flat sequence structure if you use Error In and Error Out to ensure the execution flow will occur in the proper order. Be sure to include the delay time in the loop so that your vi doesn't hog all the CPU time.
Message Edited by tbob on 10-17-2005 01:00 PM
- tbob
Inventor of the WORM Global
Attachments:
RampVoltage.PNG 8 KB -
How to iterate List in jsp without using for loop
Hi,
I am developing a small application is struts. I have one ActionForm file which contain one List like getEmployeeDetailsList(). When I am using this list in jsp page for displaying data. I want to display it as employee name, employee address, employee designation and employee contact no. These all fields are available in the above list. Now what is the problem is that I am using logic:iterate method to iterate data. but this is not sufficient to display all records in order. like employee name should be in one table and they can be vertical not horizontal, employee address is also should be seperate. and same thing with employee designation and contact no. I don't want to use for loop to iterate this list. Please tell me about optionCollection for this list. only employee names should be one drop down and employee designation is also in another drop down.
Please help. It is really urgent.
Any help will be appreciated.
Thanks in advance.
ManveerI'm not sure what you problem is, but one thing you can do is to create a new class and pass the list into its constructor (and store it as a private variable). Then, provide a set of functions in the new class that extracts data from the list and returns it in a form that the various parts of the JSP page wants. For example, one function may return a sorted list of just the employee names. In this way, all the business logic for formatting the data into a form that JSP page likes is hidden inside the new class.
-
How do I go about this? Creating table while looping through dates?
How do I do this? Creating table while looping through dates?
I have a table with information like:
ID---Date---Status
1-------04/23-----Open
1-------04/25-----Open
2-------04/24-----Closed
3-------04/26-----Closed
What I want to do is create another table based on this per ID, but have all the dates/statuses on the same line as that ID number (as additional columns). The problem is that the number of columns needed is to be dynamically decided by the number of dates.
To illustrate my example, I'm looking to achieve the following:
ID---04/23 Status---04/24--Status---04/25--Status---04/26--Status
1----Open--------------<null>-------------Open---------------<null>
2----<null>------------Closed-------------<null>-------------<null>
3----<null>------------<null>-------------<null>-------------Closed
What would be the best way to go about this?
Can someone please point me in the right direction?
Would I need to do some looping?
Thanks in advance!thedunnyman wrote:
How do I do this? Creating table while looping through dates?
I have a table with information like:
ID---Date---Status
1-------04/23-----Open
1-------04/25-----Open
2-------04/24-----Closed
3-------04/26-----Closed
What I want to do is create another table based on this per ID, but have all the dates/statuses on the same line as that ID number (as additional columns). The problem is that the number of columns needed is to be dynamically decided by the number of dates.
To illustrate my example, I'm looking to achieve the following:
ID---04/23 Status---04/24--Status---04/25--Status---04/26--Status
1----Open--------------<null>-------------Open---------------<null>
2----<null>------------Closed-------------<null>-------------<null>
3----<null>------------<null>-------------<null>-------------Closed
What would be the best way to go about this?
Can someone please point me in the right direction?
Would I need to do some looping?
Thanks in advance!I hope you are asking about writing a query to DISPLAY the data that way ... not to actually create such a massively denormalized table .... -
How do I find the range of a bunch of #'s using for loops?
I have a program that gets 13 numbers from the user and I nned to find the range of them. How do I do this with for loops?
This is what I have so far
if (one > two && one > three && one > four && one > five && one > six && one > seven && one > eight && one > nine && one > ten && one > eleven && one > twelve && one > thirteen)
big = one;
else if (two > one && two > three && two > four && two > five && two > six && two > seven && two > eight && two > nine && two > ten && two > eleven && two > twelve && two > thirteen)
big = two;
else if (three > two && three > one && three > four && three > five && three > six && three > seven && three > eight && three > nine && three > ten && three > eleven && three > twelve && three > thirteen)
big = three;
else if (four > two && four > three && four > one && four > five && four > six && four > seven && four > eight && four > nine && four > ten && four > eleven && four > twelve && four > thirteen)
big = four;
else if (five > two && five > three && five > four && five > one && five > six && five > seven && five > eight && five > nine && five > ten && five > eleven && five > twelve && five > thirteen)
big = five;
else if (six > two && six > three && six > four && six > five && six > one && six > seven && six > eight && six > nine && six > ten && six > eleven && six > twelve && six > thirteen)
big = six;
else if (seven > two && seven > three && seven > four && seven > five && seven > six && seven > one && seven > eight && seven > nine && seven > ten && seven > eleven && seven > twelve && seven > thirteen)
big = seven;
else if (eight > two && eight > three && eight > four && eight > five && eight > six && eight > seven && eight > one && eight > nine && eight > ten && eight > eleven && eight > twelve && eight > thirteen)
big = eight;
else if (nine > two && nine > three && nine > four && nine > five && nine > six && nine > seven && nine > eight && nine > one && nine > ten && nine > eleven && nine > twelve && nine > thirteen)
big = nine;
else if (ten > two && ten > three && ten > four && ten > five && ten > six && ten > seven && ten > eight && ten > nine && ten > one && ten > eleven && ten > twelve && ten > thirteen)
big = ten;
else if (eleven > two && eleven > three && eleven > four && eleven > five && eleven > six && eleven > seven && eleven > eight && eleven > nine && eleven > ten && eleven > one && eleven > twelve && eleven > thirteen)
big = eleven;
else if (twelve > two && twelve > three && twelve > four && twelve > five && twelve > six && twelve > seven && twelve > eight && twelve > nine && twelve > ten && twelve > eleven && twelve > one && twelve > thirteen)
big = twelve;
else if (thirteen > two && thirteen > three && thirteen > four && thirteen > five && thirteen > six && thirteen > seven && thirteen > eight && thirteen > nine && thirteen > ten && thirteen > eleven && thirteen > twelve && thirteen > one)
big = thirteen;
if (one < two && one < three && one < four && one < five && one < six && one < seven && one < eight && one < nine && one < ten && one < eleven && one < twelve && one < thirteen)
little = one;
else if (two < one && two < three && two < four && two < five && two < six && two < seven && two < eight && two < nine && two < ten && two < eleven && two < twelve && two < thirteen)
little = two;
else if (three < two && three < one && three < four && three < five && three < six && three < seven && three < eight && three < nine && three < ten && three < eleven && three < twelve && three < thirteen)
little = three;
else if (four < two && four < three && four < one && four < five && four < six && four < seven && four < eight && four < nine && four < ten && four < eleven && four < twelve && four < thirteen)
little = four;
else if (five < two && five < three && five < four && five < one && five < six && five < seven && five < eight && five < nine && five < ten && five < eleven && five < twelve && five < thirteen)
little = five;
else if (six < two && six < three && six < four && six < five && six < one && six < seven && six < eight && six < nine && six < ten && six < eleven && six < twelve && six < thirteen)
little = six;
else if (seven < two && seven < three && seven < four && seven < five && seven < six && seven < one && seven < eight && seven < nine && seven < ten && seven < eleven && seven < twelve && seven < thirteen)
little = seven;
else if (eight < two && eight < three && eight < four && eight < five && eight < six && eight < seven && eight < one && eight < nine && eight < ten && eight < eleven && eight < twelve && eight < thirteen)
little = eight;
else if (nine < two && nine < three && nine < four && nine < five && nine < six && nine < seven && nine < eight && nine < one && nine < ten && nine < eleven && nine < twelve && nine < thirteen)
little = nine;
else if (ten < two && ten < three && ten < four && ten < five && ten < six && ten < seven && ten < eight && ten < nine && ten < one && ten < eleven && ten < twelve && ten < thirteen)
little = ten;
else if (eleven < two && eleven < three && eleven < four && eleven < five && eleven < six && eleven < seven && eleven < eight && eleven < nine && eleven < ten && eleven < one && eleven < twelve && eleven < thirteen)
little = eleven;
else if (twelve < two && twelve < three && twelve < four && twelve < five && twelve < six && twelve < seven && twelve < eight && twelve < nine && twelve < ten && twelve < eleven && twelve < one && twelve < thirteen)
little = twelve;
else if (thirteen < two && thirteen < three && thirteen < four && thirteen < five && thirteen < six && thirteen < seven && thirteen < eight && thirteen < nine && thirteen < ten && thirteen < eleven && thirteen < twelve && thirteen < one)
little = thirteen;
I'm trying to fix this so it's not so confusing with for loops -
I stuck with a problem that I am using FOR loop for generating repeating nodes.
Now when I concat the generated node in the main node then I got only last iteration of that FOR loop.
can anybody suggest me a way to handle this error....
FOR i IN 1..pl_phone_tab.Count
LOOP
SELECT xmlelement("Phone"
,xmlelement("PHONETYPE",xmlattributes('01' AS "dmnADRP_PHONETYPE"),pl_phone_tab(i).p_phtype_tab)
,xmlelement("PHONENUM",pl_phone_tab(i).p_phnum_tab)
,xmlelement("PRIMARY_CONTACT",pl_phone_tab(i).p_prcon_tab)
INTO p_phone_xml
FROM dual; END LOOP;
SELECT xmlelement("PhoneInfo"
,xmlconcat(p_phone_xml))
INTO p_phone_info_xml
FROM dual;
here I am getting only one node but there has to be two nodes for PHONE nodeNot that I'm encouraging you but here are two standalone examples explaining how to do what you want :
1) Loop through the input collection and append each node to its target container :
SQL> declare
2
3 type t_emp_tab is table of scott.emp%rowtype;
4
5 emp_tab t_emp_tab;
6 emp_info_xml xmltype;
7 emp_xml xmltype;
8
9 begin
10
11 -- filling emp_tab with data
12 select e.*
13 bulk collect into emp_tab
14 from scott.emp e
15 where e.deptno = 10;
16
17 emp_info_xml := xmltype('<EmpInfo/>');
18
19 -- looping through emp collection and appending to EmpInfo element
20 for i in 1 .. emp_tab.count loop
21 select appendchildxml(
22 emp_info_xml
23 , '/*'
24 , xmlelement("Emp"
25 , xmlattributes(emp_tab(i).empno as "id")
26 , xmlforest(
27 emp_tab(i).ename as "Name"
28 , emp_tab(i).job as "Job"
29 )
30 )
31 )
32 into emp_info_xml
33 from dual;
34 end loop;
35
36 dbms_output.put_line(emp_info_xml.getclobval(1,2));
37
38 end;
39 /
<EmpInfo>
<Emp id="7782">
<Name>CLARK</Name>
<Job>MANAGER</Job>
</Emp>
<Emp id="7839">
<Name>KING</Name>
<Job>PRESIDENT</Job>
</Emp>
<Emp id="7934">
<Name>MILLER</Name>
<Job>CLERK</Job>
</Emp>
</EmpInfo>
PL/SQL procedure successfully completed
2) Build a secondary collection of XML nodes and use XMLAgg to aggregate them in one go :
SQL> declare
2
3 type t_emp_tab is table of scott.emp%rowtype;
4
5 emp_tab t_emp_tab;
6 emp_info_xml xmltype;
7 emp_xml_tab xmlsequencetype := xmlsequencetype();
8
9 begin
10
11 -- filling emp_tab with data
12 select e.*
13 bulk collect into emp_tab
14 from scott.emp e
15 where e.deptno = 10;
16
17 -- looping through emp collection and appending to the collection of Emp nodes
18 for i in 1 .. emp_tab.count loop
19
20 emp_xml_tab.extend;
21
22 select xmlelement("Emp"
23 , xmlattributes(emp_tab(i).empno as "id")
24 , xmlforest(
25 emp_tab(i).ename as "Name"
26 , emp_tab(i).job as "Job"
27 )
28 )
29 into emp_xml_tab(i)
30 from dual;
31
32 end loop;
33
34 select xmlelement("EmpInfo", xmlagg(t.column_value))
35 into emp_info_xml
36 from table(emp_xml_tab) t ;
37
38 dbms_output.put_line(emp_info_xml.getclobval(1,2));
39
40 end;
41 /
<EmpInfo>
<Emp id="7782">
<Name>CLARK</Name>
<Job>MANAGER</Job>
</Emp>
<Emp id="7839">
<Name>KING</Name>
<Job>PRESIDENT</Job>
</Emp>
<Emp id="7934">
<Name>MILLER</Name>
<Job>CLERK</Job>
</Emp>
</EmpInfo>
PL/SQL procedure successfully completed
Both solutions give the same output.
Test them both and see which one fits better into your scenario. -
Will using for loop decrease the performance
Hi,
Will using for loop with a query decrease the performance.
for r_row in (select * from table) Loop
end loop.
This is done inside another for loop, most of the cases it returns only one value.
will it decrease the peformance of the procedure.
kindly advice.......
Regards,
Baluuser575682 wrote:
Will using for loop with a query decrease the performance.
for r_row in (select * from table) Loop
end loop.
This is done inside another for loop, most of the cases it returns only one value.
will it decrease the peformance of the procedure.Perhaps it is better to understand just what this PL/SQL loop construct does.
PL/SQL is two languages. It is PL (programming logic code) like Pascal or C or Java. You can use a 2nd language inside it called SQL. The PL engine is clever enough to recognise when the 2nd language is used. And it compiles all the stuff that is needed for the PL engine to call the SQL engine, pass data to the SQL engine and get data back, etc. (compare this with the complexity of using the SQL language in Pascal or C or Java).
So what does that loop do? The PL engine recognises the SQL SELECT statement. It creates an implicit cursor by calling the SQL engine to parse it (hopefully a soft parse) and then execute it.
As part of the PL loop, the PL engine now calls the SQL engine to fetch the data (rows) from the cursor. With 10g and later, the PL engine is smart enough to use implicit bulk processing.
Prior to 10g it used to fetch a row from the SQL engine, do the loop, fetch the next row, do the loop, etc. This means if there is a 1000 rows to fetch, it will call the SQL engine a 1000 times.
With 10g and later it will fetch a 100 rows, store that in an internal buffer and then do the loop a 100 times. With a 1000 rows to fetch, it now only requires 10 bulk fetches instead of a 1000 single row fetches.
These fetches require a context switch - as the PL engine has to step out and into the SQL engine and back, to fetch a row. This is an overhead and thus can become slow the more context switching there is.
And this is the basics for this loop (and most other cursor loops) construct in PL/SQL.
The ideal is to reduce the number of context switches. This is an overhead that can impact on performance.
What about using a loop within a loop. Also "bad". This uses the outer loop to fetch data. This data is then used to drive the fetch in the inner or nested loop. So the outside loop pulls data from the SQL engine into PL variables. The inside loop pushes that very same data back to the SQL engine.
Why? It would have been a lot faster no to pull and push that data between the loops using PL.
It will be a lot faster doing it via SQL only. Write both loops as a single SQL statement and have the SQL engine directly drive these loops itself. This is called a JOIN in SQL. And the SQL engine can do it not only faster, but it has some froody algorithms that can be used that are even faster than a nested loop process (called merge joins, hash joins, etc).
Bottom line. Maximise SQL. Minimise PL.*
Do as much of your data crunching in SQL as possible. SQL is the best and fastest "place" to process data. Not PL (or Pascal/C/Java). -
How to let " i " of a for loop to start from a "X"
Hi,
how to let " i " of a for loop to start from a value "x" where x is a variable?
Thx
Message Edited by starfish on 10-19-2007 06:00 AMHi starfish,
use it like this:
If this doesn't fit your needs you should attach an example of what you really need!
Message Edited by GerdW on 10-19-2007 01:15 PM
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome
Attachments:
I.png 2 KB -
Is meta data used for SEO if so how dose it work ?
Is meta data used for SEO? I would like to know how to create meta data for SEO use. I found this on a form with the label mete data for SEO. Can anyone help me understand what the parts of this code are used for?
<title>epecho | The visual works of Danel Roldán</title>
<meta name="verify-v1" content="+Yjk73MkziQFeIPyBcJtgXwi2LcwfLnAMazU0KtigIA=" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="epecho is a creative studio founded by designer Danel Roldán in 2004. Located in New Jersey, epecho serves clientele locally, nationally and internationally.
epecho focuses on logo design, corporate and brand identity and works closely with providers of multimedia, illustration and production of internet and print marketing campaigns. For more information please contact epecho. For a direct quote, please complete and submit the online application form." />
<meta name="keywords" content="logo, logos, logo design, logo designs, brand, brands, branding, brand design, brand designs, design, designer, graphic, graphic designer, danel, danel roldán, roldán, jersey, new jersey, geneva, lausanne, cross, genève, graphiste, logotype, font, type, typeface" />
<meta name="author" content="Danel Roldán" />
<meta name="copyright" content="(c) 2009 epecho" />Vinay has given you some good links, but I'll add a little bit more :-)
<meta name="verify-v1" content="+Yjk73MkziQFeIPyBcJtgXwi2LcwfLnAMazU0KtigIA=" />
That is a verification code, supplied via google if you have signed up for the WebMaster Tools:
https://www.google.com/webmasters/tools/
It allows you to check some stats etc., once you have added the verification code to your page.
The only other Meta Tags you really need to use are the <Title> tag and the Description tag.
The rest of SEO is making sure that the web pages are SE friendly. Not many SEs take into account all those meta-tags these days.
Make sure that keywords are scattered through the pages, make sure that the <h1> and <h2> heading tags use words that are important to site as they help with SEO as well.
SEO can't be mastered in a day - there are people that do this full time and even they are constantly learning new ways to ensure good rankings in the SEs. :- ) It's not dificult, but does take persistence !
Google's SEO Starter Guide (PDF)
http://www.google.com/webmasters/docs/search-engine-optimization-starter-guide.pdf
High Rankings Advisor
http://www.highrankings.com/newsletter/
SEOMoz.org - Beginner's Guide to SEO (1-page html)
http://www.seomoz.org/article/beginners-1-page
SEO Chat
http://www.seochat.com/ -
Hi guys,
I am testing out array. How do I create a 1D array of x-y using for loop?Nextal wrote:
I am testing out array. How do I create a 1D array of x-y using for loop?
OK, first of all you did not say what the array should contain. If you want an array that has one array element for each iteration of the while loop, you need to first think a bit harder. Your outer loop has no wait, thus it will spin millions of times per second and you will run out of memory soon, no matter how much memory you have. How many times should the while loop iterate? If you know the number before the program starts, you would use a FOR loop and autoindex at the loop boundary.
If you want to use a whiile loop, you need a mechanism to keep the array size reasonable. For small final arrays, you can just build the array in a shift register if you need it updated as it happens. If you only need the array after the loop stops, you can autoindex at the right loop boundary.
In any case, you should take a step back and decide what you really want. Currently the specifications are very vague and unreasonable.
LabVIEW Champion . Do more with less code and in less time . -
Incrementing var_(x) to var_(y) using FOR loop
How can i keep incrementing var_(x) to var(y) using FOR loop.
I want variables var_1 to var_3 displayed. So I tried the below mentioned method. But i got error.
SQL> set serveroutput on
declare
var_1 number;
var_2 number;
var_3 number;
begin
var_1:=884;
var_2:=646;
var_3:=213;
for i in 1..3 loop
dbms_output.put_line(var_(i));
end loop;
end;
SQL> /
dbms_output.put_line(var_(i));
ERROR at line 10:
ORA-06550: line 10, column 26:
PLS-00201: identifier 'VAR_' must be declared
ORA-06550: line 10, column 5:
PL/SQL: Statement ignoredThank you Padders. I have a complex requirement involving an UPDATE. To avoid unnecessary lines/repeat of UPDATE statements i somehow have to increase the variable number from var_(x) to var_(y)
-
how do you remove back up data from the memory storage? my storage data states that i have over 80gb of data used for back ups and i dont know why as i use a external hard drive as a time machine .now my 250gb flash storage is nearly full.. HELP!
When Time Machine backs up a portable Mac, some of the free space will be used to make local snapshots, which are backup copies of recently deleted files. The space occupied by local snapshots is reported as available by the Finder, and should be considered as such. In the Storage display of System Information, local snapshots are shown as Backups. The snapshots are automatically deleted when they expire or when free space falls below a certain level. You ordinarily don't need to, and should not, delete local snapshots yourself. If you followed bad advice to disable local snapshots by running a shell command, you may have ended up with a lot of data in the Other category. Ask for instructions in that case.
See this support article for some simple ways to free up storage space. -
Procedure to insert same record for 30 times in a table using for loop
Hi,
I need to insert a record in a table which has to be iterated using for loopI think you are in the wrong forum. You can do that like this:
CREATE TABLE my_table (my_column NUMBER);
BEGIN
FOR i IN 1 .. 30
LOOP
INSERT INTO my_table
(my_column
VALUES (i
END LOOP;
END;
/Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.apress.com/9781430235125
http://apex.oracle.com/pls/apex/f?p=31517:1
http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
-------------------------------------------------------------------
Maybe you are looking for
-
Can an swf movie be opened on a specific frame?
When I call up an Flash-generated swf movie in its own browser window via a navigation bar button, it always open on its first frame. Is there a way to tell the browser in conjunction with the getURL command to open at a specific frame other than fra
-
My old messages do not show on my new iphone 6.
I am able to send new messages and they show in the log but none of my old messages show anymore. I just moved from my old faithful iPhone 4s to the iPhone 6.
-
Hey all I have this issue/ question that is related to the scheduling if we have scheduled a report to run every morning, this report is based on parameter that the user has to enter the values for based on which value of the parameter the report wil
-
I have about 800 songs in my itunes library and only 300 are syncing onto my iPhone. Is there a way to fix this?
-
Pager Element in PCUI result list
Hi, Am facing a very peculiar issue(s) described below, if anyone has faced this issue or has a solution i look forward to their replies on the same The pager element on the result list screen of the PCUI application seems to be resetting to 1. When