Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2014
    Posts
    11

    Unanswered: How to handle error in 5th counting on cursor

    Suppose I have 10 records whenever cursor reach in 5th no. then we have to generate error, please let me know that how to cursor work for 10 records.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Show us how you are writing/using your cursor. That way we can show you the best solution based on your usage and style.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Mar 2014
    Posts
    11
    My output like should be:

    employee_id = 1
    employee_id = 2
    employee_id = 3
    employee_id = 4
    employee_id = 5 generate issue
    employee_id = 6
    employee_id = 7
    employee_id = 8
    employee_id = 9
    employee_id = 10

  4. #4
    Join Date
    Dec 2007
    Posts
    253
    Please re-read Pat's post and respond on that basis.

  5. #5
    Join Date
    Mar 2014
    Posts
    11
    according to output, give me simple example of cursor.

  6. #6
    Join Date
    Mar 2007
    Posts
    623
    Ok, here you have a cursor giving the required output:
    Code:
    set serveroutput on
    declare
      cursor c_emp is
        select column_value employee_id
        from table( sys.odcinumberlist( 1,2,3,4,5,6,7,8,9,10 ) );
    begin
      for r_emp in c_emp loop
        if r_emp.employee_id = 5 then
          dbms_output.put_line( 'employee_id = '||to_char(r_emp.employee_id)
            ||' generate issue' );
        else
          dbms_output.put_line( 'employee_id = '||to_char(r_emp.employee_id) );
        end if;
      end loop;
    end;
    /
    As you did not post any input source, well, you probably do not have any, so this is correct code.

    Good luck.

  7. #7
    Join Date
    Mar 2014
    Posts
    11
    Thank you so much flyboy for providing good illustration.

  8. #8
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by aaditya321 View Post
    My output like should be:

    employee_id = 1
    employee_id = 2
    employee_id = 3
    employee_id = 4
    employee_id = 5 generate issue
    employee_id = 6
    employee_id = 7
    employee_id = 8
    employee_id = 9
    employee_id = 10
    You don't need a cursor for that output:
    Code:
    select 'employee_id = '||employee_id||decode(employee_id, 5, ' generate_issue', '')
    from employees;
    SQLFiddle example: http://sqlfiddle.com/#!4/6edfc/1
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

Posting Permissions

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