Changes

Jump to: navigation, search

YSL

1,494 bytes added, 10:19, 16 October 2011
2.
<pre>
 
SET SERVEROUTPUT ON
SET VERIFY OFF
ACCEPT region PROMPT 'Enter value for region: '
 
 
DECLARE
v_region_id REGIONS.region_id%TYPE;
country COUNTRIES.country_name%TYPE;
BEGIN
SELECT region_id INTO v_region_id
FROM REGIONS
WHERE region_id = &region;
 
 
BEGIN <<inner>>
SELECT country_name INTO country
FROM COUNTRIES
WHERE region_id = &region
AND country_id NOT IN (
SELECT DISTINCT country_id
FROM LOCATIONS
);
 
 
IF SQL%ROWCOUNT = 1 THEN
DBMS_OUTPUT.PUT_LINE('In the region ' || &region || ' there is ONE country ' || country || ' with NO city');
 
 
UPDATE COUNTRIES
SET flag = 'Empty_' || region_id
WHERE country_id NOT IN (
SELECT DISTINCT country_id
FROM LOCATIONS
);
 
 
DBMS_OUTPUT.PUT_LINE('Number of countries with NO cities listed is: ' || SQL%ROWCOUNT);
END IF;
 
 
EXCEPTION
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('This region ID has MORE THAN ONE country without cities listed: ' || &region);
END inner;
 
 
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('This region ID does NOT exist: ' || &region);
END;
/
 
 
SELECT *
FROM COUNTRIES
WHERE country_id NOT IN (
SELECT DISTINCT country_id
FROM LOCATIONS
)
AND flag IS NOT NULL
ORDER BY region_id, country_name;
 
 
ROLLBACK;
</pre>
<pre>
</pre>
 
 
 
===3.===
1
edit

Navigation menu