Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

Assignment No.

//SQL queries on JOIN.


SQL>select* from emp;
ENAME JOB DEPTNO
----------- ------ ------------
Anil Mgr 10
Suresh Accountant 30
Niraj Salesman 50

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;

ENAME JOB DEPTNO DEPTNO DNAME LOCATION


---------- ----- ----------- ---------- ---------- -------------Anil
Mgr 10 10 Research Pune
Suresh Accountant 30 30 sales satara
Niraj Salesman 50 NULL NULL NULL
Right Outer-join:
SQL>select*from emp right 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
NULL NULL NULL 20 Sales satara

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

Creating Read Only View.


SQL>create view dept30 as select*from emp where deptno=30 with
read only;
View created.
SQL>select*from dept30;
EMPNO ENAME SAL DEPTNO
----------- ----------- ------ ------------
3 Ram 18000 30
Drop view.
SQL>drop view dept30;
View dropped.
Create Index .
SQL> Create index nm_idx on emp(ename);
Index created.
Alter Index.
SQL> Create index nm_idx rename to name_index;
Index altered.
Drop Index.
SQL> drop index name_index;
Index dropped.
Assignment No.7
//PL-SQL block on branching statement.
Simple if:
SQL>DECLARE
X number:=10;
BEGIN
LOOP
dbms_output.put_line(x);
x:=x+10;
IF x>50 THEN
Exit IF;
END LOOP;
dbms_output.put_line(‘After exit x is:’||x);
END;
/
Output:
10
20
30
40
50
After exit x is:60.

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:-

You might also like