For Loop with parameter in application process
Hello,
I am working on a project for school and a loop in an application process is giving me a headache. I have an application from which I make an ajax call to an "on-demand" process. Here's a short version of the process:
declare
valuesList varchar2(32000) := '';
sqlWhere varchar2(32000) := '';
begin
begin
//calculations, but let's hard code sqlWhere for demonstration purposes
sqlWhere := ' where ID = 50';
for j in (select * from myview sqlWhere) loop
valuesList :=valuesList || '~rowsep~' || j.id || '~colsep~' || j.beds;
end loop;
exception
when no_data_found then null;
when others then HTP.p('Error: ' || SQLERRM);
valuesList := substr(valuesList, 9, length(valuesList));
end;
htp.prn(valuesList);
end;
I thought the for loop would contain only one record but it lists all records in the view. Interestingly, when I replace the loop condition to 'select * from myview where ID = 50' it returns what it's supposed to.
Could someone please explain what I am doing wrong?
Thank you!
There are a couple of different options but using a variable in the sql statement and not the where clause needs an execute immediate. The link below gives a good overview and options to accomplish what you are trying to do.
execute immediate with for loop
Edited by: tread on Apr 23, 2012 1:09 PM
Similar Messages
-
the demand of my application is that i can not replace for loop with a while loop.because i need fixed number of iterations and as far as i know fixed iterations could be only with possible with the for loop.
your recommended second option that i could add true/false case.
this true/false case must be inside the for loop or outside the for loop?if this case is inside the for
loop, how can i send stop command from outer while
loop?
more over do you have any example for this please?
thanks"You can execute a fixed number of iterations using a while loop by comparing the iteration count to the number of iterations you want and wiring the output of that comparison (e.g. Less Than or Equal To) to the continue (or stop) terminal of your while loop. Which comparison you use depends on personal preference, where you wire the desired count and the interation count, and whether you're using the while loop as Continue if True or Stop if True.
Ben gave you step-by-step instructions in response to your previous question. Look here for Ben's response.
Ben's response looks pretty good and detailed to me. It certa
inly deserved better than a 1-star rating. -
Display a message in a For Loop with field value
Hello All,
pls,i wanna display a message in a For Loop with field value the code is:
FOR Q1 IN GET_SUM_EXP_QUANTITY LOOP .
INSERT INTO PLN_PLAN_DISTRIBUTION_WAY
(FIN_YEAR_CODE , MONTH_CODE , MATERIAL_CODE , DISTRIBUTION_WAY , EXPECTED_QUANTITY , GROUP_CODE)
VALUES (:PLN_PLAN.FIN_YEAR_CODE , TO_CHAR(V_FROM_DATE,'MM') , Q1.MATERIAL_CODE , 1 , V_MONTHLY_QTY , Q1.GROUP_CODE);
MESSAGE(':PLN_PLAN.FIN_YEAR_CODE'||:PLN_PLAN.FIN_YEAR_CODE ||' '||'V_FROM_DATE = '||TO_CHAR(V_FROM_DATE,'MM'), 'Q1.MATERIAL_CODE'||' '|| Q1.MATERIAL_CODE||' '||'DISTRIBUTION_WAY'||' = 1'||'EXPECTED_QUANTITY'||' = '|| V_MONTHLY_QTY||'GROUP_CODE'|| ' '|| Q1.GROUP_CODE);
FORMS_DDL('COMMIT');
How 2 display a message with the value:
Q1.MATERIAL_CODE
Q1.GROUP_CODE
message(Q1.MATERIAL_CODE)
gave me numeric or value error on run time when pressed on button
Regards,
Abdetu..Thanks 4 reply..
again they r in a For Loop as mentioned above...
INSERT INTO PLN_PLAN_DISTRIBUTION_WAY
(FIN_YEAR_CODE , MONTH_CODE , MATERIAL_CODE , DISTRIBUTION_WAY , EXPECTED_QUANTITY , GROUP_CODE)
VALUES (:PLN_PLAN.FIN_YEAR_CODE , V_REPAIR_MONTH , Q1.MATERIAL_CODE , 1 , V_REPAIR_Qty , Q1.GROUP_CODE);
FORMS_DDL('COMMIT');
The fields in bold r required to be displayed for testing puposes..
this gives me numeric or value error in runtime..
Best regards,
Abdetu.. -
Bug in conditional for loop with an empty array
There appears to be a bug in the for loop with a conditional terminal.
If an empty array is wired to an auto-indexed array input tunnel, an output array tunnel has one element instead of zero.
The array constant on the left is empty.
Top loop without the conditional terminal produces an empty array.
The bottom loop with a never true conditional terminal produces an array with one element
Using LabVIEW version 8.5
Message Edited by TrevMrgn on 05-05-2009 02:01 PM
Solved!
Go to Solution.
Attachments:
For loop bug.png 3 KBCreating the example from scratch, I do not see the error.
Neither do I.
If I add one or more elements to the array (constant or control), then delete them all (using 'Delete Element') the bottom array has one element.
Nup. Still empty.
If I empty the array (using 'Empty Array') both are empty.
Yep.
Also if I create an empty array using 'initialise array' with zero elements, I get one element.
Nup. Still empty.
'Show constant folding' does not appear to change the behaviour, but including a random operation in the loop does.
Agreed that constant folding doesn't cause any odd behaviour. Introducing a random operation (adding two constants) in the loop doesn't either.
I've tried all your methods here Trevor, but I can't replicate this behaviour in 8.5.1 under WinXP SP3. Sorry!
Maybe somebody else will be able to help, or find a useable workaround.
Thoric (CLA, CLED, CTD and LabVIEW Champion) -
Cursor For Loop SQL/PL right application? Need help with PL Performance
I will preface this post by saying that I am a novice Oracle PL user, so an overexplanation would not be an issue here.
Goal: Run a hierarchial query for over 120k rows and insert output into Table 1. Currently I am using a Cursor For Loop that takes the first record and puts 2 columns in "Start" section and "connect by" section. The hierarchial query runs and then it inserts the output into another table. I do this 120k times( I know it's not very efficient). Now the hierarchial query doesn't take too long ( run by itself for many parts) but this loop process is taking over 9 hrs to run all 120k records. I am looking for a way to make this run faster. I've read about "Bulk collect" and "forall", but I am not understanding how they function to help me in my specific case.
Is there anyway I can rewrite the PL/SQL Statement below with the Cursor For loop or with another methodology to accomplish the goal significantly quicker?
Below is the code ( I am leaving some parts out for space)
CREATE OR REPLACE PROCEDURE INV_BOM is
CURSOR DISPATCH_CSR IS
select materialid,plantid
from INV_SAP_BOM_MAKE_UNIQUE;
Begin
For Row_value in Dispatch_CSR Loop
begin
insert into Table 1
select column1
,column2
,column3
,column4
from( select ..
from table 3
start with materialid = row_value.materialid
and plantid = row_value.plantid
connect by prior plantid = row.value_plantid
exception...
end loop
exception..
commitBluShadow:
The table that the cursor is pulling from ( INV_SAP_BOM_MAKE_UNIQUE) has only 2 columns
Materialid and Plantid
Example
Materialid Plantid
100-C 1000
100-B 1010
X-2 2004
I use the cursor to go down the list 1 by 1 and run a hierarchical query for each row. The only reason I do this is because I have 120,000 materialid,plantid combinations that I need to run and SQL has a limit of 1000 items in the "start with" if I'm semi-correct on that.
Structure of Table it would be inserted into ( Table 1) after Hierarchical SQL Statement runs:
Materialid Plantid User Create Column1 Col2
100-C 1000 25 EA
The Hierarchical query ran gives the 2 columns at the end.
I am looking for a way to either just run a quicker SQL or a more efficient way of running all 120,000 materialid, plantid rows through the Hierarchial Query.
Any Advice? I really appreciate it. Thank You. -
How to use for loops with Multiple Initializers and Incrementers
I found that my for loop is printing out wrong, because I am using two for loops. I have searched but all I can find out is you can't use multiple inializers and increments, does anyone know how to get around this? How would I use an array for this?
Thanks very much for your help.
import java.util.Random;
import java.util.Arrays;
/** Generate numnodes value for random integers in the range 0..499. */
public final class RandomInteger {
public static final void main(String... aArgs){
log("Generating 6 random integers in range 0..499.");
int numnodes = 6;
//Randomly generate a number between 0 and 499 for the x and y coordinates for the nodes
Random randomGenerator = new Random();
for (int x = 0; x < numnodes; ++x) {
int randomInt = randomGenerator.nextInt(500);
Random randomGenerator2 = new Random();
for (int y = 0;y < numnodes; ++y) {
int randomInt2 = randomGenerator2.nextInt(500);
log("Generated : " + randomInt + " " + randomInt2);
log("Done.");
}Sorry that code works, but I want to use both my x and y coordinates to get a random number from 0 to 499 in both of them, then I want to do some comparisons of the values, then return it to another function. As it stands now, I get the wrong results when I run it, as you can see at the bottom.
Thanks very much for your help. I have been stumped all mornign on this and have looked everywhere trying to find an example. I don't won't to use math random. I am on a tight deadline to finish and at the rate I am going, I will not complete it.
/** Generate numnodes value for random integers in
the range 0..499. */
public final class RandomInteger {
public static final void main(String... aArgs){
log("Generating 6 random integers in range
0..499.");
int numnodes = 6;
//Randomly generate a number between 0 and 499 for
the x and y coordinates for the nodes
Random randomGenerator = new Random();
for (int x = 0; x < numnodes; ++x) {
int randomInt = randomGenerator.nextInt(500);
Random randomGenerator2 = new Random();
for (int y = 0;y < numnodes; ++y) {
int randomInt2 = randomGenerator2.nextInt(500);
log("Generated : " + randomInt + " " + randomInt2);
log("Done.");
private static void log(String aMessage){
System.out.println(aMessage);
Output:
--------------------Configuration:
<Default>--------------------
Generating 6 random integers in range 0..499.
Generated : 98 254
Generated : 98 347
Generated : 98 359
Generated : 98 25
Generated : 98 277
Generated : 98 148
Generated : 416 401
Generated : 416 165
Generated : 416 354
Generated : 416 169
Generated : 416 144
Generated : 416 354
Generated : 295 158
Generated : 295 138
Generated : 295 349
Generated : 295 324
Generated : 295 18
Generated : 295 193
Generated : 197 451
Generated : 197 416
Generated : 197 480
Generated : 197 33
Generated : 197 490
Generated : 197 494
Generated : 324 412
Generated : 324 490
Generated : 324 213
Generated : 324 386
Generated : 324 467
Generated : 324 163
Generated : 379 180
Generated : 379 446
Generated : 379 314
Generated : 379 52
Generated : 379 113
Generated : 379 271
Done.
Process completed. -
Hello all,
As per my sample VI.
I gave Empty array to For Loop. As we know this Loop will not execute because N value “0”.
But, I want to know why Error out always giving True value. This Error Indicator value changing to “True” irrespective of Error In.
BR,
Munna
Munna
Solved!
Go to Solution.That''s exaclty what I said.
If you use plain tunnels and the loop iterates zero times, the output will give the default value for the datatype, which is FALSE for errors.
If you use shift registers, whatever is wired to the initializer terminal will be output unchanged on the right if the loop iterates zero times. Since you initialize with a error=TRUE, that's what you get.
This is all as expected. In your first post you claimed that the output is error=true using plain tunnels, which cannot be. Agreed?
If you want error=false with the shift register, change the diagram constant accordingly.
LabVIEW Champion . Do more with less code and in less time . -
Function with for loop and parameter table/column names ... syntax help
I'm trying to create a function that returns the distinct values and counts from a user defined schema/table/column.
The code below defines an object type [stats_on_column_obj] and creates a single table of this type [stats_on_column_tab].
The function is supposed to take three input variables: p_schema_name, p_table_name, p_column_name and return a table (above).
I can hard code a SELECT statement into the () ... but once I try to convert it to parameters & exec immediate I am stuck. The red section is where the issue is (i think).
Oracle 10g.
CREATE TYPE stats_on_column_obj IS OBJECT(
COL_VAL VARCHAR2(500),
COL_VAL_CNT NUMBER (7)
CREATE TYPE stats_on_column_tab IS TABLE OF stats_on_column_obj;
CREATE OR REPLACE FUNCTION get_STATS_ON_COLUMN
p_schema_name IN varchar2,
p_table_name IN varchar2,
p_column_name IN varchar2
RETURN STATS_ON_COLUMN_tab
IS
l_STATS_ON_COLUMN_tab STATS_ON_COLUMN_tab := STATS_ON_COLUMN_tab ();
n INTEGER := 0;
str_select_tbl varchar2(5000);
BEGIN
str_select_tbl := 'SELECT '||p_column_name||' as col_val, count(*) as col_val_cnt FROM '||p_schema_name||'.'||p_table_name||' group by '||p_column_name;
FOR r IN (str_select_tbl)
LOOP
l_STATS_ON_COLUMN_tab.EXTEND;
n := n + 1;
l_STATS_ON_COLUMN_tab (n) := STATS_ON_COLUMN_obj (r.col_val, r.col_val_cnt);
END LOOP ;
RETURN l_STATS_ON_COLUMN_tab;
END;
[Error] PLS-00103 (124: 4): PLS-00103: Encountered the symbol "LOOP" when expecting one of the following: * & - + / at mod remainder rem .. <an exponent (**)> || multiset year DAY_
[Error] PLS-00103 (126: 9): PLS-00103: Encountered the symbol "=" when expecting one of the following: constant exception <an identifier> <a double-quoted delimited-identifier> table LONG_ double ref char time timestam
[Error] PLS-00103 (127: 29): PLS-00103: Encountered the symbol "(" when expecting one of the following: constant exception <an identifier> <a double-quoted delimited-identifier> table LONG_ double ref char time timestam
[Error] PLS-00103 (128: 4): PLS-00103: Encountered the symbol "END" when expecting one of the following: begin function package pragma procedure subtype type use <an identifier> <a double-quoted delimited-identifier> form
SELECT * FROM TABLE (get_STATS_ON_COLUMN('SCHEMAS_X','TABLE_X','COLUMN_X'));SCOTT@orcl > CREATE OR REPLACE
2 FUNCTION get_STATS_ON_COLUMN(
3 p_schema_name IN varchar2,
4 p_table_name IN varchar2,
5 p_column_name IN varchar2
6 )
7 RETURN STATS_ON_COLUMN_tab
8 IS
9 v_STATS_ON_COLUMN_tab STATS_ON_COLUMN_tab := STATS_ON_COLUMN_tab ();
10 v_n INTEGER := 0;
11 v_str_select_tbl VARCHAR2(5000);
12 BEGIN
13 v_str_select_tbl := 'SELECT stats_on_column_obj(' || p_column_name || ',count(*)) FROM ' ||
14 p_schema_name || '.' || p_table_name || ' group by ' || p_column_name;
15 EXECUTE IMMEDIATE v_str_select_tbl
16 BULK COLLECT
17 INTO v_STATS_ON_COLUMN_tab;
18 RETURN v_STATS_ON_COLUMN_tab;
19 END;
20 /
Function created.
SCOTT@orcl > select *
2 from table(
3 get_STATS_ON_COLUMN(
4 'SCOTT',
5 'EMP',
6 'JOB'
7 )
8 )
9 /
COL_VAL COL_VAL_CNT
CLERK 4
SALESMAN 4
PRESIDENT 1
MANAGER 3
ANALYST 2
SCOTT@orcl >
Or better change it to pipelined function.
SY. -
Enhanced for loop with DirectoryStream in java 7
Hi, I'm a newbie to Java and am having trouble with the following code, which I'm trying to use to iterate through a directory and obtain the file names of all the pics to create thumbnails of them.
I've done hours and hours of searching on the web and find no answer for this one, so it's probably something very simple I've screwed up.
All assitance is appreciated.
The code segment:
try (DirectoryStream<Path> ds =
Files.newDirectoryStream(FileSystems.getDefault().getPath(dirNew)))
System.out.println("at dirstream");
System.out.format("toString: %s%n", ds.toString());
for (Path p : ds)
// Iterate over the paths in the directory and print filenames
System.out.println(p.getFileName());
System.out.println("at Path p : ds");
thumbName = p.getFileName();
createThumb(String.format("%s",thumbName));
} catch (IOException e) {
System.out.println("dirstream failed!!!");
// e.printStackTrace();
System.out.println("atend of dirstream");and the output:
run:
/home/rich/Images/FromWeb-Misc/1
at dirstream
toString: sun.nio.fs.UnixSecureDirectoryStream@196b20e
atend of dirstream
Edited by: 898552 on Mar 6, 2013 3:04 PM
Edited by: 898552 on Mar 6, 2013 3:07 PM
Edited by: 898552 on Mar 6, 2013 3:09 PMrp0428 wrote:
>
It's not entering the loop.
>
With the versions of NetBeans I use you can set breakpoints BEFORE and even ON the loop! Being able to set them inside a loop is just a no-cost extra. ;)I know! But you said "IN THE LOOP" :D The poor guy will set his breakpoint in it and think his debugger is broken ;)
Relax - take a deep breath - repeat after me
>
5 more points - 5 more points - 5 more points
>
Congratulations - I see a 'shiny' future for you!
Status Level: Expert (2,495) :DHaha, I hadn't noticed that :D I better be extra helpful now, so I can pop open a bottle of champagne tonight ;) -
Using a For Loop with an array
Ok, the issue is with the enabling of the buttons on my
stage. I run a loop to deactivate them all when one is clicked,
then I want to turn them back on, EXCEPT the one which was clicked.
I thought I could start off with an array of MC names and simply
delete them from the array. But I can't get my head around exactly
how to read in the array contents as MC names...
Any help would be greatly appreciated.
MikeTry something like this:
-
I get the following compiler error when using the Java 5 SE enhanced for loop with a generic collection.
Code:
public static void main(String[] args)
List<Integer> l = new ArrayList<Integer>();
l.add(new Integer(1));
printCollection(l);
private static void printCollection(Collection<?> c)
for (Object e : c)
System.out.println(e);
Error on attempting to build:
"Error: Internal compilation error, terminated with a fatal exception"
And the following from ojcInternalError.log:
java.lang.NullPointerException
at oracle.ojc.compiler.EnhancedForStatement.resolveAndCheck(Statement.java:2204)
at oracle.ojc.compiler.StatementList.resolveAndCheck(Statement.java:4476)
at oracle.ojc.compiler.MethodSymbol.resolveMethod(Symbol.java:10822)
at oracle.ojc.compiler.RawClassSymbol.resolveMethodBodies(Symbol.java:6648)
at oracle.ojc.compiler.Parser.resolveMethodBodies(Parser.java:8316)
at oracle.ojc.compiler.Parser.parse(Parser.java:7823)
at oracle.ojc.compiler.Compiler.main_internal(Compiler.java:978)
at oracle.ojc.compiler.Compiler.main(Compiler.java:745)
at oracle.jdeveloper.compiler.Ojc.translate(Ojc.java:1486)
at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildGraph(UnifiedBuildSystem.java:300)
at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildProjectFiles(UnifiedBuildSystem.java:515)
at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildAll(UnifiedBuildSystem.java:715)
at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.run(UnifiedBuildSystem.java:893)Install the Service Update 1 patch for JDeveloper (using the help->check for updates), and let us know if this didn't solve the problem.
-
For Loop and Void Method Questions
Question 1: How would I write a for loop that repeats the according to the number entered, to prompt the user to enter a number (double) between 1 and 100. If the number is outside this range it is not accepted.
Question: 2 Also how would I write a for loop to do sum and find the average of the array numbers in a seperate void method( does not return anything to the main method)?
Question: 3 (first code snippet) With my for loop that is used to process each number in the array and square it and cube it and display the results to 2 decimal places. How do I make it so say I want the array to allow me to enter 2 numbers (so I enter 2 numbers) then it asks me to enter a number between 1 -100 (which will prompt 2 times) that it shows me the results for the entered numbers between 1-100 after one another instead of number then result number then result like I how it now.
for (int index = 0; index < howNum; index++) // process each number in the array
enterYourNumbers = JOptionPane.showInputDialog
("Enter a number between 1 and 100");
numArray = new double[howNum];
try
numArray[index] = Double.parseDouble(enterYourNumbers);
catch (NumberFormatException e)
enterYourNumbers = JOptionPane.showInputDialog
("Enter a number between 1 and 100");
DecimalFormat fmt = new DecimalFormat ("###,###.00");
JOptionPane.showMessageDialog(null, enterYourNumbers + " " + "squared is " + fmt.format(calcSquare(numArray[index]))
+ "\n" + enterYourNumbers + " " + "cubed is " + fmt.format(calcCube(numArray[index])));
wantToContinue = JOptionPane.showInputDialog ("Do you want to continue(y/n)? ");
while (wantToContinue.equalsIgnoreCase("y"));
import javax.swing.*;
import java.text.DecimalFormat;
public class Array
public static void main(String[] args)
int howNum = 0;
int whichNum = 0;
double[] numArray;
boolean invalidInput = true;
String howManyNumbers, enterYourNumbers, wantToContinue;
do // repeat program while "y"
do // repeat if invalid input
howManyNumbers = JOptionPane.showInputDialog
("How many numbers do you want to enter");
try
howNum = Integer.parseInt(howManyNumbers);
invalidInput = false;
catch (NumberFormatException e )
howManyNumbers = JOptionPane.showInputDialog
("How many numbers do you want to enter");
while (invalidInput);
for (int index = 0; index < howNum; index++) // process each number in the array
enterYourNumbers = JOptionPane.showInputDialog
("Enter a number between 1 and 100");
numArray = new double[howNum];
try
numArray[index] = Double.parseDouble(enterYourNumbers);
catch (NumberFormatException e)
enterYourNumbers = JOptionPane.showInputDialog
("Enter a number between 1 and 100");
DecimalFormat fmt = new DecimalFormat ("###,###.00");
JOptionPane.showMessageDialog(null, enterYourNumbers + " " + "squared is " + fmt.format(calcSquare(numArray[index]))
+ "\n" + enterYourNumbers + " " + "cubed is " + fmt.format(calcCube(numArray[index])));
wantToContinue = JOptionPane.showInputDialog ("Do you want to continue(y/n)? ");
while (wantToContinue.equalsIgnoreCase("y"));
public static double calcSquare(double yourNumberSquared)
return yourNumberSquared * yourNumberSquared;
public static double calcCube(double yourNumberCubed)
return yourNumberCubed * yourNumberCubed * yourNumberCubed;
public static void calcAverage(double yourNumberAverage)
}DeafBox wrote:
Question 1: How would I write a for loop that repeats the according to the number entered, to prompt the user to enter a number (double) between 1 and 100. If the number is outside this range it is not accepted. Use a while loop instead.
Question: 2 Also how would I write a for loop to do sum and find the average of the array numbers in a seperate void method( does not return anything to the main method)? Why would you want to use 2 methods. Use the loop to sum the numbers. Then after the loop a single line of code calculates the average.
Question: 3 (first code snippet) With my for loop that is used to process each number in the array and square it and cube it and display the results to 2 decimal places. How do I make it so say I want the array to allow me to enter 2 numbers (so I enter 2 numbers) then it asks me to enter a number between 1 -100 (which will prompt 2 times) that it shows me the results for the entered numbers between 1-100 after one another instead of number then result number then result like I how it now. If I understand you correctly, use 2 loops. One gathers user inputs and stores them in an array/List. The second loop iterates over the array/List and does calculations. -
Using a For loop to call one array element at a time
I have been working on a VI that reads a GPS unit, parses the data, outputs what I need, compares the actual GPS location to the desired location, determines a desired heading and moves on from there. My question pertains to the number of desired locations I can input right now. I need to be able to input a predtermined number of locations (not just the one that I can input right now). I was told that it is possible to use a For Loop with an array and have the first set of Lat and Long values run through the VI and when everything is complete that the next set of values will be chosen. Does this mean that I need to put the entire VI inside a For Loop and have the array update as soon as the VI has completed its first mission? I understand the concept of how this work from other programming languages but I'm not sure how to implement the solution in LabVIEW. Any help would be appreciated.
Adamadamoutlaw wrote:
Here is a portion of the VI. I need two separate arrays, one for Latitude and one for Longitude, of the same size.
I don't see any arrays in your code. Do you want to generate arrays form individual data points or do you want to process arrays, one element at a time? Both can take advantage of autoindexing. Here's a simple picture.
Your VI contains a weird mix of DBL and EXT precision. Most likely all you need is DBL. Keep your representations consistent!
Message Edited by altenbach on 08-02-2007 07:14 AM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
Indexing.png 4 KB -
i have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks
Hi fais,
Following through with what JB suggested. The steps involved in replacing the inner for loop with a while loop are outlined below.
You can replace the inner for loop with a while by doing the following.
1) Right-click of the for loop and select "Repalce" then navigate to the "while loop".
2) Make sure the tunnels you where indexing on with the for loop are still indexing.
3) Drop an "array size" node on your diagram. Wire the array that determines the number of iterations your for loop executes into this "array size".
4) Wire the output of the array size into the new while loop.
5) Set the condition terminal to "stop if true".
6)Drop an "OR" gate inside the while loop and wire its output to the while loops condition terminal.
7) C
reate a local of the boolean "stop" button, and wire it into one of the inputs of your OR gate. This will allow you to stop the inner loop.
8) Drop a "less than" node inside the inner while loop.
9) Wire your iteration count into the bottom input of the "less than".
10) Wire the count (see step 4 above) into the top input of the less than. This will stop the inner loop when ever the inner loop has processed the last element of your array.
Provided I have not mixed up my tops and bottoms this should accomplish the replacement.
I will let others explain how to takle this task using the "case solution".
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction -
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).
Maybe you are looking for
-
How can I display the HTML page from servlet which is called by an applet
How can I display the HTML page from servlet which is called by an applet using the doPost method. If I print the response i can able to see the html document. How I can display it in the browser. I am calling my struts action class from the applet.
-
Lenovo y500 trouble connecting to internet
Hi Lenvo community! I bought a lenovo y500 recently and have had trouble connnecting to private networks from the moment i opened the notebook. The day I recieved my computer I took it out of the box and tried to connect it to the internet during the
-
STO with WM with shipping and transportation process
Hi , Can anyone explain the process STO with WM with shipping and transportation?. What are all the config needs to be done for shipping and transportation? Regards, abi
-
i need to delete this email acct off my phone but cant because i did it from the link, the information that i have in is wrong. What to do?
-
Can N95-8GB play multiple video clips without inte...
I bought the N95 8gb few days ago. Then transfer some of my MV to its Video Centre. When I played those MV in N95, I need to click the arrow button to switch to the next song or previously song. Is there any way to create a video playlist in this pho