Dbms Worksheet-3: Name: - Praduman Kumar Section: - 20ITB5 UID: - 20BCS9446
Dbms Worksheet-3: Name: - Praduman Kumar Section: - 20ITB5 UID: - 20BCS9446
Code:-
create table dept(
deptno number(2,0),
dname varchar2(14),
loc varchar2(13),
constraint pk_dept primary key (deptno)
)
Screenshot:-
2. Create table EMP with the following description :
Name Type
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(3)
AGE NUMBER(3)
ESAL NUMBER
1. Get the description EMP table.
2. List all employees details.
3. List all employee names and their salaries, whose salary lies
between 1500/- and 3500/- both inclusive.
4. List all employee names and their and their manager whose
manager is 7902 or 7566 0r 7789.
5. List all employees who belongs to the department 10 or 20
Code:-
SQL>desc emp;
RESULT:-
Name Null? Type
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(3)
AGE NUMBER(3)
ESAL NUMBER(10)
RESULT:-
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO AGE ESAL
INPUT:-
SQL>select ename from emp where sal between 1500 and 3500;
RESULT:-
ENAME
----------
ALLEN
JONES
BLAKE
CLARK
SCOTT
TURNER
FORD
russel
greg
9 rows selected.
4. List all employee names and their and their manager whose
manager is 7902 or 7566 0r 7789.
RESULT:-
ENAME
-------
SCOTT
FORD
RESULT:-
ENAME
---------
SMITH
JONES
CLARK
SCOTT
KING
ADAMS
FORD
MILLER
8 rows selected.
Code:-
DECLARE
n NUMBER := 0;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE ('The value of n inside the loop is: ' ||
TO_CHAR(n));
n := n + 1;
IF n > 5 THEN
EXIT;
END IF;
END LOOP;
DBMS_OUTPUT.PUT_LINE('The value of n outside the loop is: ' ||
TO_CHAR(n));
END;
/
Screenshot:-
Output:-
Here, first, we take three variables num, fact, and temp and assign the
value in num variable (i.e which number factorial we want).
And then after we assign fact variable to 1.
Examples:
Input : 4
Output : 24
Input : 6
Output : 720
Code:-
declare
begin
temp :=num;
end loop;
end;
-- Program End
Screenshot:-
Output :-
factorial of 6 is 720.