Oracle Data Types and DDL Commands Guide
Oracle Data Types and DDL Commands Guide
Data_Types:
Number(M,N) :-Ex1 : Salary Number(10,2); Ex2: Empid Number(8); Max
Size 38 Digit
Minimum Size Is 1 Digit
We Can Store Interger Values And Float Values. This
Data Type Is For Numeric Values
It Will Occupy The Space Based On The Input Value
(Column_Name) Data_Type Vsize Max Max Total- Data_Stored
Account_Bal Integer Dismal Value _In_Column
1000.50 Number (9,2) 6 7 2 9 1000.50
12345678.55 “ 7 2 9 Can’t Insert
1234567.555 “ 9 7 2 9 1234567.55
1234567.50 Number(7) 7 7 0 7 1234567
120.56 Number(38,38) Can’t Insert
.123456789 “ 9 0 38 38 .123456789
1234567898 Number(10,-2) 10 10 0 10 1234567800
123456 “ 6 10 0 10 123400
Number (10,-2) : -2 Means It Will Round Up Last Two Digits Ex1:12345 Col_Value :- 12300
It Will Support Null Values –It Won’t Occupy Any Space For That
Create:
Used To Make A New Database Object (Ex:Table, View,Synonm .............. Etc)
By Using Create Command We Can Create Table
Syntax:- Create Table <Table_Name> (Col1 Datatype, Col2 Datatyp, Col3
Datatype……Coln Datatype);
Ex: Create Table Student_Info (Roll_No Number(4), Stu_Name
Varchar2(25), Stu_Class Number(3), Stu_Dob Date, Marks
Number(4));
Iq-1)Table Can Have Maximm 1000 Columns
Iq-2)Table Name Or Column Name Should Be <= 30 Character, (Note:- All The
Object Name Should Be <= 30 Characters, Ex: Index Name, View Name, Synonym…)
Iq-3)Types Of Tables (Data Base Table (Sql Table), Nested Table, Global Temporary Table,
External Table, Partition Table)
4
Iq-4)How To See The Column Names And Their Data Types After Create The Tables?
>Desc <Table_Name>; Ex: Desc Emp;
Iq-5)How To Get The Table Creation Script Or Object Creation Script (Ddl Script) ? Select
Dbms_Metadata.Get_Ddl(‘Table’,’Emp’) From Dual;
Select Dbms_Metadata.Get_Ddl(<Object_Type>,<Object_Name>); Iq-
6)We Can’t Create Two Database Objects With Same Name
Ex: Create Table Stu_Info (Roll Number(3), Stu_Name Varchar2(30); ->R Create Table
Stu_Info (Roll_No Number, Stu_Name Char(9), Age Number(3));-> W
Alter Command:-
Iq-1: We Can’t Drop The Table If That Table Is Master (Parent) Table; We Have To Use
Cascade Constraint To Drop Parent Table.
Ex: Drop Table Dept Cascade Constraints;
Dql : Data Query Language
Used To Retrive Data Or Infromation From The Table For Read Only Purpose Syntax :- Select
Col1, Col2, … From <Table_Name> Or Select * From <Tab_Name); Ex: Select * From Emp
(Or) Select Empno, Ename, Sal From Emp;
5
Where Clause: Used To Specify Conditions While Manipulating Or Retrieving Data From
Tables
Ex: Select * From Student_Info Where Roll_N0= 2;
Dml: Data Manipulation Language
Used To Manipulate The Infromation In The Existing Database Objects Dml
Commands :- Insert , Update, Delete
Insert :- Used To Feed New Records Or Rows Into Table
Syntax:- Insert Into <Table_Name> <Column_List> Values <List_Of_Values>;
Ex1: Insert Into Student_Info (Empno, Ename,Sal,Deptno) Values(1,’Raja’,100,10); Create
Table Student_Info (Roll_No Number,Name Char(4));
Insert Into Student_Info Values (101,’Raja’);
Update:-Used To Change Or Modify The Existing Infromation In Tables Syntax:-Update
<Table_Name> Set Column1=Value, Column2= Value…….Where
<Condition>
Update Emp Set Sal=7000 Where Empno = 7369;
Update Emp Set Sal= 10000, Comm= 1000 Where Deptno=7369;
Delete :- Used To Remove The Rows From The Table
Syntax:-Delete From <Table_Name>; Or Delete From <Table_Name> Where
<Condition>
Ex1: Delete From Emp;
Ex2; Delete Emp Where Empno = 7369;
Ex3: Delete From Emp Where Empno =7369 And Deptno = 10;
Note : Oracle Is Not A Case Sensitive But Data Is Case Sensitive
Operators:-
Arithmetic Operators :- + , - , * , /
Relational Operators :- < , > , <= , >= , = , Between, Like, In , Is Null Relational
Negation :- != , <>, Not Between, Not In, Not Like, Is Not Null Logical Operators :-
And , Or, Not
Set Operators :- Union , Intersect, Minus, Union All
Auto Commit;
After Dml Commands If We Use Any Ddl Command Then Auto Commit;
6
Iq1) (For Ddl Commands Commit Is Not Require, But After Dml Command If You Use Any Ddl
Command Then Those Dml Statements Automatically Will Commit, That’s Why We Can Not
Use Ddl In Pl/Sql Block)
Tcl :Transaction Control Language:-
Transaction Control Statements Used To Manage The Changes Made By Dml Statements
Commit: - Save Work Done
Insert Into Emp (Empno, Ename,Deptno,Sal) Values (101,’A’,10,5000);
Update Emp Set Sal=8000 Where Empno = 7369;
Commit;
- -> (After Commit, Data Permanently Stored In The Database Until We Delete) Savepoint: -
Identify A Point In A Transaction To Which You Can Later Roll Back Ex:- Create Table
Temp_2(A Number, B Number);
Insert Into Temp_2 Values (100,100);
Commit;
Insert Into Temp_2 Values (1,10);
Insert Into Temp_2 Values (2,20);
Savepoint S1;
Update Temp_2 Set A= 999 Where B=100;
Savepoint S2;
Insert Into Temp_2 Values(3,30);
Savepoint S3;
Rollback To Savepoint S2;
Commit;
Select * From Temp_2;
Out Put Is
999 100
1 10
2 20
Note:- Commit Or Rollback Will Clear Savepoints.
Rollback :- Restore Database To Original Since The Last Commit Ex: Create
Table Temp_3 (A Number(3), B Number(3));
Insert Into Temp_3 Values(10,20);
Commit;
Insert Into Temp_3 Values (100,200);
Rollback;
Select * From Temp_3;
Out Put Is
10 20
7
Null :-
It Is An Undefined And Uncomperable Value
It Is Not Equal To Space Or Zero
It Will Not Ocupy Any Memory
Any Arthmetic Operation With Null Returns Null Only
It Is Represent With Null Keyword But Shown As Space On To Screen
Supports All Data Types
Ex:-
1) Select Sal * Null From Emp;
2) Update Emp E Set Comm = Comm * 10 Where Deptno = 10;
Dual Table:-
It Is A System Define Table
Supports To Retrive General Information From Select Statement
Dual Table Contain One Column-> Column Name Is-> Dummy
Data Type Is : Varchar2. Size Is : 1. Value Is : ` X`
Can’t Apply Any Dml And Ddl Operations On This Table Ex:-
1. Select ‘Employee Name Is Smith’ From Dual; 2.
Select 10000 – 3000 , 100/4 From Dual;
3. Select Sysdate From Dual;
Arthmetic Functions:-
1. Abs
2. Ceil
3. Floor
4. Mod
5. Sqrt
6. Power
7. Greatest
8. Least
9. Sign
9
10. Exp
11. Log
12. Cos
13. Round
14. Trunc
Abs (N):- This Function Is Used To Find Out The Absolute Value Of Given Number; Ex:-
Select Abs(-10), Abs(20) From Dual;
Result Is:- 10, 20
Ceil (N):- Ceil Returns Smallest Integer Greater Then Or Equal (>=) To ‘N’ Ex: Select
Ceil (15.77), Ceil (100.01), Ceil (1000.00) , Ceil (-100.2) From Dual;
Result Is :- 16 , 101, 1000 , 100
Floor (M) :- Floor Returns Largest Integer Less Then Or Equal (<=)
Ex:- Select Floor (15.77), Floor (100.01), Floor (1000.00) , Floor (-100.2) From Dual;
Result Is :- 15 , 100 , 1000 , -101
Mod(M, N) :- This Function Is Used To Findout The Remainder Of A Given Number. Ex:-
Select Mod(9,3), Mod(17,5), Mod(16,4), Mod(16,-4), Mod(9,-2) From Dual;
Sqrt (N):-This Function Is Used To Find Out The Square Root Of Given Number Ex:Select
Sqrt(25), Sqrt(625), Sqrt(900) From Dual
Power(M,N):-This Function Is Used To Find The Nth Power Of A Given Number Select
Power(5,2), Power(5,-2), Power(2,8) From Dual
Greatest (N1,N2,N3..Nn): Greatest(Date1, Date2….Daten):- Supports Number And Date
Data Types
This Functiong Returns The Largest Value From The Given List Of Numbers Or Dates
Ex:- Select Greates(-99,1,100,-99999), Greatest(Sysdate, Sysdate-2,Sysdate + 3) From Dual;
Least (N1,N2,N3,…Nn): Least(Date1, Date2,…Daten):- Supports Number And Date Data
Types
Ex:-Select Least(1,-12,-100,0,100), Least(Sysdate, Sysdate-100, Sysdate-10) From Dual;
Sign(M):-This Function Is Used To Find The Status Of A Given Number
Seelect Sign (-10), Sign(22) From Dual;
Exp(N) :-> Given E Power N Result (Natural Algorithm)
Round :- This Function Is Used To Round The Number To The Nearest Select
Round(123456.45678, -1 Or 1 ) From Dual
-2 Or 2
-3 Or 3
-4 Or 4
-5 Or 5
Trunc:-This Function Is Used To Truncate/Delete From Some Position. Select
Trunc(123456.45678, -1 Or 1 ) From Dual
-2 Or 2
-3 Or 3
-4 Or 4
10
-5 Or 5
Char Functions:-
Length(String):- Gives [Link] Characters In Given String Select
Length(‘Apple’) From Dual;
Select Length(Ename), Ename, Length(Empno), Empno, Length(Sal), Sal, From Emp; Select *
From Emp Where Length(Ename) > 5;
Reverse(String):-Gives The String In Reverse Pattern Select
Reverse(‘Apple’), Reverse(‘Madam’) From Dual;
Select ‘Yes Given String Is Palendrom’ From Where Reverse(‘Madam’)= Mdam
Ascii(Char):- Gives Ascii Value Of Given Character
Select Ascii(‘A’), Ascii(‘B’), Ascii(‘A’), Ascii(‘B’), Ascii(‘’’’), Ascii(‘ ‘) From Dual;
Chr(N):- Gives The Equalent Character Of Given Number
Select Chr(39), Chr(65), Chr(66), Chr(10) From Dual
Lpad(String,N,Char):-Left Padding
Left Side Files The String ‘String’ Upto N Space With ‘Char’ Chacter Select
Lpad(‘Raja’,10,’*’ ), Lpad(‘1234’, 8 , 0000) From Dual Rpad(String,N,Char):-
Right Padding
Right Side Files The String ‘String’ Upto N Space With ‘Char’ Chacter Select
Raja(‘Raja’,10,’*’ ), Raja(‘1234’, 8 , 0000) From Dual;
Concat(Str1, Str2) :->Used To Join Strings By Using Pipe Symbol ‘||’ Also We Can Do Same
Thing
‘||’ :-> Concationtion Operator
Select Concat (‘Raja’,’Sekhar’), Concat(‘Empnumber ‘, [Link]) From Emp E;
Select ‘Empno Is:- ’||[Link]||’, Ename Is: ’||[Link] From Emp Where Empno = 7369;
As Empno Is :- 7369 , Ename Is : Smith
Initcap :- It Returns Char, With The First Letter Of Each Word In A Uppercase All Other
Letters In Lowercase
Select Initcap(‘ Hi, Good Morning ’) , Initcap(Ename) From Emp; Lower:-
Lower Returns Char , With All Letters In Lowercase Select
Lower(Ename), Lower(‘Hi, Good Morning’) From Emp; Upper:-Upper
Returns Char , With All Letters In Uppercase Select Upper(Ename),
Upper(‘Hi, Good Morning’) From Emp;
Replacing (String, Str1, Str2):-This Function Is Used To Replace Str1 Completely With Str2
In The Given String
Select Replace(‘Ple’,’P’,’App’), Replace(‘Hi Good Morning’,’ ‘,’’) From Dual; Select
Ename([Link], ‘S’,’S’ ) From Dual
Translate (String, Str1,Str2):- This Fnction Is To Replace Each Character Of One Set With
The Corresponding Character Of Another Set In The Given String
Select Translate(‘Ple’,’P’,’App’), Translate(‘Aabccdefg’, ‘Abc’, ‘Xyz’) From Dual Iq1):-
Find The No Of ‘A’ S In A Given String?
As: Select Length(‘Animal’) - Length(Replace(‘Animal’, ’A’, ‘’) ) From Dual
11
Soundex:-
Select ‘Both Words Sounds Same’ From Dual Where Soundex(‘Srinu’)= Soundex(‘Sreenu’);
L
1. Select Ltrim(‘Sssram’,’S’) From Dual ; Ram
2. Select Rtim(‘ Ram ‘, ‘ ‘) From Dual : Ram
3. Select Trim(Rtrim(‘ Ramaraoaaa’, ‘A’,’’)) , Trim(‘Aaramaa’) From Dual
Substr(String, M , N): This Function Is To Select Some Portion Of The String From The
Specified Position Upto The Number Of Chars From The Given String Ex: Select
Substr(‘Oraclesql’,1,6), Substr(‘Oraclesql’,7), Substr(‘Oraclesql’,-3), Substr(‘Oraclesql’,-
1,3), Substr(‘Oracle’,-10),Substr(‘Oraclesql’,-9) From Dual Instr(String,Char,M,N):-This
Function Is Used To Find The Position Of Character(S) The Given String From The
Specified Position At The Nth Occurrence
Ex: Select Instr(‘Oracle, Java,.Net,Apps’, ‘.’,1,1) From Dual
Ex2:Select Instr(‘Oracle,Java,.Net,Apps’, ‘A’,1,2),
Instr(‘Oracle,Java,.Net,Apps’,’A’,2,1),
Instr(‘Oracle,Java,.Net,Apps’,’A’,1,1), Instr(‘Oracle,Java,.Net,Apps’,’A’,4,1)
/*Form 4th Character Onwards, Firrst ‘A’ Position */ From Dual;
Iq1)In Below String, Find The String Between 3rd And 4th Comma?, Find The String
Between 2nd And 3rd Comma?
Date Functions:-
To_Date :-It Converts String Into Date Value
Select To_Date(‘10122015’,’Ddmmrrrr’), To_Date(‘22/12/2015’,’Dd/Mm/Rrrr’) From Dual
Update Emp E Set [Link] = To_Date(‘05/10/2015’,’Dd/Mm/Rrr’) Where [Link]= 7369;
To_Char:- This Function Converts Any Date Value To A Char Value In The Specified Format As
To Convert Number Into Character
Select Round(Sysdate,’Mm’) /*Today Is: 16/Nov/2016 , As: 1/Dec/2016 */ From Dual Select
Round(Sysdate,’Yyyy’) /*Today Is :16/Nov/2016, As: 1/Jan/2017 */ From Dual Select
Round(To_Date(‘16/12/2015 17:30:30’, ‘Dd/Mm/Rrrr Hh24:Mi:Ss’), ‘Mm’) From Dual
As:- 1/1/2016 00:00:00
Select Round(To_Date(‘16/12/2015 17:30:30’, ‘Dd/Mm/Rrrr Hh24:Mi:Ss’), ‘Yyyy’) From Dual
As:- 1/1/2017
--Nearest Suday Day Date Will Display
Ex: Select Round(Sysdate, ‘Day’) From Dual Sysdate:-
Pscudo Column Gives Date From Server Alias
Names:-
Used To Specify Temporary Headingss For Columns Or Expressions Or Tables
Update Emp E Set [Link] =7000 Where [Link]= 7369;
Select [Link], [Link], [Link], [Link]* (10/100) Comm From Emp E;
Select [Link], [Link], [Link], [Link] From Emp E Where [Link] = 10; Select
Empno, Ename, (Select Dname From Dept D Where [Link] = [Link])
Deptname From Emp Where [Link] = 10;
Distinct Clause:- This Clause Is Used To Remove Duplicates From The Result Set, This Clause
Can Only Used With Select Stmt
Select Distinct Ename From Emp;
Select Distinct Deptno From Emp;
Select Clause:
Select <Columns List> From <Table_Name> [Where <Condition>
Group By <Columns> Having
<Condition> Order By
<Columns>]
16
Case Decode
2) Case We Can Use Inside The Select Inside The Select Statement Only We
Statement And Without Select Can Use Decode, Without Select
Statement Also We Can Use Statement We Can Not Use Decode
Ex:
1) Update Emp Set Deptno=Decode(Deptno, 10,20,20,30,30,40);
2) Select Empno, Ename, Sal, Decode(Deptno,10,(Sal*10)/100,20, (Sal*10)/100, 30, (Sal
*30)/100 ) Emp_Bonus From Emp
3) Select Stu_No, Stu_Name, Marks,Decode (Marks,500,’A’,400,’B’,300,’C’,’Fail’) From
Student_Info
4) Select Stu_No, Stu_Name, (Case When Marks > 500 Then ‘Grade A’ When Marks <
500 And Marks > 400 Then ‘Grade B’ Else ‘Grade C’ End) Grade From Student_Info
5) Update Emp Set Comm = (Case When Sal > 10000 Then 2000 When Sal > 7000 And
Sal < 10000 Then 1500 Else 1000 End)
6) Select Empno, Ename, Sal, Deptno,( Case When Deptno = 10 Then ‘Hr Department’
When Deptno = 20 Then ‘Manager Department’ Else ‘Admin Department’ End)
Dept_Name From Emp
Rownum:-
It Is A Numaric Value
Ex: Select Rownum, Empno, Ename, Sal From Emp Order By Sal Desc Select
Rownum,Empno,Ename,Sal From Emp Order By Sal Asc Select *
From Emp Where Rownum >=1
Rowid:-
It Is A Hexa Decimal Value (18 Digit Value)
It Is A Combination Of Objectid,File Number, Block Number, Row Number
(Object_Num -Of- Object, File_Num -In Tablespace, Block_Num - In File ,
Row_Num --In Block)
It Is A Static Value
When We Insrt New Row Into The Table, That Time Oracle Automatically
(Implicitly) Genarate One Hexadicmial Value That Is Rowid
Rowid Rownum
It Is A Static Value(Always Same Row It Is Not A Static Value (Based On The Out
Contain Same Rowid ) Put Of Select Statement Rownum Will
Change . Dynamically
Change)
It Is A Hexa Dicimal Number (18 Digit It Is A Numaric Value
Value)
It Is Combination Of Objectid,File It Is A Numaric Value
Number, Block Number, Row
Number
Oracle Automatically Provide Based On Select Statement Out Put
Rowid When We User Insert New Rownum Will Genarate
Row Into The Table
Rowid Will Be Stored In The It Won’t (Temporerly It Will
Database Genarate For Select Statement
Output)
Column Comments
1. Comment On Column [Link] Is ‘Employee Id Number’
2. Comment On Column [Link] Is ‘Mployee Salary Details’
Desc Emp;
Drop Comment:
1) Comment On Column [Link] Is ‘ ‘
Joins
Supports To Retrieve Data From More Than One Table
Nulls Will Never Join
We Can Join Any Number Of Tables, But If You Join ‘N’ Tables Then Atleast N- 1
Conditions Are Require.
5 Types Of Joins
1) Cartesion Join
2) Equi Join
3) Non-Equi Join
4) Self Join
5)Outer Joins (Full Outer, Left Outer , Right Outer)
Equi Join:-
Used To Retrieve Data From More Than One Table Based On Equality (‘=’)
Condition
If N Tables Are Joined Then Atleast N-1 Conditions Are Require
Mostly We Apply Equi Join On Parent Child Tables (Primary , Foreign Key Relation
Tables )
Student_Info
20
College_Info
Branch_I Branch_Locatio Branch_Address College_Na
D N Me
101 Guntur Near: Rtc Complex, Narayana_C
Plot-122 Ollege
102 Vishaka Opp:Railway Narayana_C
Station, Plot-402 Ollege
103 Hyderabad Gachi Bowli, Plot- Narayana_C
12 Ollege
Grade_Info
[Link] Min_Marks Max_Marks Grade
1 550 600 A
2 450 549 B
3 350 449 C
4 250 349 D
Retrive Student Details Along With College Details ?
Select Hallticket_No, Stu_Name, Stu_Marks, Branch_Name, Branch_Location From
Student_Info Si, College_Info Ci Where Si.Branch_Id = Ci.Branch_Id; Display Guntur
Naraya College Student Info?
Select Hallticket_No, Stu_Name, Stu_Marks, Branch_Name, Branch_Location From
Student_Info Si, College_Info Ci Where Si.Branch_Id= Ci.Branch_Id And
Ci.Branch_Location = ‘Guntur’;
Non Equi Join:
Used To Join The Tables On Non Eqi Condition
Tables Are Joined Without Using Equality Condition
We Can Use These Operators For Non Equi Join (<, > ,Between , Not
Between…Etc)
Display Student Info Along With Their Grade?
Select Si.Stu_Name, Si.Stu_Marks, [Link] From Student_Info Si, Grade_Info Gi
Where Si.Stu_Marks Between Gi.Min_Marks And Gi.Max_Marks;
Display Student Info Along With College Details And Their Grade?
21
Self Join:
Joining The Table To Itself
Worker_Tab
EMPNO ENAME manager
101 A NULL
102 B 101
22
103 C 102
104 D 101
105 E 102
Customer_Table
CUST_AC_NO CUST_NAME CUST_DOB CUST_BAL LOAN_TYPE
11111 A 01/DEC/1995 5000 1
22222 B 30/APR/1976 56000 2
33333 C 29/MAY/1981 650000 1
444444 D 31/DEC/1997 900
555555 E 27/FEB/2004 43000 3
Loan_Details_Table
Loan_Type Loan_Name
1 Car Loan
2 House Loan
3 Gold Loan
4 Personal Loan
Views
View Is A Stored Select Statement
It Will Not Hold The Data Physically On It
If You Apply Any Dml Operation On The View It Will Impact On Original Objects
(We Can Apply Dml Operations On The View But It Will Impact On The Table Data)
It Will Hide The Complecity Of The Query
Dml On View Are Reflected In Table And Vice Versa
It Supports To Share Selected Rows With Other Users While Sharing Provide
High Security
Suppose We Have 3 Tables , If I Want To Give Permission Of These 3 Tables To
Other User Then We Have To Give 3 Object Permissions , Instead Of That We Can
Create One View On These Objects And We Can Give Permission To That Object.
Suppose Frontend Resource (Java Resource) Using Same Query Multiple Times So
He Need’s Some Time To Exist That Sql Query In Frontend Code, So Instead Of That
We Will Create View On That Query Then Simple He Can Select * From
<View_Name>.
Drop View <View_Name>
Select * From User_Views;
Simple View:-- If You Create A View On Single Table , That Is Called As Simple View
Create View V1 As Select Empno, Ename, Sal From Emp ;
Create View V1 As Select Empno, Ename, Sal ,( Sal *10)/100 Bonus , ( Sal *
.25)/100 Fr OMNOTE:
EMP; WE CAN’T APPLY DML OPERATIONS ON ARTHMETIC VIEWS
Complex Views :- If You Create A View On More Then One Table That View Is Called
As A Complex View
25
Ex1):- Create View Vw_Emp _Dept As Select Empno, Ename , Sal, Dname, Location
From Emp E , Dept D Where [Link] = Deptno;
Ex 2): Create View Vw_Student_Info As Select Stu_Name, Stu_Class, Stu_Marks,
Branch_Location , Grade From Student_Info Si, College_Info Ci, Grade_Info Gi Where
Si.Branch_Id = Ci.Branch_Id And And Stu_Marks Between Gi.Min_Marks And
Gi.Max_Marks;
Ex3:- Soppose Two Users There U1 And U2.
User U1
Create View Vw_Emp_Dept As Select Empno,Ename,Sal,Dname,Location From Eme E,
Dept D Where [Link]=[Link];
Grant Select On Vw_Emp_Dept To User2;
User U2
Then U2 Can Select The Data From Vw_Emp_Dept Only, He Can’t Apply Dml On That.
If U2 Need All The Permissions On That View Then He Need’s All Permission U1:
Grant All On Vw_Emp_Dept To U2 (This Case User:U2 Can Do All Operations )
Forced View:- Without A Table We Can Create A View That Is Called As A Forced View,
But That View Is An Invalid Status. After Create The Table That View Will Be Valid.
Ex: Create View Vw_Audit_Emp As Select * From Audit_Emp;
(Note:- Audit_Emp View Is An Invlid Status Because Audit_Emp Table Is Not Exist)
Read Only Views:- Below Views Are Read Only Views , We Can’t Apply Dml
Operation On Views
View With Arthmetic Operations
View With Aggregate Functions
View With Readonly Option
If Key Preserved Table Join With A Non Key Preserved Table Then Also That
View Is Read Only View
Ex 1:- Create View Vw_Emp_Info As Select Empno, Ename, Sal, (Sal * 10/100)
Bonus, (Sal * 2) /100 Pf From Emp E Where [Link] = 10;
Ex 2:-Create View Vw_Emp_Maxsal As Select E.* From Emp E, (Select Max(Sal)
Max_Sal , Deptno From Emp Group By Deptno) D Where [Link]
= D.Max_Sal And [Link] = [Link]
Ex3:- Create View Vw_Aggregate As Select Sum(Sal), Deptno From Emp E Group
By Deptno.
Ex4:- Create View Vw_Readonly As Select Empno, Ename, Sal, Dname,
Location From Emp E, Dept D Where [Link] = [Link] With Read Only
Key Preserved Table Non Key Preserved Table:
Suppose We Are Joining Two Tables , If Both The Tables Don’t Have A
Primary Key Columns Then Both Tables Are Called As A
26
Case 1:-
Emp Table Dept Table
Empno—Primary Key Deptno—Not Having Primary Key
If You Create View On Both Tables, We Can’t Apply Dml On Emp But Can’t On Dept.
Case 2:-
Emp Table Dept Table
Empno—Primary Key Deptno—Primary Key
If You Create View On Both Tables, We Can Apply Dml On Emp Can’t On Dept.
(Because Dept Table Key Column Having Duplicate Values In A View Result). Case 3:-
Emp Table Dept Table
Empno—Not Have A Primary Key Deptno—Not Have A Primary Key
If You Create View On Both Tables, We Can’t Apply Dml On Both Table
Columns.
(Because Both Tables Are Non Key Preserved Tables). Case
4:-
Emp Table Dept Table
Empno—Primary Key Deptno -- Primary Key(It Is Fk In Emp Table And
Uk/Pk Also In Emp Table )
If You Create View On Both Tables, We Can Apply Dml On Both Table Columns
Synonym:
Mainly It Is Used To Hide The Original Name Of The Object
27
If You Want To Give Permission Of One User Object To Another User, We Can Use
Synonym (Note: Both Users Should Be On Same Database)
We Can Create Synonym On Tables, Views,Funtions, Procedures
One Synonym Is For One Object
It Will Not Hold The Data Physically On It
We Can Create Synonym On Another Synonym
It Is Giving High Secure While Sharing The Information To Other Users
Synonyms Are Two Types
1) Private Synonym 2)Public Synonym
Private Synonym:- Private Synonym Is Mainly Used To Hide The Original Name Of The Object.
Grant Permission:
Sys Schema Grant Create Synonym To <User> Or <Schema
User Create Synonym Syn_Emp For Emp; (Now User Can Do All The Operations On
Syn_Emp Instead Of Original Object Emp)
Ex1) Select * From Syn_Emp; Ex2) Delete From Syn_Emp; Ex3) Update Syn_Emp Sal= 2000;
User Create Synonym Syn_Emp_Dept For Vw_Emp_Dept; Drop
Synonym <Synonym_Name>
Select * From User_Synonyms.
Public Synonym:- If You Create The Public Synonym That Synonym Can Access Any User Int
That Database. (If We Want To Use Another User Object In Our Schema, We Have To Write
Schema_Name.Object Name, Instead Of That We Can Use Synonym)
User1 User2
Emp [Link]
If You Create The Public Synonym Then No Need To Give The <Schema_Name>.Object
Sys Schema
Grant Create Public Synonym To User1; User1
Ex1) Create Public Synonym Syn_Emp For Emp;
Grant All On Syn_Emp To User2;
Ex2) Create View Vw_Emp_Dept As Select Empno, Ename , Sal, Dname, Location From
Emp E, Dept D Where [Link] = [Link];
Create Public Synonym Syn_Emp_Dept For Vw_Emp_Dept;
Grant Select On Syn_Emp_Dept To User2;
User2
Insert Into Syn_Emp (Empno, Ename, Sal,Deptno) Values (101,’Raja’,500,30); Select
* From Syn_Emp;
Select * From Syn_Emp_Dept;
CREATE PUBLIC SYNONYM SYN_PROC1 FOR PROC1
Merge Statement:-
Use The Merge Statement To Select Rows From One Or More Tables (Or Views) For Insert Or
Update Or Delete Into Another Table Or View
Syntax: Merge Into <Target_Table> T
Using <Source_Table> S
On <Condition>
When Matched Then
(Update Set <T.Col1 = S.Col1, T.Col2 = S.Col2…>
And
Delete Where <T.Col1 = S.Col1 And T.Col2= T.Col2) When
Not Matched Then
Insert (T.Col1, T.Col2, T.Col3) Values (S.Col1, S.Col2,S.Col3); Ex:
Merge Into Audit_Emp T
Using Emp S On ([Link] = [Link])
When Matched Then
Update Set [Link]= [Link], [Link] = [Link]
Delete Where [Link] = 10
/* With Out Update Statement We Can Not Write Delete Statement
,Means :Destination/Target Table Are Not Deleted When They Are Not Updated By
The Merge First */
When Not Matched Then
Insert Values ([Link], [Link], [Link], [Link], [Link], [Link],
[Link], [Link]);
Note: (This We Will Discuss On Trigger Concept)
With Clause :- The With Query_Name Clause Assign A Name To A Subquery Block. You Can
Then Reference The Subquery Block Multiple Places In The Query By Specifying The Query
Name.
Syntax:
With <Alias Name> As (Subquery_Select_Statement>
Select <Column_List> From <Table_Name> T, <Alias_Name> A Where T.Col1= A.Col1
Ex 1) Display Department Wise Highest Salary Emp Details,?
With Sub_Q As
(Select Deptno, Max(Sal) Sal From Emp E Group By Deptno) Select
[Link], [Link], [Link], [Link]
From Emp Ee, Sub_Q Where [Link] = Sub_Q.Sal And [Link] = [Link];
Sequence
Mostly We Are Using Sequence To Genarate Unique And Order Wise Values (Ex:
Account_No, Emp_Id, Roll_No…For These Type Of Columns We Can Use Sequence)
SUPPOSE COMPANY HAVING SOME EMPLOYEES, NOW NEW EMPLOYEE JOINED IN THAT
COMPANY WHAT IS HIS EMPLOYEE NO, WE HAVE TO CHECK PREVIOUS EMPLOYEE NO AND
WE HAVE TO ADD ONE(+1) TO THAT EMPID, INSTEAD OF THAT WE CAN USE SEQUENCE IT
WILL AUTOMATICALLY GIVE NEXT VALUE
Constraints
Constraint Means Rule Or Ristriction (By Using Constraints Ristrict The Table Data)
Unique:-
After Create Unique Key Constraint Automatically Unique Index Will Be Create
Automatically Unique Key Index Will Be Automatically Unique Key Index Will Be
Create Create
It Will Allow Any [Link] Null Values It Won’t Allow Null Values
We Can Create Any [Link] Unique We Can Create Maximum 1 Primary Key
Constraints On A Table On A Table
Won’t Allow Duplicate Values Won’t Allow Duplicate Values
Check Constraint: Used To Specify Conditional Restrictions
Ex1:- Alter Table Emp Add Constraint Chk_Gender Check (Gender In (‘M’,’F’)); Ex2:-
Alter Table Emp Add Constraint Chk_Sal Check ( Sal > 5000);
Ex3:-Create Table Emp (Empno Number, Ename Varchar2(20), Sal Constraint Chk_Sal Check(Sal
> 5000));
Drop Constraint :- Alter Table Emp Drop Constraint Chk_Sal;
Foreign Key:-
Used To Specify Relations Between 2 Tables
A Foreign Key Column Should Be Refrence To Primary Key Or Unique Key Column
In The Same Table Or Another Table
Ex1:- Alter Table Emp Add Constraint Fk_Deptno Foregin Key (Deptno ) Refrences Emp
(Empno);
Ex2:-Create Table Dept (Deptno Number(8) Constraint Pk_Deptno Primary Key);
Create Table Emp (Empid Number(8), Ename Varchar2(30), Gender Char(1) Constraint
Chk_Gender Check (Gender In (‘M’, ‘F’)) , Deptno Number(8) Constraint Fk_Deptno
Refrences Dept(Deptno));
Primary Key Foreign Key
It Won’t Accept Duplicate Values And It Will Allow Duplicate Values And
Null Values Null Values
We Can Create Only One Primary Key We Can Create Any No Of Foreign Key
On The Table Columns On The Table
Index Automatically Create If Need, We Have To Create Index
We Can Create Primary Key On Any We Can Create Foreign Key Constraint On
Column Any Column But Refrence Column
Should Be Primary Or Unique Key
Column
On Delete Cascade Clause:- Automatically Removes Child Records When Ever Parent
Record Is Removed (We Can Give On Delete Cascade On Foreign Key Column Only)
Ex1:- Alter Table Emp Add Constraint Fk_Deptno Foreign Key (Deptno) Refrences
Dept(Deptno) On Delete Cascade
Ex2: (Table Level)
C-Check Constraint U-
Unique Constraint
R-Refrences (Foreign Key Constraint)
Disable Constraint
Alter Table <Table_Name> Disable Constraint <Constraint_Name> Alter Table
Emp Disable Constraint Pk_Deptno
Alter Table Emp Enable Constraint Pk_Deptno Sub
Query:-
Query With In A Query
First Inner Query Will Be Executed And Based On Output Of Inner Query Outer
Query Will Be Executed.
Subqueries Will Improve Performance While Retrieving Or Manupulating Data
List Of The Employees , Who’s Salary Is Like ‘Smith’ Salary?
Select * From Emp E Where [Link] = (Select Sal From Emp D Where [Link] =
‘Smith’);
Select * From Emp E Where [Link] In (Select Deptno From Emp D Where [Link]
=’Analyst’)
Update Emp E Set Comm = 500 Where Comm = (Select Min(Comm) From Emp D Where
[Link]= 20 And D. Sal =7000);
Correlated Subquery:-
In A Correlated Subquery First Outerquery Will Be Executed And Based On Output Of
Outer Query Inner Query Will Be Executed.
(Correlated Subquery Is A Sub_Query That Uses Values From The Outer Query In
This Case The Inner Query Has To Be Executed For Every Row Of Outer Query)
Ex:Selet Empno, Ename, (Select Dname From Dept D Where [Link] = [Link])
Dept_Name From Emp;
Inline View:
After From Clause Instead Of Table Name If You Use Query That Is Called A Inline View
Display Department Wise Max Salary Employees List?
Ex1: Select D.* From (Select Max(Sal) Salary, Deptno From Emp E Group Deptno) Tab ,
Emp D Where [Link] = [Link] And [Link] = [Link];
Ex2: Select * From (Select Max(Sal), Deptno From Emp Group By Deptno) T; Ex3:Select *
From (Select Empno, Ename, Sal, Dname,Loc From Emp E , Dept D Where [Link] =
[Link])
Index
Simple Index:-If You Create Index On Single Column That Is Called As A Simple Index
Syntax:- Create Index <Index_Name> On <Table_Name>(<Column Name>); Ex1:-
Create Index Idx_Empno On Emp(Empno);
Ex2:- Create Index Idx_Rollno On Student_Info (Rollno);
Complex Index:- If You Create Index On More Then One Column , That Is Called
As A Complex Index
Syntax:-Create Index <Index_Name> On <Table_Name>(<Col1>,<Col2>,…..);
Ex1:Create Index Idx_Rollno_ Name On Student_Info (Roll_No, Name); Ex2:Create
Index Idx_Empno_Status On Emp (Empno, Status);
Reverse Key Index:
Create Index Idx_Reverse_Empno On Emp(Empno) Reverse Create
Index Idx_Reverse_Deptno On Dept (Deptno)Reverse;
O Bitmap Index
Bitmap Indexes On Columns With Very Few Unique Values(Low Cardinality Data
Columns)
Bimap Indexes Are Widely Used In Data Warehousing Environments.
Designation
Software 0 0 0 0 1 0 1 0 0 0 1
Engineer
Project Leader 1 0 0 1 0 0 0 0 0 0 0
Project 0 0 0 0 0 1 0 1 0 0 0
Manager
Trainee 0 0 1 0 0 0 0 0 1 1 0
Group Head 0 1 0 0 0 0 0 0 0 0 0
Ex 1: Create Bitmap Index Indx_Designation On Emp(Designation); Ex 2:
Create Bitmap Index Indx_Deptno On Emp (Deptno);
When We Can Create Bitmap Index:
Ex:
Deptno : 10 20 30 40 50 Null
[Link] : 300 200 100 200 100 100
Total_No_Of_Distinct_Values :- 5
Total_No_Of_Records :- 1000
Selectivity = Total_No_Of_Distinct_Values 5
------------------------------------------------ = ------------- = 0.005
Total_No_Of_Records 1000
If Selectivity Is Approching To 1 It Is Good For Index, If It Is Approching To ‘0’ Then It Is
Bad For Index Creation.
How Oracle Takes Decision Whether To Use Index Or Not? Select *
From Emp Where Deptno = 20;
Expected Output (Cardinality) = Total No Of Recornds – Null Values
---------------------------------------------------------
Total Distinct Values
= 1000 - 100
---------------- = 180
5
180 Is Less Then 20% , Hence Index Will Be Used
Function Based Index:
Empno Ename Sal Comm Deptno
1 Smith 60000 8000 10
2 Cleark 34000 3000 10
3 Ward 45000 7000 20
4 Jones 70000 12000 30
If Bonus Is 10% Of Salary, Then How Many Employees Getting More Then 3000rs Bonus?
For This, We Will Write The Query Like Below. Select
* From Emp Where (Sal * 10 ) / 100 > 3000
In This Case What Will Happen, Each Time Sal Will Take From Emp Table And Multiple With
10 Then Devide By 100, Suppose If You Create Function Based Index On That Calculation, It
Will Be Stored Calculated Value In Index Blocks , Function Based Index Creation
Ex 1: Create Index Idx_Bonus On Emp ( (Sal + Comm)*10 / 100);
Composit Index:-
You Can Create An Index On Multiple Columns In A Table.
You Can Create Composite B-Tree Indexes As Well Bitmap Indexes Syntax:-
Create Index <Index_Name> On <Tab_Name> (<Col1,Col2..>) Create Index
Indx_Empno_Ename On Emp (Empno, Ename);
Create Index Indx_Account_Status On Account_Info(Account_No, Status); Rebuild
Index:-Re_Creating An Existing Index Offers Better Performance (Instead Of
Re_Creating An Existing Index Simple We Can Rebuild Index); Syntax:-Alter Index
<Index_Name> Rebuild;
Ex: Alter Index Indx_Empno Rebuild
Renaming An Index:- You Can Rename An Existing Index Syntax:Alter
Index Index_Name Rename To New_Index_Name Ex: Alter Index
Indx_Empno Rename To Idx_Empnumber Move An Index To A
Different Tablespace
Alter Index <Index_Name> Rebuild Tablespace <New_Tablespace> Select
* From User_Index;
Clusters
It Holds The Common Column Shared By Two Tables
It Will Improve Performance While Retieving Or Manipulating Data From Master-
Child Tables
It Has To Be Created Before Creating Tables.
Create Cluster C1(Deptno Number(5));
Create Table Dept (Deptno Number(5), Dname Varchar2(30), Loc
Varchar2(30)) Cluster C1(Deptno);
Create Table Emp (Empno Number, Ename Varchar2(30) , Deptno
Number(5)) Cluster C1(Deptno);
Create Index Idx_C1 On Cluster C1;
--Materialized View
We Can Apply Dml Operations On Materialized View
It` Will Store The Information Means Physically Occupy Space
We Can Create Index, Constraint On Materialized View
Analytic Functions
Select Empno, Deptno, Count(*) Over ( ) Cnt From
[Link]
Where Deptno In (10, 20);
The Order By Clause In The Over Function Is Different From The Order By Clause Of The
Main Query Which Comes After Where.
The General Syntax Of Specifying The Order By Clause In Analytic Function Is:
Order By <Sql_Expr> [Asc Or Desc] Nulls [First Or Last] Row_Number, Rank
And Dense_Rank:
All The Above Three Functions Assign Integer Values To The Rows Depending On Their Order.
Row_Number( ):
It Gives A Running Serial Number To A Partition Of Records. It Is Very Useful In Reporting,
Especially In Places Where Different Partitions Have Their Own Serial Numbers.
Row_Number() Over (Partition By Deptno Order By Hiredate Nulls Last) Srlno From
[Link]
Where Deptno In (10, 20)
Order By Deptno, Srlno;
Shown Below:
Lead (<Sql_Expr>, <Offset>, <Default>) Over (<Analytic_Clause>)
Lag: The Syntax Of Lag Is Similar Except That The Offset For Lag Goes Into The Previous Rows.
Select Ename, Hiredate,
Lag(Hiredate, 2) Over (Order By Hiredate) As Nexthired From
[Link] Where Deptno = 30;
Sql Queries
23. Display The Ename Of Employees Who Are Not Working As Salesman Or Clerk Or Analyst
24. Display All Rows From Emp Table .The System Should Wait After Every Screen Full Of Information.
25. Display The Total Number Of Employees Working In The Company.
26. Display The Total Salary Being Paid To All Employees.
27. Display The Maximum Salary From Emp Table.
28. Display The Minimum Salary From Emp Table.
29. Display The Maximum Salary Being Paid To Clerk.
30. Display The Maximum Salary Being Paid To Clerk.
31. Display The Maximum Salary Being Paid In Dept No 20.
32. Display The Min Sal Being Paid To Any Salesman.
33. Display The Average Salary Drawn By Managers
34. Display The Total Salary Drawn By Analyst Working In Deptno 40.
35. Display The Names Of Employees In Order Of Salary I.E. The Name Of The Employees
Earning Lowest Salar Should Appear First.
36. Display The Names Of Employees In Descending Order Of Salary.
37. Display The Details From Emp Table In Order Of Emp Name.
38. Display Empno,Ename,Deptno And [Link] The Output First Based On Name And Within
Name By Deptno And Within Deptno By Sal;
39. Display The Name Of The Employee Along With Their Annual Salary (Sal *12) .The
Name Of The Employee Earning Highest Annual Salary Should Appear First.
40. Display Name,Sal,Hra,Pf,Da,Total Sal For Each [Link] Output Should Be In The
Order O;F Total Sal,Hra15% Of Sal,Da 10% Of Sal, Pf 5% Of Sal Total Salary Will Be
(Sal*Hra*Da)-Pf.
41. Display Dept Numbers And Total Number Of Employees Within Each Group.
42. Display The Various Jobs And Total Number Of Employees With Each Job Group.
43. Display Department Numbers And Total Salary For Each Department.
44. Display Department Numbers And Maximum Salary For Each Department.
45. Display The Various Jobs And Total Salary For Each Job.
46. Display Each Job Along With Minimum Sal Being Paid In Each Job Group.
47. Display The Department Numbers With More Than Three Employee In Each Dept.
48. Display The Various Jobs Along With Total Sal For Each Of The Jobs Where Total Sal Is
Greater Then 4000
49. Display The Various Jobs Along With Total Number Of Employees In Each [Link]
Output Should Contain Only Those Jobs With More Than Three Employees.
50. Display The Name Of Emp Who Earns Highest Sal.
51. Display The Employee Number And Name Of Employee Working As Clerk Amd Earning
Highest Salary Among Clerks.
52. Display The Names Of The Salesman Who Earns A Salary More Than The Highest Salary Of Any Clerk.
53. Display The Names Of Clerks Who Earn Salary More Than That Of James Of That Of Sal
Lesser Than That Of Scott.
54. Display The Names Of Employees Who Earn A Sal More Than That Of James Or That Of Salary
Lesser Than That Of Scott.
55. Display The Names Of The Emploees Who Earn Highest Salary In Their Respective Departments.
56. Display The Names Of Employees Who Earn Highest Salaries In Thir Respective Job Groups.
57. Display The Employee Names Who Are Working In Accountging Dept.
58. Display The Employee Names Who Are Working In Chicago.
59. Display The Job Groups Having Total Salary Greater Then The Maximum Salary For Managers.
GNANA IT SOLUTIONS, SQL MATERIAL
48
60. Display The Names Of Employees From Department Number 10 With Salary Greater Than
That Of Any Employee Working In Other Departments.
61. Display The Names Of Employees From Department Number 10 With Salaty Greater Then
That Of All Employees Working In Other Departments.
62. Display The Names Of Employees In Upper Case.
63. Display The Names Of Employees In Lower Case.
64. Display The Names Of Employees In Proper Case.
65. Find Out The Length Of Your Name Using Appropriate Function.
66. Display The Length Of All Employees Names.
67. Display The Name Of The Employee Concatenate With Empno.
68. Use Appropriate Function And Extract 3 Characters Starting From 2 Characters From The
Following String ‘Oracle’ I.E. The Output Should Be ‘Rac’.
69. Find The First Occurrence Of Character ‘A’ From The Following String ‘Computer
Maintenance Corporation’.
70. Replace Every Occurrence Of Alphabet Awith B In The String Allen’s (User Translate Function).
71. Display The Information From Emp Table Wherever Job ‘Manager’ Is Found It Should Be
Displayed As Boss(Replace Function).
72. Display Empno,Ename,Deptno From Emp Table Instead Of Display Department Numbers
Display The Related Department Name (Use Decode Function).
73. Display Your Age In Days.
74. Display Your Age In Months.
75. Display Current Date As 15th August Friday Nineteen Forty Seven.
76. Display The Following Output For Each Row From Emp Table As ‘Scott Has Joined The
Company On Wednesday 13th August Nineteen Ninety’.
77. Find The Date Of Nearest Saturday After Current Day.
78. Display Current Time.
79. Display The Date Three Months Before The Current Date.
80. Display The Common Jobs From Department Number 10 And 20 .
81. Display The Jobs Found In Department Numer 10 And 20 Eliminate Duplicate Jobs.
82. Display The Jobs Which Are Unique To Deptno 10.
83. Display The Details Of Those Who Do Not Have Any Person Working Under Them.
84. Display The Details Of Employees Who Are In Dept And Grade Is 3.
85. Display Those Who Are Not Managers And Who Are Manager Any One.
86. Display Those Employees Whose Name Contains Not Less Than 4 Chars.
87. Display Those Departments Whose Name Start With ‘S’ While Location Name End With ‘0’.
88. Display Those Emplouees Whose Manager Name Is Jones.
89. Display Those Employees Whode Salary Is More Than 3000 After Giving 20% Increment .
90. Display All Employees With Thee Dept Name.
91. Display Ename Who Are Working In Sales Dept.
92. Display Employee Name,Deptname,Salary And Comm. For Those Sal In Between 2000 And 5000
While Location Is Chicago.
93. Display Those Employees Whose Salary Greater Than His Manager Salary.
94. Display Those Employees Who Are Working In The Same Dept Where His Manager Is Working .
95. Display Those Emplouees Who Are Not Working Under Any Manager.
96. Display Grade And Employees Name For The Dept No 10 Or 30 But Grade Is Not 4,While
Joined The Company Before 31-Dec-82.
97. Update The Salary Of Each Employee By 10% Increments That Are Not Eligible For Commission.
98. Delete Those Employees Who Joined The Company Before 31-Dec-82 While There Dept
Location Is ‘New York’ Or ‘Chicago’.
99. Display Employee Name,Job,Deptname,Location For All Who Are Working As Managers.
100. Display Those Employees Whose Manager Names Is Jones And Also Display There
Manager Name.
101. Display Name And Salary Of Ford If His Sal Is Equal To High Sal Of His Grade.
102. Display Employee Name,His Job,His Dept Name,His Manager Name,His Grade And
Make Out Of An Under Department Wise Break [Link];
103. List Out All The Employees Name ,Job,And Salar Grade And Department Name For
Every One In The Company Except’clerk’ Sort On Salary Display The Highest Salary.
104. Display Employee Name ,His Job And His Manager .Display Also Emplyoees Who Are
Without Manager.
105. Display The Name Of Those Employees Who Are Getting Highest Salary.
106. Display Those Employees Whose Salary Id Equal To Average Of Maximum And Minimum.
107. Display Count Of Employees In Each Department Where Count Greater Than 3.
108. Display Dname Where At Least 3 Are Working And Display Only Dname.
109. Display Name Of Those Manager Name Whose Salary Is More Than Average
Ssalary Of Company.
110. Display Those Managers Name Whose Salary Is More Than An Average Salary Of His Employees.
111. Display Wmployee Name,Sal,Comm. And Net Pay For Those Employees Whose Net
Pay Are Greater Than Or Equal To Any Other Employee Salary Of The Company.
112. Display Those Emploiyees Whose Salary Is Less Than His Manager But More Than Salary
Of Any Other Managers.
113. Find Out The Last 5(Least) Earner Of The Company.
114. Find Out The Number Of Employees Whose Salary Is Greater Than There Manager Salary
115. Display Those Manager Who Are Not Working Under President But They Are Working
Under Any Other Manager.
116. Delete Those Department Where No Employees Working.
117. Delete Those Records Frtom Emp Table Whose Deptno Not Available In Dept Table.
118. Display Those Earners Whose Salary Is Out Of The Grade Available In Sal Grade Table.
119. Display Employee Name,Sal ,Comm. And Whode Net Pay Is Greater Than Any
Other In The Company.
120. Display Name Of Those Employees Who Are Going To Retire 31-Dec-99. If The
Maximum Job Is Period Is 18 Years.
121. Display Those Employees Whose Salary Is Odd Value.
122. Display Those Emplouees Whose Salary Contains At Least 4 Digits.
123. Display Those Employees Who Joined In The Company In The Companu In The Months Of Dec.
124. Display Those Employees Whose Name Contains “A”.
125. Display Those Employees Whose Deptno Is Available In Salary.
126. Display Those Employees Whose First 2 Characters From Hiredare-Last 2 Characters Of Salary.
127. Display Those Employee Whose 10% Of Salary Is Equal To The Year Of Joining.
128. Display Those Employees Who Are Working In Sales Or Research.
129. Display The Grade Of Jones.
130. Display Those Employees Who Joined The Company Before 15th Of The Month.
131. Delete Those Employees Who Joined The Company 21 Years Back From Today.
165. Find Out All Dept Which Have More Than 3 Empouees
166. Display The Half Of The Enames In Upper Cade And Remaining Lower Cade .
167. Create Copy Of Emp Table.
168. Select Ename If Ename Exists More Than Once
169. Display All Enames In Reverse Order
170. Display Rthose Employee Whose Joining Of Month And Grade Is Equal.
171. Display Those Employee Whose Joining Date Is Available In Deptno .
172. Display Those Employees Name As Follows A Allen,B Blake.
173. List Out The Employees Ename ,Sal,Pf From Emp.
174. Create Table Emp With Only One Column Empno
175. Add This Column To Emp Table Ename Varchar2(20)
176. Oops ! I Forgot To Give The Primary Key Constraint. Add It Now
177. Now Increase The Length Of Ename Column To 30 Characters
178. Add Salary Column To Emp Table
179. I Want To Give A Validation Saying That Sal Cannot Be Greater 10,000(Note Give A
Name To This Column)
180. For The Time Being I Have Decided That I Will Not Impose This Validation. My Boss Has
Agreed To Pay More Than 10,000
181. My Boss Has Changed His Mind. Now He Doesn’t Want To Pay More Than 10,000. So
Revoke That Salary Constraint
182. Add Column Called As Mgr To Your Emp Table
183. Oh! This Column Should Be Related To Empno. Give A Command To Add This
Constraint Add Deptno Column To Emp Table
184. This Dept No Column Should Be Related To Deptno Column Of Dept Table
185. Create Table Called As New Emp, Using Single Command Create This Table As Well As To
Get Data Into This Table (Use Create Table As)
186. Create Table Called As New Emp. This Table Should Contain Only Empno,Ename,Dname.
187. Delete The Rows Of Employees Who Are Working In The Company For More Than Two Years.
188. Provide A Commission To Employees Who Are Not Earning Any Commission.
189. If Any Employee Has Commission, His Commission Should Be Incremented By 10%
Of His Salary.
190. Display Employee Name And Department Name For Each Employee.
191. Display Employee Number,Name And Location Of The Department In Which He Is Working.
192. Display Ename,Dname Even If There No Employees Working In A Particular
Department(Use Outer Join).
193. Display Employee Name And His Manager Name.
194. Display The Department Number Along With Total Salary In Each Department.
195. Display The Department Number And Total Number Of Employees In Each Department.
196. Display The Current Date And Time.