Professional Documents
Culture Documents
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
1.Database Concepts
Objective
Introduction
Database Management System
Traditional Data Processing System
Need of a Database Management System
Types of DBMS
Relational Database Management System Terminology
Keys
1.1
Introduction
1.2
Types of DBMS
1.3
RDBMS terms
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/database-concepts-0
1 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
1.1. Introduction
What is a data
Any factual information in raw and disorganized form is called data.
What is a database
A database is a collection of related data organized in a way that data can be easily accessed ,managed and updated.
Database Management System
A general-purpose Database Management System(DBMS) is a software system designed to allow the definition, creation, querying, updating
and administration of databases.
Well-known DBMS's include MySql,Oracle,Microsoft SQL server,Foxpro,SQLite, FileMaker Pro.
The primary goal of a Database Management System(DBMS) is to provide a way to store and retrieve database information that is both
convenient and efficient.
Traditional File Processing System
A file system is a method of storing and organizing computer files and the data they contain and to make it easy to find and access them.
Limitations of File processing System:
1. Separated and Isolated Data
2. Data Redundancy
3. Data Dependence
4. Difficulty in representing data from the user's view
5. Inflexibility in retrieving the Data
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/introduction-20
2 / 56
Campus Commune
8/19/2014
6. Data Security
7. Transactional Problems
8. Concurrency problems
Need of a Database Management System
To overcome the limitations of the traditional file processing system , the modern DBMS was created.
Functions of DBMS :
1. Minimal Data Redundancy
2. Data Consistency
3. Data Integration
4. Data Sharing
5. Application Development Ease
6. Better Controls
7. Data Independence
8. Reduced Maintenance
Ask a doubt
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/introduction-20
3 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/types-of-dbms-0
4 / 56
Campus Commune
8/19/2014
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/types-of-dbms-0
5 / 56
Campus Commune
Ask a doubt
8/19/2014
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/types-of-dbms-0
6 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
Keys in DBMS
Keys are used to establish and identify relation between tables
Super Key:
A Super key is any combination of fields within a table that uniquely identifies each record within that table.
Candidate Key:
1. A candidate is a subset of a super key.
2. A candidate key is a single field or the least combination of fields that uniquely identifies each record in the table.
3. The least combination of fields distinguishes a candidate key from a super key.
Primary key:
1. A primary key is a candidate key that is most appropriate to be the main reference key for the table.
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/rdbms-terms-0
7 / 56
Campus Commune
8/19/2014
Related Videos
Ask a doubt
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
Open Doubts
Closed Doubts
BHARATHWAJ SUNDARESAN
The above material is totally not related to the questions on the quiz. and there are a lot of bugs. kindly do the needful.
about 1 month ago
SANTHOSH DEVUNURI
Hi
It would be great, if you can provide the details of the bugs which you found.
Thanks
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/rdbms-terms-0
8 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
Introduction to SQL
2.2
2.3
2.4
2.5
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/data-query-language-0
9 / 56
Campus Commune
2.6
8/19/2014
Practice problems
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/data-query-language-0
10 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/introduction-to-sql-0
11 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
Selection means selecting set of rows from a table. In the below table, 3 rows marked with yellow colour suggesting that those rows are selected.
12 / 56
Campus Commune
8/19/2014
[WHERE search_condition]
[GROUP BY grouping_column_name]
[HAVING aggregated_search_condition]
[ORDER BY sorting_column]
1. The SELECT and FROM clauses of the statement are mandatory. The remaining four clauses are optional.
Consider the following table
Ask a doubt
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/data-query-language-select-0
13 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/select-statement-projection-and-selection
14 / 56
Campus Commune
8/19/2014
The above query displays only id, name and salary columns from customer_details
Related Videos
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/select-statement-projection-and-selection
15 / 56
Campus Commune
Ask a doubt
8/19/2014
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/select-statement-projection-and-selection
16 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
1. Name, age and salary of the customers displayed as per the ascending order of their salary.
2. DESC keyword can be used to display the list in descending order
GROUP BY Clause
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/distinct-keyword-and-order-by-clause
17 / 56
Campus Commune
8/19/2014
The GROUP BY statement is used to group the result-set by one or more columns.
The above query displays number of customers present in particular age group.
Note: Group By Statements will be discussed in detail later
Ask a doubt
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/distinct-keyword-and-order-by-clause
18 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
The Name, age and the strings are displayed as single output columns
Column Alias
Column heading in the result set can be changed with Column aliases using the keyword AS.
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/concatenation-operator-and-column-alias
19 / 56
Campus Commune
8/19/2014
1. The columns name and id are displayed as customer_name and customer_id in the result set.
2. Column headings in the table is unchanged.
Related Videos
Ask a doubt
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/concatenation-operator-and-column-alias
20 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
1. Write a statement to select all the products with a price between $60 and $120.
2. Write a statement to select the name price in dollor and price
in cents(use alias)(1$=100 cents)
3. Write a statement to get different contents in boxes
4. Write a statement to get the full name of employee by combining firstname and lastname
5. Write a query to get the employees who are not assigned to any department?
6. Write a query to get employees salary is less than 7000 and belongs to department 20 or 40
7. Write a query to get the employes who are having managers.
8. Write a query to display the details of all employees whose last name is not available.
9. Write a query to display the details of all the female employees who is earning more than 12000 an belongs to the designation 'A'.
10. Write a query to display the various shift codes available in the SWIPES table.
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/practice-problems-9
21 / 56
Campus Commune
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/practice-problems-9
8/19/2014
22 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
3.2
Practice problems
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/data-definition-language-1
23 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
Data Types
A data type identifies or classifies a particular type of information or data.
Some commonly used data types are:
CHAR (size) - Used to store character strings values of fixed length.
VARCHAR2 (size) Used to store variable length string data.
NUMBER (size, precision) Used to store numbers(fixed or floating point)
DATE Used to represent date and time.
LONG Used to store large variable length strings(upto 2GB).
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/data-definition-language-ddl-0
24 / 56
Campus Commune
8/19/2014
(
column_name1 DATATYPE(Size) ,
column_name2 DATATYPE(Size),
column_name3 DATATYPE(Size)
);
Ex: Create Table Employee
(
Emp_id number(4) NOT NULL,
Name varchar2(20) NOT NULL,
Salary number(8),
E_Mail varchar2(30),
Country varchar2(20),
);
Table created.
The above statement creates a table named Employee with columns Emp_id, Name,Salary,E_Mail and Country.
The above statement adds a new column 'age' of number data type with constraint not null.
Modifying the column:
Ex: ALTER TABLE Employee MODIFY salary number(10,2);
Table Altered.
Rename and Drop a Column:
Using the alter statement we can rename a column and also the drop any column.
The above statements renames the column name salary to em_sal and drops column age.
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/data-definition-language-ddl-0
25 / 56
Campus Commune
8/19/2014
Related Videos
Ask a doubt
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/data-definition-language-ddl-0
26 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
3. Write a query to alter the name column in products table to varchar2(35) to varchar2(80)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/practice-problems-10
27 / 56
Campus Commune
8/19/2014
6. Write a query to prepare a table EMPLOYEE with the following fields - eno , first name , last name , dob , doj , dor , designation.
7. Write a statement to add a column manager to employess table with datatype as number
8. Write a query to prepare a table SHIFT with the following fields - shift code , shift start time , shift end time.
9. Write a query to prepare a table SWIPES with the following fields - eno , shiftcode , swipedate , swipe in time , swipe out time.
10. Write a query to add new fields Basic & Gender to the EMPLOYEE table.
12. Write a query to remove a DOR column from the table EMPLOYEE.
13. Write a query to create a back up table SWIPES in order to store only the the records of the year 2013.
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/practice-problems-10
28 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
4.2
Practice problems
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/data-manipulation-languagedml-0
29 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
INSERT statement
Insert statement is used for inserting data into table.
Insertion of data can be done in multiple ways.
Syntax:
INSERT INTO table_name[(column1, column2,...)]
VALUES(value1, value2,....);
Ex:
If values in all the columns inserted in proper order, column names are not mandatory.
Syntax-:INSERT INTO table_name VALUES(value1, value2,....);
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/data-manipulation-languagedml-1
30 / 56
Campus Commune
8/19/2014
Ex:
UPDATE statement
Update command is used to change or modify data of one or more records in a table.
Syntax:
UPDATE Table_name SET Column_name1=value1 [,Column_name2=value2,...]
[WHERE Condition];
Ex.
DELETE statement
1. Delete statement is used to remove one or more records from a table.
2. A subset may be defined for deletion using a condition, otherwise all records are removed.
Syntax:
DELETE FROM Table_Name
[WHERE Condition];
Delete statement using WHERE condition.
Ex:
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/data-manipulation-languagedml-1
31 / 56
Campus Commune
8/19/2014
Note: Delete statement without where condition deletes all the rows from table.
Example-
Related Videos
Ask a doubt
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/data-manipulation-languagedml-1
32 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
2. Write a query to take the values at run time and insert into products table.
3. Write statement to delete the price from products table for the code 6 and 7.
5. Write a query to input the below information into the employee table.
Eno
First name
Last name
DOB
DOJ
DOR
NONE
10/06/83
10/06/03
NTWO
10/02/84
10/02/04
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/practice-problems-11
Designation
33 / 56
Campus Commune
8/19/2014
NTHREE
10/07/83
10/07/03
6. Write a query to input the below information into the BASIC field & GENDER field of the EMPLOYEE table.
Eno
Basic
Gender
10000
Male
15000
Female
10000
Female
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/practice-problems-11
34 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/transaction-control-language
35 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
36 / 56
Campus Commune
8/19/2014
Related Videos
Ask a doubt
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/transaction-control-language-tcl-1
37 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
6.1
6.2
6.3
Conversion Functions
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/single-row-aggregate-group-functions-in-sql-0
38 / 56
Campus Commune
8/19/2014
6.4
Character Functions
6.5
6.6
Aggregate/Group functions
6.7
Practice problems
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/single-row-aggregate-group-functions-in-sql-0
39 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/introduction-to-oracle-built-in-functions-1
40 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
Related Videos
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/single-row-functions-1
41 / 56
Campus Commune
Ask a doubt
8/19/2014
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/single-row-functions-1
42 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/conversion-functions-0
43 / 56
Campus Commune
8/19/2014
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/conversion-functions-0
44 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/character-functions-0
45 / 56
Campus Commune
8/19/2014
The above query returns all the employee names with the first letter in upper case and rest other characters in lower case.
LOWER: This function converts all letters in the specified string to lower case. If there are characters in the string that are not letters, they are
unaffected by this function.
Syntax : LOWER(expr1)
Ex: SELECT LOWER (emp_name) FROM employee:
amit
ajay
sima
dipa
anuj
The above query returns all the characters of the employee name in lower case.
UPPER:This function converts all letters in the specified string to uppercase. If there are characters in the string that are not letters, they are
unaffected by this function.
Syntax : UPPER(expr1)
Ex: SELECT UPPER (emp_name) FROM Employee:
AMIT
AJAY
SIMA
DIPA
ANUJ
The above query returns all the characters of the employee name in upper case.
CONCAT: This function allows you to concatenate two strings together.
Syntax : CONCAT(expr1,expr2)
Ex: SELECT CONCAT(emp_name,dep_name) full_name FROM Employee;
The above query returns the emp_name & dep_name concatenated into a single string.
SUBSTR: Returns specified characters from a string, starting from specific position to required characters length.
Syntax : SUBSTR(col/expr,m,n)
If 'm' is positive,oracle counts from beginning of string, If it is negative Oracle counts from the end of string.
If 'n' is omitted, Oracle returns all characters to end of the string starting from m.
Ex: SELECT SUBSTR(emp_name,3,2) FROM Employee.
The above query starts searching from the third position of the employee name from the starting of the string and displays two characters from
there.
Ex: SELECT SUBSTR('abcdefg'-4,2) FROM dual;
dc
The above query starts searching from the fourth position of the given string from the end of the string and display two characters from there.
REPLACE: It returns the every occurrence of search_string replaced by the replacement_string.
If the replacement string is omitted or null all occurrences of search string will be removed.
Syntax : REPLACE(string,search_string,replace_string)
Ex: SELECT REPLACE(branch_name,'Mumbai','Kolkata') FROM Employee WHERE dep_name = 'HR';
The above query replaces branch name to 'Kolkata' wherever 'Mumbai' is available for the HR department .
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/character-functions-0
46 / 56
Campus Commune
8/19/2014
LPAD,RPAD:
LPAD pads the character value right justified to a total width of n character positions.
Syntax : LPAD(expr1,padded_length,padded_string)
RPAD pads the character value left justified to a total width of n character positions.
Syntax : RPAD(expr1,padded_length,padded_string)
The default padding character is space.
Ex: SELECT LPAD('jhon',8) FROM dual;
jhon
Since the third parameter is not specified in the result of the above query will be by default space padded for the previous four positions.
Ex2: SELECT LPAD('jhon',8 ,'x') FROM dual;
xxxxjhon
The above query fills the four blank spaces with 'x' left of the given string.
Ex3: SELECT RPAD('jhon',8 ,'x') FROM dual;
jhonxxxx
The above query fills the four blank spaces with 'x' right of the given string.
TRIM: It enables to trim leading or trailing characters or both from a string.
If we dont specify anything, it will trim spaces.
Syntax : TRIM( [LEADING | TRAILING | BOTH] character FROM string)
LTRIM : Removes the leading characters
RTRIM : Removes the trailing characters
TRIM : Removes both
Ex: SELECT RTRIM('s' from 'ssmithss') FROM dual;
ssmith
The above query removes 'trailing' 's' from the given string.
Ex: SELECT LTRIM('s' from 'ssmithss') FROM dual;
mithss
The above query removes 'leading' 's' from the given string.
Ex: SELECT TRIM('s' from 'ssmiths') FROM dual;
mith
The above query removes 'trailing' & 'leading' 's' from the given string.
Ex: SELECT TRIM(' smith ') FROM dual;
Smith
The above query removes 'trailing' & 'leading' spaces from the given string.
INSTR: This function returns the location of a sub string in a given string.
Syntax : INSTR( string, sub_string [, start_position [, nth_appearance ] ] ).
start_position and nth_appearance are optional. If not specified, always INSTR starts with first position and will give first appearance.
Ex: SELECT INSTR('internet','e') FROM dual;
4
The above query returns the first position of 'e' searched from the start of the given string.
Ex: SELECT INSTR('internet','e',1,2) FROM dual;
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/character-functions-0
47 / 56
Campus Commune
8/19/2014
7
The above query returns the second position of 'e' searched from the start of the given string.
Ex: SELECT INSTR('internet','e',5,1) FROM dual;
3
The above query returns the first position of 'e' searched from the fifth position of the given string.
LENGTH: Returns number of characters in a value.
Syntax : LENGTH(column)
Ex: SELECT LENGTH(branch_name) FROM Employee;
The above query returns number characters in the branch_name field for each and every record.
Ex: SELECT LENGTH('jhon') FROM dual;
4
The above query returns the number of characters from the given string.
Ask a doubt
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/character-functions-0
48 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
Dual table
1. This is a single row and single column dummy table provided by oracle. This is used to perform mathematical calculations without using a
table.
2. Oracle presents the output of every operations in a tabular format so that it seems to the user that the output comes from a table
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/numeric-functions-1
49 / 56
Campus Commune
8/19/2014
The above query returns the absolute value of the given 'number'.
The MOD function returns the remainder value of the parameter passed.
Syntax : MOD(number1,number2)
Ex: SELECT MOD(10,4) FROM dual;
2
The above query returns the remainder when 10 is divided by 4.
The above query returns the largest integer nearest to 7.14 & 7.84.
Ex: SELECT FLOOR(-7.14) FROM dual;
-8
The above query returns the largest integer nearest to -7.14.
The CEIL function returns the smallest integer greater than or equal to the value
mentioned in parameter.
Syntax: CEIL(decimal number)
Ex: SELECT CEIL(7.14), CEIL(7.84) FROM dual;
8
The above query returns the smallest integer nearest to 7.14 & 7.84.
Ex: SELECT CEIL(-7.14) FROM dual;
-7
The above query returns the smallest integer nearest to -7.14.
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/numeric-functions-1
50 / 56
Campus Commune
8/19/2014
1) The TRUNC function truncates the value present in the column, expression up to decimal places mentioned in first parameter.
2) If the second argument is 0 or is missing, the value is truncated to zero decimal places.
Syntax: TRUNC(decimal number,number of places)
Ex: SELECT TRUNC(137.5738,3) As Rounded FROM dual;
137.573
The above query returns the decimal number with three digits after the decimal point.
Ex: SELECT TRUNC(137.5738,0) As Rounded FROM dual;
137
The above query returns the integer value.
The ROUND function round off the value present in the column, expression up to decimal places mentioned in first parameter.
If the second argument is 0 or is missing, the value is rounded to zero
decimal places.
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/numeric-functions-1
51 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/this-is-a-single-row-and-single-column-dummy-table
52 / 56
Campus Commune
8/19/2014
The above query displays the average salary of all the employees in the table Employee
MAX: Returns the maximum value, ignoring null values.
Syntax: MAX([DISTINCT] column_name)
Ex: SELECT MAX(salary) as Maximum Salary FROM Employee where Dep_Name='HR';
16000
The above query displays the maximum salary of all the employees in HR Department in the table Employee.
MIN: Returns the minimum value, ignoring null values.
Syntax: MIN([DISTINCT] column_name)
Ex: SELECT MIN(salary) as Minimum Salary FROM Employee where Dep_Name='HR';
10000
The above query displays the minimum salary of all the employees in HR Department in the table Employee.
COUNT: Returns the count of not null values ignoring null values.
Syntax: COUNT([DISTINCT] column_name)
Ex: SELECT COUNT(DISTINCT Dep_name) Departments FROM Employee;
3
The above query displays the count of different departments in the table Employee.
COUNT:(*) Count function with asterisk returns the count of total number of rows including null values
Syntax: COUNT(*)
Ex: SELECT COUNT(*) FROM Employee;
5
The above query displays the total number of rows in table Employee.
GROUP BY clause
Creates a data set, containing several sets of records grouped together based on a condition.
Syntax: SELECT <columnName1>[,<columnName2>], AGGREGATE FUNCTION(<expression>) FROM Table_Name GROUP BY
<columnName1>[,<columName2>] ;
Ex: SELECT dep_name,COUNT(emp_id) "No of Employee" FROM Employee GROUP BY dep_name;
HR
Marketing
Admin
WHERE clause
Used to apply a filter condition before the Grouping the rows.
Syntax: SELECT <columnName1>[,<columnName2>], AGGREGATE FUNCTION(<expression>) FROM Table_Name WHERE
<condition_before_grouping_rows> GROUP BY <columnName1>[,<columName2>] ;
Ex: SELECT Dep_Name,COUNT(Salary) FROM Employee WHERE Salary>15000 GROUP BY Dep_Name;
HR
Marketing
Admin
The above query displays department wise count of salary more than 15000.
HAVING clause
Used to apply a filter condition on Aggregate values.
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/this-is-a-single-row-and-single-column-dummy-table
53 / 56
Campus Commune
8/19/2014
16000
Marketing
20000
The above query displays the departments for which total salary is less 30000 excluding the Admin department, total salary for which is 40000.
Related Videos
Ask a doubt
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/this-is-a-single-row-and-single-column-dummy-table
54 / 56
Campus Commune
8/19/2014
Pre-ILP Home
Unix/C++/Oracle Lounge
Logout
Oracle
Q
1.Database Concepts
Q
2.Data Query Language
Q
3.Data Definition Language
Q
4.Data Manipulation Language
Q
5.Transaction Control Language
Q
6.Single Row, Aggregate / Group functions in SQL
55 / 56
Campus Commune
8/19/2014
(Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune)
Open Doubts
Closed Doubts
PADMINI T
Is there any option to reset tech lounge quizzes?
about 2 months ago
APURVA MISHRA
no
https://campuscommune.tcs.com/communities/unix-c-oracle-lounge/content/practice-problems-12
56 / 56