For loop in forall
Hi all
i have a problem.Actually i'm giving a test problem here.While executing this i'm getting ora 66550 error .What wrong i'm doing?
say col1 and col2 is column of tab1.
type test is table of number;
a_test test:=test(8,9);
cursor c1(test number) is
select col1 from tab1
where col2=test;
p1 c1%rowtype;
begin
forall i in 1 .. a_test.count
for p1 in c1(a_test(i)) loop
insert into b_test values(a_test(i),p1.col1)
end loop;
end;
Thanks in advance
bp wrote:
Hi all
i have a problem.Actually i'm giving a test problem here.While executing this i'm getting ora 66550 error .What wrong i'm doing?
say col1 and col2 is column of tab1.
type test is table of number;
a_test test:=test(8,9);
cursor c1(test number) is
select col1 from tab1
where col2=test;
p1 c1%rowtype;
begin
forall i in 1 .. a_test.count
for p1 in c1(a_test(i)) loop
insert into b_test values(a_test(i),p1.col1)
end loop;
end;
test@ORA10G>
test@ORA10G>
test@ORA10G> select * from tab1;
C COL2
a 6
b 7
c 8
d 9
e 10
5 rows selected.
test@ORA10G>
test@ORA10G>
test@ORA10G> --
test@ORA10G> declare
2 type test is table of number;
3 a_test test:=test(8,9);
4 begin
5 forall i in 1 .. a_test.count
6 insert into b_test (x,y)
7 select col2, col1
8 from tab1
9 where col2 = a_test(i);
10 end;
11 /
PL/SQL procedure successfully completed.
test@ORA10G>
test@ORA10G> select * from b_test;
X Y
8 c
9 d
2 rows selected.
test@ORA10G>
test@ORA10G>isotope
Similar Messages
-
Breaking a single query using for loop to improve performance
Hi,
This is a continuation of my previous post which I marked Answered and few things are were left from my side and I was advised to post a new thread...
[Will it be a good ply|http://forums.oracle.com/forums/thread.jspa?threadID=880922&tstart=0]
will it be applicable to any query because I took this to simplify the thing to explain my case
which is actually........... pull the data from some tables using joins and insert into some other tables .....
I used few procedures for diff conditions one of them use plain' insert into select' and others use bulk collect technique.
I followed the simple strategy (for DML ) by Tom Kytes ..and Steven Feuerstein
Use single statement whenever it is possible..
if not use PL/SQL with bulk collect to avoid for loop.
Please correct me if I am wrong.
Thanks and Regards,
Hesh.A simple test can prove the case
SQL> set serveroutput on
SQL>
SQL> create table t
2 as
3 select * from all_objects where 1=2
4 /
Table created.
SQL> declare
2 ltime integer;
3 begin
4 ltime := dbms_utility.get_time;
5 insert into t select * from all_objects;
6 ltime := dbms_utility.get_time - ltime;
7
8 dbms_output.put_line(ltime);
9 end;
10 /
187
PL/SQL procedure successfully completed.
SQL> rollback
2 /
Rollback complete.
SQL> declare
2 ltime integer;
3 type tbl is table of t%rowtype index by pls_integer;
4 l_tbl tbl;
5 cursor c
6 is
7 select * from all_objects;
8 begin
9 ltime := dbms_utility.get_time;
10 open c;
11 loop
12 fetch c bulk collect into l_tbl limit 500;
13 exit when c%notfound;
14
15 forall i in 1..l_tbl.count
16 insert into t values l_tbl(i);
17 end loop;
18
19 ltime := dbms_utility.get_time - ltime;
20
21 dbms_output.put_line(ltime);
22 end;
23 /
390
PL/SQL procedure successfully completed.
SQL> rollback
2 /
Rollback complete. -
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. -
Bulk collect usage in cursor for loop
Hi Team,
I have one cursor like below assuming cursor is having 3000 records,
CURSOR csr_del_frm_stg(c_source_name VARCHAR2 , c_file_type VARCHAR2)
IS
SELECT stg.last_name,stg.employee_number,stg.email
FROM akam_int.xxak_eb_contact_stg stg
MINUS
SELECT ss.last_name,ss.employee_number,ss.email
FROM akam_int.xxak_eb_contact_stg_ss ss;
I declared one record type variable as,
TYPE emp_rec IS RECORD (LAST_NAME VARCHAR2(40)
*,EMPLOYEE_NUMBER VARCHAR2(50)*
*,EMAIL VARCHAR2(80)*
TYPE emp_rec_ss IS VARRAY(3000) OF emp_rec;
Im updating the status of those cursor records to 'C' in the below for loop,
FOR l_csr_del_frm_stg IN csr_del_frm_stg(p_source_name , p_file_type)
LOOP
FETCH csr_del_frm_stg BULK COLLECT INTO emp_rec_ss LIMIT 500;
FORALL i IN emp_rec_ss.FIRST..emp_rec_ss.LAST
UPDATE akam_int.xxak_eb_contact_stg stg
SET akam_status_flag = 'C'
WHERE stg.employee_number = emp_rec_ss(i).employee_number;
EXIT WHEN csr_del_frm_stg%NOTFOUND;
END LOOP;
Getting following errors if i compile the code,
PLS-00321: expression 'EMP_REC_SS' is inappropriate as the left hand side of an assignment statement
PLS-00302: component 'FIRST' must be declaredUse cursor variables:
declare
v_where varchar2(100) := '&where_clause';
v_cur sys_refcursor;
v_ename varchar2(30);
begin
open v_cur for 'select ename from emp where ' || v_where;
loop
fetch v_cur into v_ename;
exit when v_cur%notfound;
dbms_output.put_line(v_ename);
end loop;
close v_cur;
end;
Enter value for where_clause: deptno = 10
CLARK
KING
MILLER
PL/SQL procedure successfully completed.
SQL> /
Enter value for where_clause: sal = 5000
KING
PL/SQL procedure successfully completed.
SQL> /
Enter value for where_clause: job = ''CLERK''
SMITH
ADAMS
JAMES
MILLER
PL/SQL procedure successfully completed.
SQL> SY. -
LOOP inside FORALL in bulk binding
Can I use a loop inside forall in bulk bind updates?
as I understand, forall statement strictly loops through the length of the bulk limit size for the immediately following statement only.
I am attempting to use a loop there to update more than one table.
cursor c is select id from temp where dt_date > sysdate-30;
BEGIN
loop
fetch c into v_id;
limit 1000;
forall i in 1..v_id.count
UPDATE table_one set new_id = v_id(i);
exit when C%NOTFOUND;
end loop;
end;
I want to update another table table_two also immediately after updating table_one like this:
forall i in 1..v_id.count
UPDATE table_one set new_id = v_id(i);
BEGIN select nvl(code,'N/A') into v_code from T_CODES where ID_NO = v_id(i); EXCEPTION WHEN NO_DATA_FOUND v_code='N/A'; END;
UPDATE table_two set new_code =v_code;
exit when C% not found.
This is not working and when I run it, I get an error saying encountered BEGIN when one of the following is expected.
I got around this by having another FOR loop just to set up the values in another array variable and using that value in another second forall loop to update table_two.
Is there any way to do this multiple table udpates in bulkbinding under one forall loop that would enable to do some derivation/calculation if needed among variables [not array variables, regular datatype variables].
Can we have like
forall j in 1.. v_id.count
LOOP
update table 1;
derive values for updating table 2;
update table 2;
END LOOP;
Thank You.Well, without questioning reasions why do you want this, you are confusing bulk select and forall. You need:
begin
loop
fetch c bulk collect into v_id limit 1000;
exit when v_id.count = 0;
forall i in 1..v_id.count
UPDATE table_one set new_id = v_id(i);
end loop;
end;
/SY. -
How can I repeat a for loop, once it's terms has been fulfilled???
Well.. I've posted 2 different exceptions about this game today, but I managed to fix them all by myself, but now I'm facing another problem, which is NOT an error, but just a regular question.. HOW CAN I REPEAT A FOR LOOP ONCE IT HAS FULFILLED IT'S TERMS OF RUNNING?!
I've been trying many different things, AND, the 'continue' statement too, and I honestly think that what it takes IS a continue statement, BUT I don't know how to use it so that it does what I want it too.. -.-'
Anyway.. Enought chit-chat. I have a nice functional game running that maximum allows 3 apples in the air in the same time.. But now my question is: How can I make it create 3 more appels once the 3 first onces has either been catched or fallen out the screen..?
Here's my COMPLETE sourcecode, so if you know just a little bit of Java you should be able to figure it out, and hopefully you'll be able to tell me what to do now, to make it repeat my for loop:
Main.java:
import java.applet.*;
import java.awt.*;
@SuppressWarnings("serial")
public class Main extends Applet implements Runnable
private Image buffering_image;
private Graphics buffering_graphics;
private int max_apples = 3;
private int score = 0;
private GameObject player;
private GameObject[] apple = new GameObject[max_apples];
private boolean move_left = false;
private boolean move_right = false;
public void init()
load_content();
setBackground(Color.BLACK);
public void run()
while(true)
if(move_left)
player.player_x -= player.movement_speed;
else if(move_right)
player.player_x += player.movement_speed;
for(int i = 0; i < max_apples; i++)
apple.apple_y += apple[i].falling_speed;
repaint();
prevent();
collision();
try
Thread.sleep(20);
catch(InterruptedException ie)
System.out.println(ie);
private void prevent()
if(player.player_x <= 0)
player.player_x = 0;
else if(player.player_x >= 925)
player.player_x = 925;
private void load_content()
MediaTracker media = new MediaTracker(this);
player = new GameObject(getImage(getCodeBase(), "Sprites/player.gif"));
media.addImage(player.sprite, 0);
for(int i = 0; i < max_apples; i++)
apple[i] = new GameObject(getImage(getCodeBase(), "Sprites/apple.jpg"));
try
media.waitForAll();
catch(Exception e)
System.out.println(e);
public boolean collision()
for(int i = 0; i < max_apples; i++)
Rectangle apple_rect = new Rectangle(apple[i].apple_x, apple[i].apple_y,
apple[i].sprite.getWidth(this),
apple[i].sprite.getHeight(this));
Rectangle player_rect = new Rectangle(player.player_x, player.player_y,
player.sprite.getWidth(this),
player.sprite.getHeight(this));
if(apple_rect.intersects(player_rect))
if(apple[i].alive)
score++;
apple[i].alive = false;
if(!apple[i].alive)
apple[i].alive = false;
return true;
public void update(Graphics g)
if(buffering_image == null)
buffering_image = createImage(getSize().width, getSize().height);
buffering_graphics = buffering_image.getGraphics();
buffering_graphics.setColor(getBackground());
buffering_graphics.fillRect(0, 0, getSize().width, getSize().height);
buffering_graphics.setColor(getForeground());
paint(buffering_graphics);
g.drawImage(buffering_image, 0, 0, this);
public boolean keyDown(Event e, int i)
i = e.key;
if(i == 1006)
move_left = true;
else if(i == 1007)
move_right = true;
return true;
public boolean keyUp(Event e, int i)
i = e.key;
if(i == 1006)
move_left = false;
else if(i == 1007)
move_right = false;
return true;
public void paint(Graphics g)
g.drawImage(player.sprite, player.player_x, player.player_y, this);
for(int i = 0; i < max_apples; i++)
if(apple[i].alive)
g.drawImage(apple[i].sprite, apple[i].apple_x, apple[i].apple_y, this);
g.setColor(Color.RED);
g.drawString("Score: " + score, 425, 100);
public void start()
Thread thread = new Thread(this);
thread.start();
@SuppressWarnings("deprecation")
public void stop()
Thread thread = new Thread(this);
thread.stop();
GameObject.java:import java.awt.*;
import java.util.*;
public class GameObject
public Image sprite;
public Random random = new Random();
public int player_x;
public int player_y;
public int movement_speed = 15;
public int falling_speed;
public int apple_x;
public int apple_y;
public boolean alive;
public GameObject(Image loaded_image)
player_x = 425;
player_y = 725;
sprite = loaded_image;
falling_speed = random.nextInt(10) + 1;
apple_x = random.nextInt(920) + 1;
apple_y = random.nextInt(100) + 1;
alive = true;
And now all I need is you to answer my question! =)package forums;
import java.util.Random;
import javax.swing.Timer;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class VimsiesRetardedAppleGamePanel extends JPanel implements KeyListener
private static final long serialVersionUID = 1L;
private static final int WIDTH = 800;
private static final int HEIGHT = 600;
private static final int MAX_APPLES = 3;
private static final Random RANDOM = new Random();
private int score = 0;
private Player player;
private Apple[] apples = new Apple[MAX_APPLES];
private boolean moveLeft = false;
private boolean moveRight = false;
abstract class Sprite
public final Image image;
public int x;
public int y;
public boolean isAlive = true;
public Sprite(String imageFilename, int x, int y) {
try {
this.image = ImageIO.read(new File(imageFilename));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Bailing out: Can't load images!");
this.x = x;
this.y = y;
this.isAlive = true;
public Rectangle getRectangle() {
return new Rectangle(x, y, image.getWidth(null), image.getHeight(null));
class Player extends Sprite
public static final int SPEED = 15;
public Player() {
super("C:/Java/home/src/images/player.jpg", WIDTH/2, 0);
y = HEIGHT-image.getHeight(null)-30;
class Apple extends Sprite
public int fallingSpeed;
public Apple() {
super("C:/Java/home/src/images/apple.jpg", 0, 0);
reset();
public void reset() {
this.x = RANDOM.nextInt(WIDTH-image.getWidth(null));
this.y = RANDOM.nextInt(300);
this.fallingSpeed = RANDOM.nextInt(8) + 3;
this.isAlive = true;
private final Timer timer = new Timer(200,
new ActionListener() {
public void actionPerformed(ActionEvent e) {
repaint();
public VimsiesRetardedAppleGamePanel() {
this.player = new Player();
for(int i=0; i<MAX_APPLES; i++) {
apples[i] = new Apple();
setBackground(Color.BLACK);
setFocusable(true); // required to generate key listener events.
addKeyListener(this);
timer.setInitialDelay(1000);
timer.start();
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == e.VK_LEFT) {
moveLeft = true;
moveRight = false;
} else if (e.getKeyCode() == e.VK_RIGHT) {
moveRight = true;
moveLeft = false;
public void keyReleased(KeyEvent e) {
moveRight = false;
moveLeft = false;
public void keyTyped(KeyEvent e) {
// do nothing
public void paintComponent(Graphics g) {
super.paintComponent(g);
//System.err.println("DEBUG: moveLeft="+moveLeft+", moveRight="+moveRight);
if ( moveLeft ) {
player.x -= player.SPEED;
if (player.x < 0) {
player.x = 0;
} else if ( moveRight ) {
player.x += player.SPEED;
if (player.x > getWidth()) {
player.x = getWidth();
//System.err.println("DEBUG: player.x="+player.x);
Rectangle playerRect = player.getRectangle();
for ( Apple apple : apples ) {
apple.y += apple.fallingSpeed;
Rectangle appleRect = apple.getRectangle();
if ( appleRect.intersects(playerRect) ) {
if ( apple.isAlive ) {
score++;
apple.isAlive = false;
g.drawImage(player.image, player.x, player.y, this);
for( Apple apple : apples ) {
if ( apple.isAlive ) {
g.drawImage(apple.image, apple.x, apple.y, this);
g.setColor(Color.RED);
g.drawString("Score: " + score, WIDTH/2-30, 10);
private static void createAndShowGUI() {
JFrame frame = new JFrame("Vimsies Retarded Apple Game");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new VimsiesRetardedAppleGamePanel());
frame.pack();
frame.setSize(WIDTH, HEIGHT);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
public static void main(String[] args) {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
createAndShowGUI();
}Hey Vimsie, try resetting a dead apple and see what happens. -
Getting the label of a JButton in a for loop
hi,
I doing a project for my course at the minute and im in need of a bit of help. I have set up 1-d array of buttons and i have layed them out using a for loop. I have also added an annoymous action listener to each button in the loop. It looks something lke this:
b = new JButton[43];
for (int i=1; i<43; i++)
b[i] = new JButton(" ");
b.addActionListener(
new ActionListener()
public void actionPerformed(ActionEvent e)
System.out.println("..........");
}); // addActionListener
} // for
I want the "System.out.println( ..." line, to print out the "i" number of the button that was pressed but i cannot figure out how to do it. I cannot put "System.out.println(" "+i);" as it wont recognise i as it is not inside the for loop. Does anyone have any suggestions?
Thanks!!class ButtonExample extends JFrame implements ActionListener{The OP wanted to have anonymous listeners, not a subclassed JFrame
listening to the buttons. I don't know if the following is the best design,
since the poster has revealed so little, but here is how to pass the
loop index to an anonymous class.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButtonExample {
private JButton[] buttons = new JButton[24];
public JPanel createGUI() {
JPanel gui = new JPanel(new GridLayout(6, 4));
for(int i=0; i<buttons.length; i++) {
final int ii = i; //!! !
buttons[i] = new JButton("button #" + i);
buttons.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
System.out.println("number " + ii);
gui.add(buttons[i]);
return gui;
public static void main(String[] args) {
ButtonExample app = new ButtonExample();
JPanel gui = app.createGUI();
JFrame f = new JFrame("ButtonExample");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(gui);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true); -
How to pass the sequence number of current loop in a for loop in FPGA vi to the host
PCI-7830R
LV 8.2
What I was trying to do is to use multiple DIO to generate pulse at different sequence. Mode one is to automatically sweep from DIO1 to DIO20; mode 2 is several DIOs generate pulse simoutaneously. So I use a case structure to make the selection, in the mean time, I set up two for loop in each case so that I can use multiple pulse generations. For example, in scanning mode, if I set 2 exposures, it sweeps from 1 to 20 then do it again.
Then I need to get the loop sequence number, i of each scenario. So I put an indicator within the first loop, and create a local variable of it and put in the second one. Running the FPGA vi alone, I can see the indicator change in each case from 0 to N-1, N being the for loop time.But in the host vi, I tried to add this indicator as an element in the read/write invoke method, in the debugging mode, I could only see it directly jump to N-1 without all the changes I saw in FPGA vi.
Is it possible to get this number passed correctly from FPGA vi to the host vi? ThanksThanks for the reply Jared.
Excuse me if it looks incorrect, but I'm new to FPGA programming, so I would have to look into the FIFO you referred to. I used local variables because for one thing I have several different cases containing for loop in each of them, and I only want one indicator for the "i". If I put the indicator out of any for loop, it's only gonna show the last number which is N-1. For the other thing, it seems like property nodes are not allowed in FPGA vi. And by doing this, I can see the i number changing from 0 to N-1 in each case, well, in FPGA vi's front panel. But while I ran the host vi with everything, the indicator in host vi's front panel only showed the last number N-1. It may be the reason you said, it happened too fast before the indicator in host vi can catch it.
What I want to realize is to group the data I collect in host vi, for example, when I choose multiple exposure in each mode, and the FPGA runs 1 through 20 then do it again, I want the data stored in two groups using the loop sequence number as the seperator in file name. So it goes like 1-1, 2-1.......20-1; then 1-2, 2-2,.....20-2. -
How do we use if statement in labview?moreover can i use if statement inside for loop?
how do we use if statement in labview?moreover can i use if statement inside for loop?
The if statement in LabVIEW is the Case structure. You can find that on the Structures palette right next to the For Loop. If you're still on the same subject about terminating a for loop early, then what you do is enclose your functions inside the loop with a case statment and make one of the case's empty except for one or more constants that you might have to wire. Hopefully, the attached picture will explain what I mean. Also, as I mentioned in one of your other posts, I think this technique is not as good as using a while loop. The array in the attached example is the same size no matter what and you may have to handle stripping extra or invalid elements.
Attachments:
For_Loop_with_Case.jpg 21 KB -
Select statement in a for loop
Hi all,
Can a select stmt be used in the body of the for loop/ nested for loop ?
I tries using (even if its very simple for loop) it gives the following error
PL/SQL: ORA-00933: SQL command not properly ended...
code is
DECLARE
CURSOR C1 is select 'Monday' from dual
union all
select 'Tuesday' from dual
union all
select 'Wednesday' from dual
union all
select 'Thursday' from dual
union all
select 'Friday' from dual
union all
select 'Saturday' from dual
union all
select 'Sunday' from dual;
type rec_info is record
name varchar2(20),
FNAME varchar2(20),
LNAME varchar2(20)
type ty_info is table of rec_info;
info ty_info;
type rec_abc is record
day varchar2(3000)
type ty_abc is table of rec_abc;
abc ty_abc;
Cursor C2 is
select t.name, u.first_name, u.last_name
from territories t, users u, territories_users tu
where t.ID = tu.TERRITORY_ID
and tu.USER_ID = u.ID ;
BEGIN
OPEN C1;
Loop
FETCH C1 into abc;
EXIT when C1%notfound;
DBMS_OUTPUT.PUT_LINE(abc);
END LOOP;
CLOSE C1;
OPEN C2;
FETCH C2 BULK COLLECT into info;
CLOSE C2;
for i in info.first .. info.last
LOOP
for j in abc.first .. abc.last
LOOP
select --info(i).name, info(i).FNAME, info(i),LNAME,'AM' "AM/PM",
to_char(c.name)||' '||ct.PRIMARY_ADDRESS_CITY||','||ct.PRIMARY_ADDRESS_STATE||','||ct.PRIMARY_ADDRESS_COUNTRY
from
territories t, territories_users tu,
users u, calls_users cu, calls c,
calls_contacts cc, contacts ct
where
tu.TERRITORY_ID = t.id
and t.name = info(i).name
and u.first_name = info(i).FNAME
and u.last_name = info(i).LNAME
and (c.date_start between trim(next_day(sysdate,abc(j).day)) and trim(next_day(sysdate,abc(j).day)))
and tu.USER_ID = u.id
and cu.USER_ID = u.id
and cu.CALL_ID = c.id
and to_char(c.time_start,'hh24') < '12'
and cc.CALL_ID = c.ID
and cc.CONTACT_ID = ct.id
and rownum < 2
END LOOP;
END LOOP;
END;"Can a select stmt be used in the body of the for loop/ nested for loop "
Yes.... but with an INTO part.....
select c1 , c2 , c3 into var1 , var2 , var3 from table1
Sim -
If statement doesn't affect for loop
I wrote a function within a function to control 2 Tweens.
(the 2nd one isnt in the function, it's called)
My problem is... is that it works for the first time.. the button is hovered over and all the other buttons show themselves and then disappear again, except the one you're over. Then I do it a 2nd time and it doesn't work. why is it only working right one time? and why isn't the if statement I put in the local function affecting the for loop? The 2nd time it takes the button you're hovering over with it and fades it out. (even though the if statement registers according to trace)
this is the code
import fl.transitions.Tween;
import fl.transitions.easing.*;
var shortInst:Array = [btn1, btn2, btn3, exit];
var objTween:Tween;
function mouseOff(e:Event):void {
if (e.currentTarget.alpha !== 0) {
objTween = new Tween(e.currentTarget, "alpha", None.easeOut, 1, 0, 0.25, true);
var eTimer:Timer = new Timer(3000, 1); //timer that only runs once (in ms)
function navFX(e:Event):void {
for (var i:Number = 0; i < shortInst.length; i++) {
objTween = new Tween(shortInst[i], "alpha", None.easeOut, 0, 1, 0.25, true);
eTimer.addEventListener(TimerEvent.TIMER, local);
eTimer.start();
function local(t:TimerEvent):void {
trace("e.target in local func: " + e.target);
for (var i:Number = 0; i < shortInst.length; i++) {
if (shortInst[i] !== e.target) {
shortInst[i].dispatchEvent(new Event(MouseEvent.MOUSE_OUT));is this what you want?
import fl.transitions.Tween;
import fl.transitions.easing.*;
var shortInst:Array = [btn1,btn2,btn3,exit];
var objTween:Tween;
function mouseOff(e:Event):void
if (e.currentTarget.alpha !== 0)
objTween = new Tween(e.currentTarget,"alpha",None.easeOut,1,0,0.25,true);
function navFX(e:Event):void
var eTimer:Timer = new Timer(3000,1); // <- moved that line here
for (var i:Number = 0; i < shortInst.length; i++)
objTween = new Tween(shortInst[i],"alpha",None.easeOut,0,1,0.25,true);
eTimer.addEventListener(TimerEvent.TIMER, local);
eTimer.start();
function local(t:TimerEvent):void
trace("e.target in local func: " + e.target);
for (var i:Number = 0; i < shortInst.length; i++)
if (shortInst[i] !== e.target)
shortInst[i].dispatchEvent(new Event(MouseEvent.MOUSE_OUT));
for (var i:Number = 0; i < shortInst.length; i++)
shortInst[i].alpha = 0;
shortInst[i].addEventListener(MouseEvent.MOUSE_OVER, navFX);
shortInst[i].addEventListener(MouseEvent.MOUSE_OUT, mouseOff); -
Help with Mathscipt and for loop
I have a code in Mathscript/matlab and I need to output the array out. One option is my first code,the other option is using a for loop, but I am only getting the last ouput out. I need to get the whole output out.
Any help.
Thanks
Solved!
Go to Solution.
Attachments:
Help with Mathscript_for loop.vi 115 KB
Help with Mathscript_for loop2.vi 84 KBHere's how it should look like.
Message Edited by altenbach on 10-30-2008 05:12 PM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
MathscriptInFOR.png 15 KB -
Why use cursor and for loop?
Hi All
So in general why would we use a cursor and a for loop to do update in a stored procedure?
Why wouldnt we just use a single update statement ?
is there compelling reason for using a cursor and a for loop: I am reading some code from a co-worker that the business logic for the select (set need to be updated) is complex but the update logic is simple (just set a flag to (0 or 1 or 2 or 3 or 4).
But eventually the select come down to a key (row_id) so I re-write it using just a single sql statement.
The size of the main table is about 2.6 to 3million rows
Any thoughts on that??
The code below I just do a google for cursor for update example in case for something to play with
-Thanks for all your input
create table f (a number, b varchar2(10));
insert into f values (5,'five');
insert into f values (6,'six');
insert into f values (7,'seven');
insert into f values (8,'eight');
insert into f values (9,'nine');
commit;
create or replace procedure wco as
cursor c_f is
select a,b from f where length(b) = 5 for update;
v_a f.a%type;
v_b f.b%type;
begin
open c_f;
loop
fetch c_f into v_a, v_b;
exit when c_f%notfound;
update f set a=v_a*v_a where current of c_f;
end loop;
close c_f;
end;
exec wco;
select * from f;
drop table f;
drop procedure wco;
Joining multiple tables
create table numbers_en (
id_num number primary key,
txt_num varchar2(10)
insert into numbers_en values (1, 'one' );
insert into numbers_en values (2, 'two' );
insert into numbers_en values (3, 'three');
insert into numbers_en values (4, 'four' );
insert into numbers_en values (5, 'five' );
insert into numbers_en values (6, 'six' );
create table lang (
id_lang char(2) primary key,
txt_lang varchar2(10)
insert into lang values ('de', 'german');
insert into lang values ('fr', 'french');
insert into lang values ('it', 'italian');
create table translations (
id_num references numbers_en,
id_lang references lang,
txt_trans varchar2(10) not null
insert into translations values (1, 'de', 'eins' );
insert into translations values (1, 'fr', 'un' );
insert into translations values (2, 'it', 'duo' );
insert into translations values (3, 'de', 'drei' );
insert into translations values (3, 'it', 'tre' );
insert into translations values (4, 'it', 'quattro');
insert into translations values (6, 'de', 'sechs' );
insert into translations values (6, 'fr', 'six' );
declare
cursor cur is
select id_num,
txt_num,
id_lang,
txt_lang,
txt_trans
from numbers_en join translations using(id_num)
left join lang using(id_lang)
for update of translations.txt_trans;
rec cur%rowtype;
begin
for rec in cur loop
dbms_output.put (
to_char (rec.id_num , '999') || ' - ' ||
rpad (rec.txt_num , 10 ) || ' - ' ||
rpad(nvl(rec.txt_trans, ' '), 10 ) || ' - ' ||
rec.id_lang || ' - ' ||
rpad (rec.txt_lang , 10 )
if mod(rec.id_num,2) = 0 then
update translations set txt_trans = upper(txt_trans)
where current of cur;
dbms_output.put_line(' updated');
else
dbms_output.new_line;
end if;
end loop;
end;
/Edited by: xwo0owx on Apr 25, 2011 11:23 AMAdding my sixpence...
PL/SQL is not that different from a SQL perspective than any other SQL client language like Java or C# or C/C++. PL/SQL simply integrates the 2 languages a heck of a lot better and far more transparent than the others. But make no mistake in that PL/SQL is also a "client" language from a SQL perspective. The (internal) calls PL/SQL make to the SQL engine, are the same (driver) calls made to the SQL engine when using Java and C and the others.
So why a cursor and loops in PL/SQL? For the same reason you have cursors and loops in all these other SQL client languages. There are the occasion that you need to pull data from the SQL engine into the local language to perform some very funky and complex processing that is not possible using the SQL language.
The danger is using client cursor loop processing as the norm - always pulling rows into the client language and crunching it there. This is not very performant. And pretty much impossible to scale. Developers in this case views the SQL language as a mere I/O interface for reading and writing rows. As they would use the standard file I/O read() and write() interface calls.
Nothing could be further from the truth. SQL is a very advance and sophisticated data processing language. And it will always be faster than having to pull rows to a client language and process them there. However, SQL is not Turing complete. It is not the procedural type language that most other languages we use, are. For that reason there are things that we cannot do in SQL. And that should be the only reason for using the client language, like PL/SQL or the others, to perform row crunching using a client cursor loop. -
How to add cursor and for loop
PROCEDURE "TEST" is
bala number;
ins1 number;
ins2 number;
BEGIN
select sum(bal) into bala from (select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and c_srm_prncplinsid=acp_instruid
and acp_acntnum!='SG030001'
group by acp_instruid
union
select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and acp_acntnum!='SG030001'
and acp_instruid=c_srm_prntinsid
group by acp_instruid)view1;
dbms_output.put_line(bala);
select acp_instruid into ins1 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and c_srm_prncplinsid=acp_instruid
and acp_acntnum='SG030001';
dbms_output.put_line('principal'||ins1);
select acp_instruid into ins2 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and acp_acntnum='SG030001'
and acp_instruid=c_srm_prntinsid;
dbms_output.put_line('parent'||ins2);
update cs_acpos_bkp
set acp_totbal=-bala
where acp_instruid=ins2
and acp_acntnum='SG030001';
END;
i have written this code,i need to use cursor and for loops to get more than one rows and update also.
if there are more than 1 rows in cs_strmap_t,then the procedure throws an error stating that it cannot take 2 rows.
Edited by: 850836 on Apr 7, 2011 11:43 PMPROCEDURE "TEST" is
bala number;
ins1 number;
ins2 number;
CURSOR cur_1 IS
select sum(bal) bala from (select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and c_srm_prncplinsid=acp_instruid
and acp_acntnum='SG030001'
group by acp_instruid
union
select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and acp_acntnum='SG030001'
and acp_instruid=c_srm_prntinsid
group by acp_instruid)view1;
BEGIN
select acp_instruid into ins1 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and c_srm_prncplinsid=acp_instruid
and acp_acntnum='SG030001';
dbms_output.put_line('principal'||ins1);
select acp_instruid into ins2 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and acp_acntnum='SG030001'
and acp_instruid=c_srm_prntinsid;
dbms_output.put_line('parent'||ins2);
for var_for in cur_1
loop
update cs_acpos_bkp
set acp_totbal=var_for.bala
where acp_instruid=ins2
and acp_acntnum='SG030001'
and abs(acp_totbal)>abs(bala);
dbms_output.put_line(bala);
end loop;
END;
i wrote the following procedure,but the balance is not getting updated.
Getting this errors when there are more than 1 row in cs_strmap_t table
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: line 22
ORA-06512: at line 2 -
How to ignore error and continue with next value in PL/SQL FOR loop?
hi,
When the DROP INDEX statement fails it have to continue with the next value in FOR loop without exiting from the loop. Can anyone tell me how to do this?
DECLARE
CURSOR aud_cur IS
SELECT key_col_idx FROM audience_work where aud_ref_id between 106 and 109;
BEGIN
FOR aud_row IN aud_cur LOOP
EXECUTE IMMEDIATE
'DROP INDEX ' || aud_row.key_col_idx;
END LOOP;
END;
Thanks,
NobleDECLARE
CURSOR aud_cur
IS
SELECT key_col_idx FROM audience_work where aud_ref_id between 106 and 109;
BEGIN
FOR aud_row IN aud_cur LOOP
begin
EXECUTE IMMEDIATE 'DROP INDEX ' || aud_row.key_col_idx;
exception
when others then
if sqlcode = -01418 then
dbms_output.put_line(' index does not exist ');
else
dbms_output.put_line(sqlcode);
raise;
end if;
end;
END LOOP;
END;
/
Maybe you are looking for
-
EFS, password change denies access to encrypted data
Hi, Has anyone had the issue with admin changing users password in Console One resulting in users not being able to access their encrypted data. Laptop users are using EFS to encrypt their data. These users have WinXPPro SP2 and we are running ZfD 6.
-
User Exit or BADI for Operation tab of IW32 Transaction
Hi All, Currently I am working on the transaction IW32. I am looking for a user exit or BADI which can trace the item level changed data for operations. Thanks in advance. Regards, Rajesh
-
Trouble: HD "Data Lost," DiskWarrior stumped, then a "Clean Install"
Hello Classic Fans, Since installing OS 9.1 on my 1998 WallStreet PowerBook on 25 April 2005, I enjoyed a PERFECT computer until 3 days ago (16 Feb. 2006) when my Mac started badly acting up. I'll chart what happened and what I did to correct the pro
-
How can I remove Page Break Views?
This is driving me nuts -- I'm just trying to write basic text, and yet, for some reason, Pages forces me to view a page as if it's a real piece of paper. As I'm writing, and come to the end of the page, there's two inches of white space from the end
-
Action to: Print current document to PDF Printer "As Image" with Specified DPI
I FREQUENTLY do the following task on documents. I would LOVE to have an action that did it for me. Can someone help me create one or point me to someone who can? Version: Adobe Acrobat X Pro. Windows 7 64-bit With current PDF file open: 2) Print