Sqlplus Username: Connect As Sysdba Password: Oracle123 Create User Abhi Identified by Abhishek
Sqlplus Username: Connect As Sysdba Password: Oracle123 Create User Abhi Identified by Abhishek
Larry Ellison and his two friends and former co-workers, Bob Miner and Ed Oates, started a
consultancy called Software Development Laboratories (SDL) in 1977. SDL developed the
original version of the Oracle software.
Syntax
CREATE TABLE TableName (
Column1 datatype,
Column2 datatype,
Column3 datatype,
....
ColumnN datatype
);
CREATE TABLE Emp_Info
(
EmpID Number(2),
EmpName varchar(7),
FName varchar(7),
PhoneNo Number(10),
Address varchar(12),
City varchar(10),
Country varchar(7)
);
INSERT INTO
This statement is used to insert new records into the table.
Syntax
INSERT INTO TableName (Column1, Column2, Column3, ...,ColumnN)
VALUES (value1, value2, value3, ...);
--If you don't want to mention the column names then use the below
syntax
ALTER: It is used to alter the structure of the database. This change could be either to
modify the characteristics of an existing attribute or probably to add a new attribute.
Syntax:
To add a new column in the table
1. ALTER TABLE table_name ADD column_name COLUMN-definition;
To modify existing column in the table:
1. ALTER TABLE MODIFY(COLUMN DEFINITION....);
EXAMPLE
1. ALTER TABLE emp_info ADD(Pincode VARCHAR(6
));
2. ALTER TABLE emp_info MODIFY (empname VARC
HAR(20));
3. ALTER TABLE emp_info
DROP COLUMN country;
This statement is used to drop an existing table. When you use this statement, complete
information present in the table will be lost.
Syntax
DROP TABLE TableName;
UPDATE emp_info
SET empName = 'rahul', fname = ‘rajiv’
WHERE empId = '03';
Addition:
SELECT empid, empname, basic, hra, da, basic+hra+da
AS "Salary" FROM emp_sal;
Substraction:
SELECT empid, empname, basic, hra, da, basic-da
AS "Example_Sub" FROM emp_sal;
Multiplication:
SELECT empid, empname, basic, hra, da, basic*da
AS "Example_Mul" FROM emp_sal;
Division:
SELECT empid, empname, basic, hra, da, basic/da
AS "Example_Div" FROM emp_sal;
Describe Command:
Desc Emp_sal;
SQL Comparison Operators
Operator Description
= Equal to
SELECT * FROM emp_sal
WHERE empid = 1;
Operator Description
Order by Clause:
select * from emp_sal order by empname;
order by sorts the values in ascending order
select * from emp_sal order by empname desc;
Single Row functions - Single row functions are the one who work on single row and
return one output per row. For example, length and case conversion functions are
single row functions.
Multiple Row functions - Multiple row functions work upon group of rows and return
one result for the complete set of rows. They are also known as Group Functions.
Case Conversion functions - Accepts character input and returns a character
value. Functions under the category are UPPER, LOWER and INITCAP.
o UPPER function converts a string to upper case.
o LOWER function converts a string to lower case.
o INITCAP function converts only the initial alphabets of a string to upper
case.
Character functions - Accepts character input and returns number or character
value. Functions under the category are CONCAT, LENGTH, SUBSTR, INSTR.
o CONCAT function concatenates two string values.
o LENGTH function returns the length of the input string.
o SUBSTR function returns a portion of a string from a given start point to
an end point.
o INSTR function returns numeric position of a character or a string in a
given string.
Number functions - Accepts numeric input and returns numeric values.
Functions under the category are ROUND, TRUNC, and MOD.
o ROUND and TRUNC functions are used to round and truncate the
number value.
o MOD is used to return the remainder of the division operation between
two numbers.
SELECT LENGTH(EMPNAME)
FROM emp_info;
The SELECT query below demonstrates the use of SUBSTR and INSTR functions.
SUBSTR function returns the portion of input string from 1st position to 5th position.
INSTR function returns the numeric position of character 'a' in the first name.
SELECT SUBSTR (fname,1,5) from employee;
SELECT INSTR (fname,'h')FROM employee;
Number functions
The SELECT query below demonstrates the use of ROUND and TRUNC functions.
SELECT ROUND (HRA,1)
FROM emp_sal where empid = ‘7’;
MOD() function
MAX ( ) Function
Select max(sal),from emp;
Min ( ) Function
Sum Function:
Select sum(sal) from emp
avg ( ) Function
Count ( ) Function
Group by Function:
The GROUP BY statement is often used with aggregate functions (COUNT, MAX,
MIN, SUM, AVG) to group the result-set by one or more columns.
select count(empname), basic from emp_sal group by basic;
Having Clause:
To_Char
TO_CHAR function converts a datetime value (DATE, TIMESTAMP data types i.e.) to a string using the
specified format.
NVL Function
select empid,empname,nvl(basic,0) from emp_sal;