Plsql8
Plsql8
Plsql8
DIGITAL ASSIGNMENT-8
BCSE302P
FALL SEM 2024-25
Submitted
by
22BCE2394
Yuvraj Kr
Under Faculty-
SRIDEVI S
VIT, Vellore
6. Arithmetic Operators
DECLARE
num1 NUMBER := 10;
num2 NUMBER := 5;
sum NUMBER;
difference NUMBER;
product NUMBER;
quotient NUMBER;
BEGIN
sum := num1 + num2;
difference := num1 - num2;
product := num1 * num2;
quotient := num1 / num2;
7.Relational Operators
DECLARE
num1 NUMBER := 10;
num2 NUMBER := 5;
BEGIN
IF num1 > num2 THEN
DBMS_OUTPUT.PUT_LINE(num1 || ' is greater than ' || num2);
ELSIF num1 < num2 THEN
DBMS_OUTPUT.PUT_LINE(num1 || ' is less than ' || num2);
ELSE
DBMS_OUTPUT.PUT_LINE(num1 || ' is equal to ' || num2);
END IF;
END;
/
OUTPUT
8. Logical Operators
DECLARE
age NUMBER := 20;
has_permission BOOLEAN := TRUE;
BEGIN
IF (age >= 18 AND has_permission) THEN
DBMS_OUTPUT.PUT_LINE('Access granted.');
ELSE
DBMS_OUTPUT.PUT_LINE('Access denied.');
END IF;
END;
/
OUTPUT
9.Assignment Operators
DECLARE
total NUMBER := 0;
value NUMBER := 10;
BEGIN
total := total + value; -- Using the += operator
DBMS_OUTPUT.PUT_LINE('Total: ' || total);
END;
/
OUTPUT
OUTPUT
11. Creating a Table and Inserting Data
CREATE TABLE EMPLOYEE (
empId NUMBER PRIMARY KEY,
name VARCHAR2(15) NOT NULL,
dept VARCHAR2(10) NOT NULL
);
OUTPUT
15.Nested IF Statement
DECLARE
salary NUMBER := 50000;
BEGIN
IF salary < 30000 THEN
DBMS_OUTPUT.PUT_LINE('Salary is low.');
ELSIF salary >= 30000 AND salary < 60000 THEN
DBMS_OUTPUT.PUT_LINE('Salary is moderate.');
IF salary < 45000 THEN
DBMS_OUTPUT.PUT_LINE('Consider asking for a raise.');
ELSE
DBMS_OUTPUT.PUT_LINE('You have a decent salary.');
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('Salary is high.');
END IF;
END;
/
OUTPUT
OUTPUT
22.Strings
DECLARE
name varchar2(20);
company varchar2(30);
introduction clob;
choice char(1);
BEGIN
name := 'John Smith';
company := 'Infotech';
introduction := 'Hello! I''m John Smith from Infotech.';
choice := 'Y';
dbms_output.put_line(name);
dbms_output.put_line(company);
dbms_output.put_line(introduction);
END;
/
OUTPUT
23.Arrays
DECLARE
TYPE namesarray IS VARRAY(5) OF VARCHAR2(10);
TYPE grades IS VARRAY(5) OF INTEGER;
names namesarray;
marks grades;
total integer;
BEGIN
names := namesarray('Kavita', 'Pritam', 'Ayan', 'Rishav', 'Aziz');
marks := grades(98, 97, 78, 87, 92);
total := names.count;
dbms_output.put_line('Total '|| total || ' Students');
FOR i in 1 .. total LOOP
dbms_output.put_line('Student: ' || names(i) || ' Marks: ' || marks(i));
END LOOP;
END;
/
OUTPUT