0% found this document useful (0 votes)
32 views2 pages

IFELSE&

The document contains PL/SQL code snippets for retrieving department names and numbers from a database and calculating grades based on user input marks. It demonstrates the use of variables, conditional logic with IF-ELSE and CASE statements, and outputting results using DBMS_OUTPUT. The code is structured to handle specific department queries and grade evaluations based on defined ranges.

Uploaded by

Shiva Ram Vemula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

IFELSE&

The document contains PL/SQL code snippets for retrieving department names and numbers from a database and calculating grades based on user input marks. It demonstrates the use of variables, conditional logic with IF-ELSE and CASE statements, and outputting results using DBMS_OUTPUT. The code is structured to handle specific department queries and grade evaluations based on defined ranges.

Uploaded by

Shiva Ram Vemula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

-- display deptno, dname from dept.

SET SERVEROUTPUT ON;


variable b_deptno number;
variable b_dname varchar2(30);

BEGIN
SELECT DEPTNO, DNAME INTO :b_deptno,:b_dname FROM DEPT WHERE DEPTNO = 10;
DBMS_OUTPUT.PUT_LINE(:b_deptno || ' ' || :b_dname);
END;

---
BEGIN
SELECT DEPTNO, DNAME INTO :b_deptno,:b_dname FROM DEPT WHERE DEPTNO = 20;
DBMS_OUTPUT.PUT_LINE(:b_deptno || ' ' || :b_dname);
END;

---
DECLARE
V_DEPTNO DEPT.DEPTNO%TYPE;
V_DNAME DEPT.DNAME%TYPE;
BEGIN
SELECT DEPTNO, DNAME INTO V_DEPTNO,V_DNAME FROM DEPT WHERE DEPTNO = &DEPTNO;
DBMS_OUTPUT.PUT_LINE(V_DEPTNO || ' ' || V_DNAME);
END;

----
-- TAKE MARKS AS INPUT FROM THE USER USING & AND CALCULATE GRADE.
MARKS BETWEEN 90 AND 100 - A
BETWEEN 80 AND 90 - B
BETWEEN 65 AND 80 - C
LESS THAN 65 - F
ELSE - I

------
DECLARE
V_MARKS NUMBER := &MARK;
V_GRADE CHAR;
BEGIN
-- LOGIC FOR GETTING GRADE
-- USING IF ELSE
IF (V_MARKS BETWEEN 90 AND 100)
THEN
V_GRADE := 'A';
ELSIF (V_MARKS >= 80 AND V_MARKS <90)
THEN
V_GRADE := 'B';
ELSIF (V_MARKS >= 65 AND V_MARKS <80)
THEN
V_GRADE := 'C';
ELSIF (V_MARKS< 65 AND V_MARKS >= 0)
THEN
V_GRADE := 'F';
ELSE
V_GRADE := 'I';
END IF;
DBMS_OUTPUT.PUT_LINE(V_GRADE);
END;

-----
DECLARE
V_MARKS NUMBER := &MARK;
V_GRADE CHAR;
BEGIN
-- LOGIC FOR GETTING GRADE
-- USING CASE WHEN
CASE
WHEN (V_MARKS BETWEEN 90 AND 100)
THEN
V_GRADE := 'A';
WHEN (V_MARKS >= 80 AND V_MARKS <90)
THEN
V_GRADE := 'B';
WHEN (V_MARKS >= 65 AND V_MARKS <80)
THEN
V_GRADE := 'C';
WHEN (V_MARKS< 65 AND V_MARKS >= 0)
THEN
V_GRADE := 'F';
ELSE
V_GRADE := 'I';
END CASE;
DBMS_OUTPUT.PUT_LINE(V_GRADE);
END;

You might also like