• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

Cursor in SQL

Hi. I want to use a cursor on a table of managers. If any manager has a salary less that 10k raise and error. If manager has salary > than 50k output a message and re-raise the exception.

This is what i have so far............

DECLARE CURSOR man_cur IS SELECT * FROM manager WHERE salary < 10000.........

I'm confused after this. Thanks
  • 2
  • 2
1 Solution
slightwv (䄆 Netminder) Commented:
I don't understand the question.  Please provide more of the requirements.

For example: are you wanting a pl/sql procedure with a loop through the cursor?  If you hit a vlue and raise an exception, it stops.  How do you want to 'output' a value before the exception?

Sample data and expected results would help a lot.
graziaziAuthor Commented:
Yes I want a pl/sql procedure with a loop through the cursor. Ok let's simplify by taking out the 90k clause
slightwv (䄆 Netminder) Commented:
create or replace procedure myProc
     for i in (SELECT * FROM manager) loop

         if i.salary < 10000 then
                   raise_application_error(-20001, i.name || ' has a salary < 10000');
         elsif i.salary > 90000 then
                   dbms_output.put_line('Have a winner!');
                   raise_application_error(-20001, i.name || ' has a salary > 90000');
         end if;
     end loop
graziaziAuthor Commented:
Thank you

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now