DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: How to use a cursor...????

  1. #1
    Join Date
    May 2012
    Posts
    1

    How to use a cursor...????

    Hello everyone i'm new to pl/sql and needed some help on cursors i was hoping someone could give me a layout of what i would need e.g. declare exection and exception which i can then try to have a go with the statements thanks even if someone can give me a start e.g. declare section then i can have a go


    A description of the Employees and LEAST_EARNERS tables are shown below.

    Employees TABLE
    Name Null ? Type
    empno NOT NULL NUMBER(4)
    last_name VARCHAR2(10)
    job VARCHAR2(9)
    mgr NUMBER(4)
    hiredate
    salary
    DATE
    NUMBER(8)

    LEAST_EARNERS TABLE
    Name Null ? Type
    salary NUMBER(8)

    Create a PL/SQL block that determines the bottom n salaries of the
    employees within an organisation and inserts them into a table called
    LEAST_EARNERS. The block should prompt the user to accept a
    number n from the user where n represents the number of earners
    from the EMPLOYEES table. You should create a cursor called
    emp_cursor that retrieves the salaries of employees in ascending
    order. The salaries should not be duplicated. In the executable section,
    open the cursor and fetch the least n salaries and insert them into the
    LEAST_EARNERS table. Include any appropriate exceptions.

    thankyou for the help in advance

  2. #2
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    Quote Originally Posted by alankay246 View Post
    ...You should create a cursor called
    emp_cursor that retrieves the salaries of employees in ascending
    order. The salaries should not be duplicated. In the executable section,
    open the cursor and fetch the least n salaries and insert them into the
    LEAST_EARNERS table. Include any appropriate exceptions.
    Looks like your professor has been talking about cursors for the past few classes, take a look here: http://www.oracle.com/technetwork/is...ql-088608.html

    Please note that in the real world you do not have to have a cursor to solve this one.
    Last edited by PAVB; 05-04-2012 at 07:25 AM. Reason: typo
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  3. #3
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    4,166
    I bet you can get extra credit by writing the query to use analytics.

    http://orafaq.com/node/55

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width