Home » SQL & PL/SQL » SQL & PL/SQL » Oracle and PL/SQL Help
Oracle and PL/SQL Help [message #8057] Wed, 23 July 2003 18:08 Go to next message
Nazma Bepat
Messages: 34
Registered: May 2003
Member
Would someone be willing to help me out.

I would like to rewrite the cursor below, with the minimum number of lines, using the syntax for cursor For Loops. I would not like to change the cursor name, columns or any variables used in the code below. I would like to write the code to create the cursor For Loop.

DECLARE
social_benefits c_unions%ROWTYPE;
CURSOR change_cursor IS
SELECT wk_ends, forty_hr_wks, ot_pay
FROM bus_practices;
BEGIN
OPEN change_cursor;
LOOP
FETCH change_cursor INTO social_benefits;
EXIT WHEN change_cursor &NOTFOUND;
END LOOP;
CLOSE change_cursor;
END;
/

I really appreciate your help.
Thanks

Nazma
Re: Oracle and PL/SQL Help [message #8058 is a reply to message #8057] Wed, 23 July 2003 18:29 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
You can eliminate the declare section. The code below replaces all of your original code.

BEGIN 
  FOR social_benefits IN
    (SELECT wk_ends, forty_hr_wks, ot_pay
     FROM   bus_practices)
  LOOP
    -- put whatever processing you want here
    -- referencing columns with the same names
    -- that you would in your original code:
    --   social_benefits.wk_ends
    --   social_benefits.forty_hr_wks
    --   social_benefits.ot_pay
  END LOOP;
END;
/
Re: Thanks for your help! [message #8059 is a reply to message #8058] Wed, 23 July 2003 18:38 Go to previous message
Nazma Bepat
Messages: 34
Registered: May 2003
Member
Barbara,

Thanks a lot for your help. Ireally appreciate it.

Nazma
Previous Topic: Query performance
Next Topic: Subquery is not allowed in "Group by" clause in Ora9.2
Goto Forum:
  


Current Time: Thu Apr 25 08:26:40 CDT 2024