You are on page 1of 1

DECLARE

r_customer customers%ROWTYPE;
BEGIN
-- get the info of the customer 100
SELECT * INTO r_customer from customers where cid = 101;
-- show the customer info
dbms_output.put_line(r_customer.cname || ',address: ' || r_customer.address );
END;

#NO_DATA_FOUND
DECLARE
I_name customers.cname%TYPE;
I_customer_id customers.cid%TYPE := 8;
BEGIN
-- get the customer
SELECT cname INTO I_name from customers where cid = I_customer_id;
--show the customer name
dbms_output.put_line('customer name is ' || I_name);
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line('Customer ' || I_customer_id || ' does not exist');
WHEN others THEN
dbms_output.put_line('Error!');
END;

#TOO_MANY_ROWS
DECLARE
I_name customer.cname%TYPE;
I_customer_id customers.cid%TYPE := 101;
BEGIN
--get the customer
SELECT cname INTO I_name FROM customers WHERE cid <= I_customer_id;
--show the customer name
dbms_output.put_line('Customer name is '||I_name);
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output_line('Customer ' || I_customer_id || 'does not exist');
WHEN TOO_MANY_ROWS THEN
dbms_output.put_line("The database returns more than one customer');
END;
/

You might also like