Ex 8 D
Ex 8 D
Ex 8 D
no rows selected
RETURN v_count;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END;
/
6 rows selected.
5.Create a function to get the start date of the discount by the promotion_id.
RETURN v_date;
END;
/
PROMOTION_ID START_DAT
------------ ---------
701 13-FEB-24
704 28-APR-24
705 05-FEB-24
707 28-APR-24
709 01-MAY-24
710 01-APR-24
711 01-MAY-24
7 rows selected.
RETURN v_total_amount;
END;
/
PAYMENT_D CALCULATE_TOTAL_AMOUNT_PAID(PAYMENT_DATE)
--------- -----------------------------------------
15-FEB-24 32000
19-FEB-24 11000
09-MAY-24 9000
10-FEB-24 14000
03-DEC-24 10000
15-FEB-24 32000
6 rows selected.
RETURN v_count;
END;
/
BRANCH_NAME FIND_NO_OF_BRANCH(BRANCH_NAME)
-------------------- ------------------------------
sivakasi_branch 1
virudhunagar_branch 1
madurai_branch 4
aruppukottai_branch 1
rajapalayam_branch 1
chennai_branch 1
6 rows selected.
DECLARE
p_id payment.payment_id%type;
p_amount payment.amount%type;
p_date payment.payment_date%type;
CURSOR p_payment IS
SELECT payment_id,amount,payment_date from payment;
BEGIN
OPEN p_payment;
LOOP
FETCH p_payment into p_id,p_amount,p_date;
EXIT WHEN p_payment%notfound;
dbms_output.put_line(p_id || ' ' || p_amount || ' ' || p_date);
END LOOP;
CLOSE p_payment;
END;
/
DECLARE
2 CURSOR c_leastexperience_driver IS
3 SELECT d_id,driver_name,age,license_info FROM driver where experience
< (select avg(experience) from driver);
4 c_d_id driver.d_id%type;
5 c_name driver.driver_name%type;
6 c_age driver.age%type;
7 c_license_info driver.license_info%type;
8 BEGIN
9 OPEN c_leastexperience_driver;
10 LOOP
11 FETCH c_leastexperience_driver INTO c_d_id,c_name,c_age,c_license_info;
12 EXIT WHEN c_leastexperience_driver%NOTFOUND;
13 dbms_output.put_line('Id:'||c_d_id);
14 dbms_output.put_line(' Name:'||c_name);
15 dbms_output.put_line(' Age:'||c_age);
16 dbms_output.put_line(' License Info:'||c_license_info);
17 END LOOP;
18 CLOSE c_leastexperience_driver;
19 END;
20 /
Id:10
Name:ayyanar
Age:30
License Info:bv2468
Id:1
Name:arjun
Age:21
License Info:ad1234
Id:12
Name:abish kumar
Age:30
License Info:ad1234
Id:3
Name:balaji
Age:19
License Info:eg2341
Id:2
Name:murugan
Age:21
License Info:vb1357
Id:17
Name:arun karthick
Age:21
License Info:ad1254
Id:16
Name:ashwin
Age:21
License Info:an1234
DECLARE
CURSOR active_discount IS
SELECT count(*)
FROM promotion_and_discount
WHERE start_date <= sysdate and end_date >= sysdate;
discount_count number;
BEGIN
OPEN active_discount;
FETCH active_discount INTO discount_count;
DBMS_OUTPUT.PUT_LINE('Active Discount:'||discount_count);
CLOSE active_discount;
END;
/
Active Discount:4
RETURN v_payment_data;
END;
/
DECLARE
v_payment_data payment%rowtype;
BEGIN
v_payment_data := get_payment_data(316);
DBMS_OUTPUT.PUT_LINE('Payment ID: ' || v_payment_data.payment_id);
DBMS_OUTPUT.PUT_LINE('Amount: ' || v_payment_data.amount);
DBMS_OUTPUT.PUT_LINE('Payment Date: ' || TO_CHAR(v_payment_data.payment_date,
'DD-MON-YYYY'));
DBMS_OUTPUT.PUT_LINE('Transaction Detail: ' ||
v_payment_data.transaction_detail);
DBMS_OUTPUT.PUT_LINE('Payment Method: ' || v_payment_data.payment_method);
DBMS_OUTPUT.PUT_LINE('Customer ID: ' || v_payment_data.customer_id);
END;
/
SQL> declare
2 v_count number;
3 begin
4 v_count:=driver_count();
5 end;
6 /
Total Drivers: 12
RETURN TRUE;
END;
/
DECLARE
num_to_check NUMBER := 12;
is_prime_number BOOLEAN;
BEGIN
is_prime_number := is_prime(num_to_check);
IF is_prime_number THEN
DBMS_OUTPUT.PUT_LINE(num_to_check || ' is a prime number.');
ELSE
DBMS_OUTPUT.PUT_LINE(num_to_check || ' is not a prime number.');
END IF;
END;
/
DECLARE
num_to_check NUMBER := 13;
is_prime_number BOOLEAN;
BEGIN
is_prime_number := is_prime(num_to_check);
IF is_prime_number THEN
DBMS_OUTPUT.PUT_LINE(num_to_check || ' is a prime number.');
ELSE
DBMS_OUTPUT.PUT_LINE(num_to_check || ' is not a prime number.');
END IF;
END;
/
13 is a prime number.