How to execute an SP within a for loop?
hi,
i have the following sp.
PROCEDURE insert_and_update (
book_name IN table01.book_name%TYPE,
description1 IN table01.description1%TYPE
status IN OUT number
i need to call this sp in the following loop.
for i in (select book_name, book_descfrom new_books) loop ..... end loop;
i did the following but it didnt work. what am i missing ?
declare
nn number(10):=0;
begin
for i in (select book_name, description from new_books) loop
exec insert_and_update (i.book_name,i.book_desc, :nn);
end loop;
end;
please advise.
thanks in advanced
novideDBA
EXEC is a SQL*Plus command, not PL/SQL. You don't need EXEC in PL/SQL, just call the procedure
for i in (select book_name, description from new_books) loop
insert_and_update (i.book_name,i.book_desc, :nn);
end loop;Justin
Similar Messages
-
How do I set a variable within a 'for' loop grid array
I'm afraid I'm stuck again!
The next stage in the animation that I'm working on, is to set up a boolean, 'drilled = false', so that all instances of the attachMovie ('openCircle') have a boolean 'drilled = false' associated with them. Then when someone clicks on one of the instances of the attachMovie ('openCircle'), the boolean becomes 'drilled = true', but only for that instance that has been clicked.
What I've done is to set the variable (boolean)(highlighted in bold below) within both 'for' loops within the grid array, but it just returns an undefined value. Do I need to setup a separate array? (see code below):-
//set up grid for solid array
var spacing:Number = 5.75;
var cols:Number = 20; // number of columns in grid
var rows:Number = 20; // number of rows in grid
var leftMargin:Number = 154;
var topMargin:Number = 169;
var depth:Number = 100; // starting point for depth
var drilled:Boolean;
for (i=1; i<=rows; i++) {
for (j=1; j<=cols; j++) {
drilled[rows,cols]=false;
trace(drilled);
current = attachMovie("openCircle_mc", "openCircle_mc"+i+"_"+j, depth++);
current._x = leftMargin + ((i-1) * (spacing + current._width));
current._y = topMargin + ((j-1) * (spacing + current._height));
current.row=i;
current.col=j;
// current.oil = Math.floor(Math.random()*1.1); // about 1/10 objects have oil=1, 9/10 oil=0
//open circle initially invisible, visible on rollOver
current._alpha = 0;
current.onRelease=function(){
trace(this.row+" "+this.col);
current.drilled = true;
current.onRollOver = function() {
this._alpha = 100;
current.onRollOut = function() {
this._alpha = 0;
I'd be grateful for any help. Thanks.I'm sorry for asking this question again, but I really need to have the 'drilled' variable to be available at all times outside the openCircle_mc, so if I can set up the 'drilled' variable as an array that would be good. Below is the code that isn't working:
/* set all values of 'drilled' to false */
var col:Number = 20; // number of columns in grid
var row:Number = 20; // number of rows in grid
for (g=1; g<=row; g++) {
for (h=1; h<=col; h++){
drilled[g,h] = false;
Very many thanks -
Reading a csv file within a for loop
Hi guys,
Im trying to read a csv file within a for loop and the while loop only seems to be getting executed once rather than the number of times that is specified.
for(int i=0; i<paramValues.length;i++)
String StudentNo = paramValues4;
out.println("StudentNo="+StudentNo);
BufferedReader in = new BufferedReader( new InputStreamReader( conn2.getInputStream()));
String readLine; // stores a line from the file as a string//used to get rid of the first line which has course name
readLine = in.readLine();
int NumberOfElementsInArray=16;
String[] data;
data = new String[NumberOfElementsInArray];
data[0]=> StudentNo
data[1]=> Surname
data[2]=> Firstname
data[3]=> ExamNo
data[4]=> YrOfStdy
data[5]=> ProgOfStdy
data[6]=> Fld1
data[7]=> Fld2
data[8]=> DegType
data[9]=> EnrolStatus
data[10]=> StaffAdvNo
data[11]=> Tutor
data[12]=> Fld3
data[13]=> Fld4
data[14]=> Fld5
data[15]=> Pegged
data[16]
//out.println("<table border=\"1\">");
int datanumber=0;
while( (readLine = in.readLine()) != null )
out.println("ive entered the loop");
StringTokenizer tokens = new StringTokenizer( readLine, ",", true);
boolean prevTokenComma = true;
boolean emptyValue = false;
String aValue = null;
datanumber=0;
while( tokens.hasMoreTokens() )
aValue = null;
String token = tokens.nextToken();
token=token.trim();
//if the token does not equal to a comma
if( !token.equals(",") )
aValue = token;
prevTokenComma = false;
emptyValue = false;
else if( token.equals(",") && prevTokenComma )
prevTokenComma = true;
emptyValue = true;
else //( token.equals(",") && !prevTokenComma )
prevTokenComma = true;
emptyValue = false;
if(emptyValue)
aValue = "";
// Printing values
if( aValue == null)
//do nothing
else if (aValue.equals("") )
aValue=" ";
data[datanumber]=aValue;
//out.println("datanumber="+datanumber);
//out.println("<td> aValue: "+aValue+"</td>");
datanumber++;
else
data[datanumber]=aValue;
//out.println("<td> aValue: "+aValue+"</td>");
//out.println(datanumber);
datanumber++;
out.println("data[0]="+data[0]);
//out.println("data[3]="+data[3]);
//out.println("ExamNo="+ExamNo);
}//end while
in.close();
}//end for loop
When I print the variable student no at the beginning of the for loop it prints the different studentno's so the for loop is fine, but the while loop gets executed once. Does anyone know why????????/
Thanks
TzafPROBLEM SOLVED....
Basically the following declarations have been done within the for loop....
URL url2 = new URL ("http://localhost:8080/FYP/CSVFILES"+Year+"/"+WebCourse2+".csv");
URLConnection conn2 = url2.openConnection();
HttpURLConnection uc = (HttpURLConnection)conn2;
uc.connect();
try
responseCode = uc.getResponseCode();
out.println("Response code1: " + responseCode+"\n");
catch(IOException e)
responseCode = uc.getResponseCode();
//out.println("Response code2: " + responseCode+"\n");
thanks
anyway
tzaf -
A 'For' loop within another 'For' loop
This is the loop:
for (int i = 1; i<=5; i++) {
for (int k = 1; k<=3; k++) {
System.out.println("i is " + i + ", k is " + k);
How does it execute? After it goes through the loop i = 1, and k = 1, apparently it then doesn't go to i = 2, but instead it increments k to 2, and i remains as 1 until k is greater than 3. I'm confused how this works. Does the first loop execute first, and then the second loop executes, but then the program exits out of the second loop only when k is greater than 3?
Much appreciate your help.
YashTry to imagine expanding the loops. In the example you provided, the loops aren't that big, so it's pretty easy.
for (int i = 1; i<=5; i++) {
for (int k = 1; k<=3; k++) {
System.out.println("i is " + i + ", k is " + k);
}becomes
int i = 1;
for (int k = 1; k<=3; k++) {
System.out.println("i is " + i + ", k is " + k);
i = 2;
for (int k = 1; k <= 3; k++) {
System.out.println("i is " + i + ", k is " + k);
i = 3;
for (int k = 1; k <= 3; k++) {
System.out.println("i is " + i + ", k is " + k);
i = 4;
for (int k = 1; k <= 3; k++) {
System.out.println("i is " + i + ", k is " + k);
i = 5;
for (int k = 1; k <= 3; k++) {
System.out.println("i is " + i + ", k is " + k);
}which becomes
int i = 1;
int k = 1;
System.out.println("i is " + i + ", k is " + k);
k = 2;
System.out.println("i is " + i + ", k is " + k);
k = 3;
System.out.println("i is " + i + ", k is " + k);
i = 2;
k = 1;
System.out.println("i is " + i + ", k is " + k);
k = 2;
System.out.println("i is " + i + ", k is " + k);
k = 3;
System.out.println("i is " + i + ", k is " + k);
i = 3;
k = 1;
System.out.println("i is " + i + ", k is " + k);
k = 2;
System.out.println("i is " + i + ", k is " + k);
k = 3;
System.out.println("i is " + i + ", k is " + k);
i = 4;
k = 1;
System.out.println("i is " + i + ", k is " + k);
k = 2;
System.out.println("i is " + i + ", k is " + k);
k = 3;
System.out.println("i is " + i + ", k is " + k);
i = 5;
k = 1;
System.out.println("i is " + i + ", k is " + k);
k = 2;
System.out.println("i is " + i + ", k is " + k);
k = 3;
System.out.println("i is " + i + ", k is " + k); -
How to create parallel tasks using parallel for loops
Hi,
I am setting up a program that communicates with six logic controllers and has to read the system status every 100 ms. We are using OPC datasockets for this, and they appear a little slow.
I have created a uniform comm. method for all controllers, and now I find myself programming this method six times to communicate with each system. I am wondering if this could be done more elegant using the parallel for loop, in which case I would program an exchange once and then have six workers running simultaneously. Since a picture is more clear that a thousand words, what I am asking is this:
Is it possible to replace something like
by
and have this for loop running these tasks in parallel (on different cores / in different threads)?
I have configured the loop to create 8 instances at compile, so I would have 2 instances surplus available at runtime if I find I need an additional system.
The benefits of the method show in the second picture to me are:
* takes less space
* modifications have to be made only once
* less blocks, wires and stuff makes it more clear what's going on.
* flexibility in the actual number of tasks running (8 instances available at runtime)
* if more tasks are required, I need only to update the maximum number of instances and recompile, i.e. no cutting and pasting required.
Unfortunately, I don't have those system available yet, so there's no way to test this. Yet, I would like to know if the above works as I expect - unfortunately the labview help is not completely clear to me on this.
Best regards,
Frans
Solved!
Go to Solution.Dear mfletcher,
First of all: thanks for confirming that my intuition was right in this case.
As for your question on the help: below is a copy/paste from the help on the 'configure parallelism dialog box'
Number of generated parallel loop instances—Determines the number of For Loop instances LabVIEW generates at compile time. The Number of generated parallel loop instances should equal the number of logical processors on which you expect the VI to execute. If you plan to distribute the VI to multiple computers, Number of generated parallel loop instances should equal the maximum number of logical processors you expect any of those computers to ever contain. Use the parallel instances terminal on the For Loop to specify how many of the generated instances to use at run time. If you wire a larger number to the parallel instances terminal than you specify in this dialog box, LabVIEW only executes as many loop instances as you specify here.The reason for me doubting if what I programmed would work the way I intended lies in the fact that the help only mentions processors here, which would be interpreted as actual cores. Thus on a dual core machine, the number should be 2.
I think it would be helpful to mention something about threads here, because in some case one would like to have more parallel threads than there are cores in a system.
In mu case I would like to create six threads, which on my dual core processor would be spread over only two cores. Then these six threads run in parallel.I know that in case of heavy math that would not help, but since I am doing communications, which have timeouts and such, and that probably runs smoother in six parallel tasks even though I only have two cores.
Hope this helps in improving the help of the for loop.
Regards,
Frans -
Writting exception within cursor for loop
I have two cursor for loop as
for rec1 in () loop --loop 1
for rec2 in () loop --loop2
<statements>
end loop;
end loop
Now I want to handle exception within my second for loop so that after terminating the loop it will again go to the first loop...
How to do it ? Please help......you may
BEGIN
FOR rec1 IN your_select1
LOOP --loop 1
BEGIN
FOR rec2 IN your_select2
LOOP --loop2
statements;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
log_error;
END;
END LOOP;
END;or ...depending on your exact needs:
BEGIN
FOR rec1 IN your_select1
LOOP --loop 1
FOR rec2 IN your_select2
LOOP
BEGIN --loop2
statements;
EXCEPTION
WHEN OTHERS
THEN
log_error;
END;
END LOOP;
END LOOP;
END; -
Truncating an array within a for loop
I'm currently working with a program that builds an array of 3000*N real numbers, where N is a control that I specify. I want to pass this array into a for loop that runs N times, each time splitting the first 3000 numbers of the array. So, in other words I want the for loop to execute enough times such that the initial array will be completely divided into groups of 3000 when I'm finished. Later I'll be finding the maximum value of all of these subarrays and taking the average of those. What I tried first is to pass the array into the for loop, then truncate it at index = 3000, but the problem is that I can't hard code the loop to do this N times. Any advice or other methods you'd recommend for doing this?
Thanks.
Message Edited by Robtn on 03-05-2010 03:17 PMMark--I don't think I can use that approach. Let me be more specific on what the problem is:
Our "big program" is a giant while loop that constantly reads in voltage values from a DAQ assistant.
It has two modes, the first of which I'm having a lot of trouble with. This mode uses a for loop (N = 3000) nested within the giant while loop.
When the for loop activates, the DAQ assistant takes reads 300 samples for every iteration and takes the maximum of those 300 values. It then builds an array composed of all the maxima. After the for loop has executed 3000 times, a case structure activates, which then finds the maximum of the array of maxima.
I want this (N=3000) for loop to execute an arbitrary number of times, a number that I will specify. Each of those times it should generate a completely seperate array of maxima. So, if I want the for loop to run 5 times, I want 5 different arrays.
My approach for doing this was to change N=3000 to say N = 15000, then split up the resulting array 5 times. So, I need an entirely separate for loop that reads in this array of 15000 maxima on its own and splits it 5 ways. I think what you're suggesting is to use a for loop outside of the N=3000 loop, which is a good idea in theory, but experience has shown that this will not generate 5 separate arrays. It will actually concatenate each array into one, hence the problem we currently have.
Yik--I won't have access to Labview over the weekend. Is it possible to take a screenshot and post it, or maybe a short description?
Thank you for the responses. -
Executing each step of a for loop only on a VISA read output
Hi,
I would like to give multiple steps to a motor/controller to exectue, but I keep getting a "command overflow" error. Therefore, I am trying to tell the for loop only to execute when the VISA Read receives an output. I have included the .vi I have written so far. For example, the code /1P1000p66R tells the controller to move motor "1" forward 1000 steps and then to output the number "66" when the motor has moved 1000 steps. My input to the "table control" is, e.g., 3 commands:
/1P1000p66R
/1D1000p66R
/1D5000p66R
How do I get the code to send each of those commands only when the number "66" is sent back to the program so that I don't get the command overflow error? Also, if anyone has a better way to control the motor to do multiple steps, let me know. I'm pretty new to all of this.
Thanks.
Attachments:
Motor Controller (Sub VI 2).vi 26 KBRather than using a table control, I would just use a string array.
Set your serial port parameters before the loop. Close the serial port after the loop.
Your controls don't have any real data in them saved as default, so I'm confused a bit as to what your are trying to do. Why do you have a numeric control with the number 0 establishing the loop iterations?
Instead of a For Loop, use a while loop. Set the 1-D array of strings to be autoindexing at the input tunnel. Write the command (why you have everything wrapped in a case statement with a true constant makes no sense. Do a VISA read. If the response has the 66 (you'll have to figure out how to parse it out), all is good. If it does not have the 66, or the number of loop iterations equals the number of commands in the array -1 , then end the loop.
Message Edited by Ravens Fan on 05-20-2009 09:31 PM
Attachments:
MotorController(SubVI).vi 18 KB
Motor%20Controller%20(Sub%20VI%202)[1]_BD.png 8 KB -
How to use no of iteration of for loop as the input for the for loop
hi all,
i wanna need some help here..
i'm using for loop to iterate to ceratin no of iteration.. then, i would like to use back the no of iteration as the input of 'N' for the next iteration..
in other word, eg:
1st run:
i insert a control to 'N', let say 80
then the iteration run until 80-1 = 79..
2nd run:
i need to insert the no of "N", let say a control of 120.. i want the loop run for "120 - 79", where the 79 is the no of previous run..
easy to say,
how can i connect the "i' as a control to ''N''
n how to make a "run' or ' GO' and ''stop'' button in the front panel and block diagram after the first run without using the stop and run from the labview window
thanks..Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
Attachments:
Untitled 2.vi 9 KB -
How to use the select statement in for loop
Hi All,
my question is can we use select statement in for loop like as follows .
for key in select key from one_table.
when i am using this am getting an error like Found select invalid i identifier
how to make use of select statement in for loop
please suggest me .
Thanks
SreeSQL>set serveroutput on;
SQL> DECLARE
BEGIN
FOR Cur_Rec IN (SELECT dname FROM dept) LOOP
DBMS_OUTPUT.PUT_LINE(Cur_Rec.dname);
END LOOP;
END;
SQL>
ACCOUNTING
RESEARCH
SALES
OPERATIONSAs per your requirement always filter the Query beforehand
Like
FOR Cur_Rec IN (SELECT key FROM <table> WHERE key=1) LOOP
END LOOP;Edited by: Lokanath Giri on १ दिसंबर, २०११ ३:५६ अपराह्न -
How to traverse an array with a for-loop in this certain way...
so I need to traverse an array starting from the first element, then from the last element, then the second element, then the second last element, then third element and so on... in a for loop
how would that look in code?
Any help would be appreciated, thanks!
Edited by: inspiredone on Apr 4, 2008 6:34 AMWow, that's a really clever and elegant way to do it promethuzz. I actually came up with something already before I read your post so yeah don't worry about me copying or anything. Mine is not as elegant/efficient and I definitely like yours a lot more but I will just share it anyway...it looks pretty similar to the second algorithm The_Matrix has provided. I figured this out from thinking how quicksort compares its pivot with the two indexes...
int front=0;
int back = a.length - 1;
int counter =0;
boolean switchflag = true;
while(front<=back)
System.out.println(a[counter]);
if(switchflag)
counter = back;
front++;
switchflag = false;
else
counter = front;
back--;
switchflag = true;
} Anyways, thanks a lot for you guys help, promethuzz, The_Matrix, and newark.
Edited by: inspiredone on Apr 4, 2008 11:25 AM
Edited by: inspiredone on Apr 4, 2008 11:27 AM -
Is there any point in having an ORDER BY clause within a FOR LOOPs counter?
DB Version:10.2.0.1.0
I need to loop through empno's using a FOR loop. But is there any point in having an Order by clause within SQL as shown below. This only degrades the performance because of the unnecessary sorting by the ORDER BY clause. Right?
begin
FOR i IN (select empno from emp ORDER BY sal ASC) LOOP
curr_stat_id := i.empno +p_gennum;
.First question you should ask to your self is
"Do i need a FOR LOOP. Cant i do it in a straight SQL"
If the answer is NO (Which is not in several cases) then the next question is.
"What is my requirement"
Having an order by in the Select is totally pertained to your requirement. If your requirement
says you should loop through the employee based on there salary for lowest to highest then yes you
need an order by.
So more than performance point of view its requirement point of you. But if you are more concern about
performance you will first ask to your self
"Do i need a FOR LOOP. Cant i do it in a straight SQL"
Thanks,
Karthick. -
Hi,
I'm using labVIEW V5.1
I'm trying to generate 10 1D arrays, the first array is initialized to all zeroes, then I have set up a for loop which shifts the first element by 1, then a random number is placed into the first element position. I am using a shift register to feed back in the newly generated array into the start of the loop.
By the end of the each loop I want to be able to use the array generated in an algorithm outside the loop. However I only want the Nx1 array that has just been generated.
Unfortunately, I cannot figure out how to resize, reshape or index the output array to do this.
I would like the loop to
give me out a 1D array after each iteration.
Any help would be greatly appreciated.I hope I've understood your problem.
First your vi was lacking of the sub-vi working as shift register, I've replaced it with the rotate function.
The indexing of your arrays create a 2D array whose rows are your 1D array.To pick only one of them you have to use the index array function and select which one you want.
To use your temporary data in another part of your application you should use a local variable of array2.
I did it in a separated while loop That I syncronized with the for loop using occurrence, in this way the while loop runs each time a new value is inserted in array2 (each loop of the for loop structure).
If you don't need this syncronization just get rid of occurrence functions.
I place a delay in the for loop to show what happens when running.
Hope it was helpful.
Alberto Locatelli
Attachments:
array_test_v3.vi 35 KB -
How to use String Tokeniser inside this for loop?
[i][i]hi there..
i am reading all the file inside a directory and get the latest modified file than i have to tokenise it and juz read the number. For example my file name that is last modified will be abc_123.txt but i just want it to appear 123.
i manage to do it separately how can i put the tokeniser inside my for loop?
my directory
for (int i = 0; i < files.length; i++)
if(files[i].isFile())
if(lastModifiedFile == null){
lastModifiedFile = files[i];
String mylastModifiedFile = lastModifiedFile.toString();
StringTokenizer tokens = new StringTokenizer (mylastModifiedFile,".");
String modified = tokens.nextToken().substring(modified.length-4);*/
if(lastModifiedFile != null)
if(lastModifiedFile.lastModified() < files[i].lastModified())
lastModifiedFile = files[i];
my tokeniser is this
String mylastModifiedFile = lastModifiedFile.toString();
StringTokenizer tokens = new StringTokenizer (mylastModifiedFile,".");
String modified = tokens.nextToken().substring(modified.length-4);*/
}[i][i][i]hi there..
i am reading all the file inside a directory and get ...
tokens.nextToken().substring(modified.length-4);*/
}[/i][i][/i][/i][/i]Is there some reason for this baroque formatting? Please use the
code tags as explained in one of your other threads on this topic:
http://forum.java.sun.com/thread.jspa?threadID=793441&messageID=4510858#4510858 -
Set file position within a for loop, error 1
Hi, I'm reading from a .sxm file consisting of a large chunk of text followed by binary data for 512x512 images with 4 bytes per pixel
I’ve managed to successfully identify the start of the binary and read the first image from the file and view it using "flatten pixmap.vi", so I’m doing something right, however when i try to read the next chunk of image data in the .sxm file using a for loop, set file position keeps churning out ERR (1).
im at a loss as to whats causing this
Solved!
Go to Solution.
Attachments:
binaryread3d trouble.vi 22 KB
back panel screenshot.png 27 KBI closed the file in the loop, doh! ... another morning well spent
Maybe you are looking for
-
Automatic creation of Purchase order not possible for 103 mvt type
Hi, If i could configure "create p.o automatically", while doing G.R for mvt type 101, why cannot i do the same with 103 mvt type. I checked the checkbox "create p.o automatically" for movement type 103 and tried to do G.R for others using Mvt type 1
-
I am having the exact same issue. Only difference is I am using 2 RV180's. Same firmware version and same symptoms. My setup crashes every 2-3.5 days and I can NEVER get it to re-establish using the GUI, I always have to re-boot one side or the ot
-
If TXT02 is null then Blank else OBJ= TXT02 is under one segment say X My logic which dint work If X and TX02 exist and TXT02 =(Equals ,text function) null ->if Then " " else TXT02="OBJ= " actually we used BPM in this scenario. Using the above logic,
-
Check that backup files are not corrupted
Hi all. I am wondering if there is a possibility to check that the files obtained after backing up Oracle XE, NO ARCHIVELOG, are not corrupt. Can you help me? Thanks a lot.
-
Since I updated my iPhone5 to ios8, my apps log out completely when I press the home button. For example, I have a store-card app on my phone. It used to stay logged in all the time. Now, every time I press the home button I am logged out of the app