You are on page 1of 2

1. Write down the structure of a PL/SQL block.

With the help of example explain simple


loop, while loop and for loop.
2. What is a cursor? What is special about cursor for loop?
3. Explain if statement, with example, in PL/SQL
4. Write a PL/SQL block to compute area and perimeter of a rectangle and a circle.
5. Write a PL/SQL block to compute the sum of square of first 10 odd numbers.
6. Write suitable PL/SQL code to illustrate use of goto.
7. Rewrite the following IF statements so that you do not use an IF statement to set the
value of no_revenue . What is the difference between these two statements? How does that
difference affect your answer?
IF total_sales <= 0
THEN
no_revenue := TRUE;
ELSE
no_revenue := FALSE;
END IF;
IF total_sales <= 0
THEN
no_revenue := TRUE;
ELSIF total_sales > 0
THEN
no_revenue := FALSE;
END IF;

8. Rewrite the following IF statement to work as efficiently as possible under all conditions,
given the following information: the calc_totals numeric function takes three minutes to
return its value, while the overdue_balance Boolean function returns TRUE/FALSE in
less than a second.
IF calc_totals (1994, company_id_in => 1005) AND
NOT overdue_balance (company_id_in => 1005)
THEN
display_sales_figures (1005);
ELSE
contact_vendor;
END IF;

9. Rewrite the following IF statement to get rid of unnecessary nested IFs:


IF salary < 10000
THEN
bonus := 2000;
ELSE
IF salary < 20000
THEN
bonus := 1500;
ELSE
IF salary < 40000
THEN
bonus := 1000;
ELSE
bonus := 500;
END IF;

END IF;
END IF;

10. Which procedure will never be executed in this IF statement?


IF (order_date > SYSDATE) AND order_total >= min_order_total
THEN
fill_order (order_id, 'HIGH PRIORITY');
ELSIF (order_date < SYSDATE) OR
(order_date = SYSDATE)
THEN
fill_order (order_id, 'LOW PRIORITY');
ELSIF order_date <= SYSDATE AND order_total < min_order_total
THEN
queue_order_for_addtl_parts (order_id);
ELSIF order_total = 0
THEN
disp_message (' No items have been placed in this order!');
END IF;

11. How many times does the following loop execute?


FOR year_index IN REVERSE 12 .. 1
LOOP
calc_sales (year_index);
END LOOP;

12. Select the type of loop (FOR, WHILE, simple) appropriate to meet each of the
following requirements:
a) Set the status of each company whose company IDs are stored in a PL/SQL table to
closed.
b) For each of twenty years in the loan-processing cycle, calculate the outstanding loan
balance for the specified customer. If the customer is a preferred vendor, stop the
calculations after twelve years.
c) Display the name and address of each employee returned by the cursor.
d) Scan through the list of employees in the PL/SQL table, keeping count of all
salaries greater than $50,000. Don't even start the scan, though, if the table is empty
or if today is a Saturday or if the first employee in the PL/SQL table is the president
of the company.

You might also like