Professional Documents
Culture Documents
SQL Practical 1
SQL Practical 1
SQL>select*from depth;
DEPTNO DNAME LOCATION
------------ ----------- ----------------
10 Research Pune
20 Sales satara
30 sales satara
Equi-join:
SQL>select emp.deptno,emp.ename,dept.dname from emp,dept where
emp.deptno=dept.deptno;
DEPTNO ENAME DNAME
------------ ----------- -----------
10 Anil Research
30 Suresh sales
Outer-join:
SQL>select e.deptno,e.name,d.dname from emp e,dept d where
e.deptno(+)=d.deptno;
DEPTNO ENAME DNAME
------------- ----------- -----------
10 Anil Research
30 Suresh Sales
Left Outer-join:
SQL>select*from emp left outer join dept on emp.detpno=dept.deptno;
Full Outer-join:
SQL>select*from emp full outer join dept on emp.deptno=dept.deptno;
ENAME JOB DEPTNO DEPTNO DNAME LOCATION
---------- ----- ----------- ---------- ---------- -------------
Anil Mgr 10 10 Research Pune
Suresh Accountant 30 30 sales satara
Niraj Salesman 50 NULL NULL NULL
NULL NULL NULL 20 sales satara
Assignment No. 6
//Creating views and Index.
SQL>select*from emp;
EMPNO ENAME SAL DEPTNO
----------- ---------- ------- ------------
1 Suyash 15000 10
2 Vinod 20000 20
3 Ram 18000 30
SQL>select*from dept;
DEPTNO DNAME ENAME
------------ ------------ ------------
10 Account Suyash
20 Manager Vinod
30 Supervisor Ram
Creating Views
SQL>create view sal<18000 as select empno,ename,sal from emp where
sal<=18000;
View created.
SQL>select*from sal<18000;
EMPNO ENAME SAL
----------- ----------- ------
1 Suyash 15000
3 Ram 18000
Join View
SQL> create view emp_dp_vw as select
e.empno,e.ename,e.sal,d.deptno,d.dname from emp e,dept d where
e.deptno=d.deptno;
View created.
SQL>select*from emp_dp_vw;
EMPNO ENAME SAL DEPTNO DNAME
----------- ---------- ----- ----------- -----------
1 Suyash 15000 10 Account
2 Vinod 20000 20 manager
3 Ram 18000 30 supervisor
IF else
SQL>DECLARE
N number (2);
BEGIN
N:=&number;
If N<=5 then
DBMS _OUTPUT.PUT _LINE(‘Entered no is less than 5’);
Else
DBMS _OUTPUT.PUT _LINE(‘Entered no is less than 5’);
End if;
END;
/
Output:
Enter value for number:3
Old 4: N:=&Number;
New 4: N:=3;
Entered number is less than 5
PL/SQL procedure successfully completed.
If then Else if
SQL>Declare
a number;
b number;
c number;
Begin
dbms_output.put_line(‘Enter a:’);
a:=&a;
dbms_output.put_line(‘Enter b:’);
b:=&b;
dbms_output.put_line(‘Enter c:’);
c:=&c;
if(a>b)&(a>c)then
dbms_output.put_line(‘A is a GREATEST’||A);
elsif(b>a) and(b>c)then
dbms_output.put_line(‘B is a GREATEST’||B);
else
dbms_output.put_line(‘C is a GREATEST’||C);
end if;
End;
/
Output:
Enter value for a:2
Old 7: a:=&a;
New 7: a:=2;
Enter value for b:3
Old 9: b:=&b;
New 9: b:=3;
Enter value for c:4
Old 11: c:=&c;
New 11: c:=4;
Enter a:2
Enter b:3
Enter c:4
C is GREATEST 4
PL/SQL procedure successfully completed.
Assignment No.4
Arithmetic Function:-
Aggregate Function:-
Numeric Function:-
Character Function:-
Conversion Function:-