This will be very close to what you are looking for. You can also do a
google search on 'PL/SQL tutorial' and find many very good resources. Here
is a nice one where I got this example
http://plsql-tutorial.com/plsql-explicit-cursors.htm

1> DECLARE

2>  CURSOR emp_cur IS

3>  SELECT first_name, last_name, salary FROM emp_tbl;

4>  emp_rec emp_cur%rowtype;

5> BEGIN

6>   IF NOT sales_cur%ISOPEN THEN

7>      OPEN sales_cur;

8>   END IF;

9>   FETCH sales_cur INTO sales_rec;

10>  WHILE sales_cur%FOUND THEN

11>  LOOP

12>    dbms_output.put_line(emp_cur.first_name || ' ' ||emp_cur.last_name

13>    || ' ' ||emp_cur.salary);

15>    FETCH sales_cur INTO sales_rec;

16>  END LOOP;

17> END;

18> /



On Mon, Oct 13, 2008 at 10:06 AM, NewOracleMember <
[EMAIL PROTECTED]> wrote:

>
> I appreciate your reply Michael.Reason is because I'm trying to learn
> how cursor works in PL/SQL.
>
> Thanks
>
> On Oct 13, 11:55 am, "Michael Moore" <[EMAIL PROTECTED]> wrote:
> > why not just do
> > UPDATE emp
> >    SET sal = (SELECT   sal + (ROWNUM * 50)
> >                   FROM emp
> >               ORDER BY sal desc);
> >
> > On Mon, Oct 13, 2008 at 9:28 AM, NewOracleMember <
> [EMAIL PROTECTED]
> >
> > > wrote:
> >
> > > So far,in PL/SQL I've declared my cursor with 3 columns.I am trying to
> > > use an if statement to update the salary. But I am stuck.
> >
> > > On Oct 13, 11:17 am, NewOracleMember <[EMAIL PROTECTED]>
> > > wrote:
> > > > DECLARE myRaise integer
> > > > SET myRaise = 50
> > > > --declare the cursor
> > > > DECLARE mycursorname CURSOR FOR
> > > >                 SELECT EID, Name, Sal
> > > >                 FROM EMP
> > > >                 ORDER BY Sal DESC
> > > > OPEN mycursorname
> >
> > > > --load the cursor field values from that of the select statement
> > > > FETCH NEXT FROM mycursorname INTO @EID, @Name, @Sal
> > > >                 --loop thru the cursor until we are out of rows.
> > > > WHILE @@FETCH_STATUS = 0
> > > >  BEGIN
> > > > --give the employee the raise
> > > > UPDATE Emp SET Sal = Sal + myRaise
> >
> > > > --increment the variable by 50 for the next employee
> > > > myRaise = myRaise + 50
> >
> > > > --move the cursor to the next record
> > > > FETCH NEXT FROM mycursorname INTO @EID, @Name, @Sal
> > > > END
> > > > CLOSE
> >
> > > > --clean up
> > > > DEALLOCATE mycursorname
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Oracle PL/SQL" group.
To post to this group, send email to Oracle-PLSQL@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Oracle-PLSQL?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to