w3resource

PL/SQL Control Statement Exercises: Calculate the incentive on a target achieved and display the message either the record updated or not

PL/SQL Control Statement: Exercise-2 with Solution

Write a PL/SQL procedure to calculate the incentive on a target achieved and display the message either the record updated or not.

Sample Solution:

PL/SQL Code:

DECLARE
  PROCEDURE test1 (
    sal_achieve  NUMBER,
    target_qty  NUMBER,
    emp_id NUMBER
  )
  IS
    incentive   NUMBER := 0;
    updated  VARCHAR2(3) := 'No';
  BEGIN
    IF sal_achieve > (target_qty + 200) THEN
      incentive := (sal_achieve - target_qty)/4;
 
      UPDATE emp
      SET salary = salary + incentive 
      WHERE employee_id = emp_id;
 
      updated := 'Yes';
    END IF;
 
    DBMS_OUTPUT.PUT_LINE (
      'Table updated?  ' || updated || ', ' || 
      'incentive = ' || incentive || '.'
    );
  END test1;
BEGIN
  test1(2300, 2000, 144);
  test1(3600, 3000, 145);
END;
/

Sample Output:

Table updated?  Yes, incentive = 75.
Table updated?  Yes, incentive = 150.

PL/SQL procedure successfully completed.

Flowchart:

Flowchart: PL/SQL Control Statement Exercises: Calculate the incentive on a target achieved and display the message either the record updated or not

Improve this sample solution and post your code through Disqus

Previous: Write a PL/SQL program to arrange the number of two variable in such a way that the small number will store in num_small variable and large number will store in num_large variable.
Next: Write a PL/SQL program to check whether a number is even or odd.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.