DSAD
DSAD
DSAD
DECLARE
i NUMBER;
rev_number NUMBER;
original_num NUMBER;
BEGIN
FOR i IN 1..100 LOOP
original_num := i;
rev_number := 0;
WHILE original_num > 0 LOOP
rev_number := rev_number * 10 + MOD(original_num, 10);
original_num := FLOOR(original_num / 10);
END LOOP;
DBMS_OUTPUT.PUT_LINE('Reverse of ' || i || ' is ' || rev_number);
END LOOP;
END;
/
2)
DECLARE
num1 NUMBER := 70;
num2 NUMBER := 100;
num3 NUMBER := 777;
greatest_num NUMBER;
BEGIN
IF num1 >= num2 AND num1 >= num3 THEN
greatest_num := num1;
ELSIF num2 >= num1 AND num2 >= num3 THEN
greatest_num := num2;
ELSE
greatest_num := num3;
END IF;
3)
DECLARE
n NUMBER := 14;
a NUMBER := 0;
b NUMBER := 1;
fib_number NUMBER;
i NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE('Fibonacci Series:');
DBMS_OUTPUT.PUT_LINE(a);
DBMS_OUTPUT.PUT_LINE(b);
DECLARE
reservation_date DATE := TO_DATE('2023-11-05', 'YYYY-MM-DD');
today_date DATE := TRUNC(SYSDATE);
BEGIN
IF reservation_date < today_date THEN
RAISE_APPLICATION_ERROR(-20001, 'Reservation date cannot be in the past');
ELSE
DBMS_OUTPUT.PUT_LINE('Reservation date is valid');
END IF;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred: ');
END;
/
5)
DECLARE
CURSOR flight_cursor IS
SELECT Flight_number,Airline,Weekdays from FLiGHT1;
flight_rec flight_cursor%ROWTYPE;
BEGIN
OPEN flight_cursor;
LOOP
FETCH flight_cursor INTO flight_rec;
EXIT WHEN flight_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('Flight_number :' || flight_rec.Flight_number);
DBMS_OUTPUT.PUT_LINE('Airline ' || flight_rec.Airline);
DBMS_OUTPUT.PUT_LINE('Weekdays: ' || flight_rec.Weekdays);
DBMS_OUTPUT.NEW_LINE;
END LOOP;
CLOSE flight_cursor;
END;
/
DECLARE
CURSOR flight_cursor IS
SELECT flight_id, flight_name, departure_airport_id,
destination_airport_id, departuer_time
FROM flights;
flight_rec flight_cursor%ROWTYPE;
BEGIN
OPEN flight_cursor;
LOOP
FETCH flight_cursor INTO flight_rec;
EXIT WHEN flight_cursor%NOTFOUND; DBMS_OUTPUT.PUT_LINE('Flight ID: '
|| flight_rec.flight_id);
DBMS_OUTPUT.PUT_LINE('Flight Name: ' || flight_rec.flight_name);
DBMS_OUTPUT.PUT_LINE('Departure Airport ID: ' ||
flight_rec.departure_airport_id);
DBMS_OUTPUT.PUT_LINE('Destination Airport ID: ' ||
flight_rec.destination_airport_id);
DBMS_OUTPUT.PUT_LINE('Departure Time: ' || flight_rec.departuer_time);
DBMS_OUTPUT.NEW_LINE;
END LOOP;
CLOSE flight_cursor;
END;
/
6)
DECLARE
CURSOR flight_cursor IS
SELECT *
FROM flights
WHERE flight_id BETWEEN 1200 AND 2900;
flight_rec flights%ROWTYPE;
BEGIN
OPEN flight_cursor;
LOOP
FETCH flight_cursor INTO flight_rec;
EXIT WHEN flight_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('Flight ID: ' || flight_rec.flight_id);
DBMS_OUTPUT.PUT_LINE('Flight Name: ' || flight_rec.flight_name);
DBMS_OUTPUT.PUT_LINE('Departure Airport ID: ' ||
flight_rec.departure_airport_id);
DBMS_OUTPUT.PUT_LINE('Destination Airport ID: ' ||
flight_rec.destination_airport_id);
DBMS_OUTPUT.PUT_LINE('DepartureTime: ' || flight_rec.departuer_time);
DBMS_OUTPUT.NEW_LINE;
END LOOP;
CLOSE flight_cursor;
END;
/
7)
company_name_var VARCHAR2(100);
airplane_id_var NUMBER;
BEGIN
OPEN company_airplane_cur;
LOOP
FETCH company_airplane_cur INTO company_name_var, airplane_id_var;
EXIT WHEN company_airplane_cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('Company: ' || company_name_var || ' | Airplane ID: ' ||
airplane_id_var);
END LOOP;
CLOSE company_airplane_cur;
END;
/
9)
RETURN v_flight_count;
END;
/
10)
SELECT a.airport_name
FROM Airports a
JOIN (
SELECT ap.airport_code, COUNT(DISTINCT ap.airplane_type) as type_count
FROM Airplanes ap
GROUP BY ap.airport_code
ORDER BY type_count DESC
) t
ON a.airport_code = t.airport_code
WHERE ROWNUM = 1;
11)
12)
13)
14)