Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7416359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:28:50+00:00 2026-05-29T07:28:50+00:00

I keep getting the no data found when I execute this PL/SQL block. If

  • 0

I keep getting the “no data found” when I execute this PL/SQL block. If I comment out the output line, everything outputs as I would suspect, but the update statement never executes. Any ideas?

set serveroutput on;
Declare
   TYPE type_emp IS RECORD(
        emp_salary emp.salary%TYPE);
     rec_emp type_emp;
   v_stars varchar2(50) ;
   v_count number(3);
   s_num number(3);
begin
 SELECT min(employee_id) into s_num from emp;
 SELECT count(*) into v_count from emp;
 v_count := v_count + s_num;
 for i in s_num .. v_count loop
   SELECT salary
     into rec_emp
     from emp
    where employee_id = i; 
    if rec_emp.emp_salary <1000 then 
        v_stars := null;
      elsif rec_emp.emp_salary >=1000 and rec_emp.emp_salary <2000 then 
        v_stars := '*';
      elsif rec_emp.emp_salary >=2000 and rec_emp.emp_salary <3000 then 
        v_stars := '**';
      elsif rec_emp.emp_salary >=3000 and rec_emp.emp_salary <4000 then 
        v_stars := '***';
      elsif rec_emp.emp_salary >=4000 and rec_emp.emp_salary <5000 then 
        v_stars := '****';
      elsif rec_emp.emp_salary >=5000 and rec_emp.emp_salary <6000 then 
        v_stars := '*****';
      elsif rec_emp.emp_salary >=6000 and rec_emp.emp_salary <7000 then 
        v_stars := '******';
      elsif rec_emp.emp_salary >=7000 and rec_emp.emp_salary <8000 then 
        v_stars := '*******';
      elsif rec_emp.emp_salary >=8000 and rec_emp.emp_salary <9000 then
        v_stars := '********';
      elsif rec_emp.emp_salary >=9000 and rec_emp.emp_salary <10000 then 
        v_stars := '*********';
      elsif rec_emp.emp_salary >=10000 and rec_emp.emp_salary <11000 then 
        v_stars := '**********';
      elsif rec_emp.emp_salary >=11000 and rec_emp.emp_salary <12000 then 
        v_stars := '***********';
      elsif rec_emp.emp_salary >=12000  then 
        v_stars := '************';
    end if;
    --dbms_output.put_line(rec_emp.emp_salary || '   ' || i || '      '|| v_stars);  
    update emp set emp.stars = v_stars where employee_id = i;
 end loop;
 end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:28:51+00:00Added an answer on May 29, 2026 at 7:28 am

    You’re using a very unusual method to iterate through all the records in the table. Your method assumes that the employee IDs are contiguous (i.e. no gaps). It also has an off-by-one error.

    Let’s say your table has the following rows:

    100
    101
    102
    103
    104
    

    Firstly you get the minimum employee ID: s_num = 100.

    Then, you get the count of records: v_count = 5.

    Finally, you add these together to get the upper bound: s_num + v_count = 105

    Can you see the problem with your loop now? On the last iteration, your query:

    SELECT salary
     into rec_emp
     from emp
    where employee_id = i; 
    

    Will look for employee ID 105, which raises NO_DATA_FOUND. The DBMS_OUTPUT calls were already done, so you’d see the output; but the unhandled exception causes a rollback, which means your UPDATEs are undone.

    Instead, you could make your loop much simpler, e.g.:

    FOR rec_emp IN (SELECT employee_id, salary AS emp_salary FROM emp) LOOP
      if rec_emp.emp_salary <1000 then 
        v_stars := null;
      elsif <snip>
        ...
      end if;
      --dbms_output.put_line(rec_emp.emp_salary || '   ' || i || '      '|| v_stars);  
      update emp set emp.stars = v_stars where employee_id = i;
    END LOOP;
    

    The above code is slightly more efficient too. It could be made even more efficient, but I don’t want this answer to go too far past what you’ve got so far.

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep on getting this error error: expected specifier-qualifier-list for core data code im
We keep getting this error randomly in our web application. System.Data.SqlClient.SqlException: A network-related or
I'm trying to pull data into flash using JSON but i keep getting this
Keep getting this error after inserting a subdatasheet into a query and trying to
I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
I keep getting this NPE in my application and I can't seem to get
I keep getting this : DeprecationWarning: integer argument expected, got float How do I
I want to deserialize the following json data https://mtgox.com/code/data/getDepth.php . I keep getting an
I am trying to config my github account. However, I keep getting this error
I keep getting ADB rejected shell command (ls -l /data): and the command prompt

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.