oracle sql and plsql
TRANSCRIPT
-
8/6/2019 Oracle SQL and Plsql
1/4
Oracle SQL and PLSQL
SQL stands for Structured Query Language and it is generally referred to as
SEQUEL and it is a Nonprocedural language as compared to the procedural or
third generation languages such as COBOL and C. It was developed by IBM in the
year 1970s.The American National Standards Institute published its first SQLstandard in the year 1986 and secondly in the year 1989.ANSI released updates in
the 1992 known as SQL92 and SQL2 and again in the year 1999 known as SQL 99
and SQL3.Every Time ANSI added new features and incorporated new commands
and capabilities in to the language.
SQL is simple ,yet powerful ,language used to create, access, manipulate data and
structure in the database.
SQL Statement Categories:
DDL- Data Definition Language
DDL is used to define alter and drop database objects and their privileges. DDL
statements will implicitly perform a commit.
DDL Statements:
Create: it is used to create objects(tables ,view) in the database.
Alter: it is used to alter the structure of the database objects.
Drop: delete database objects(it will invalidate the dependent objects, it also drops
indexes, triggers and referential integrity constraints).
Truncate: remove all records from a table, including all the spaces allocated for the
records are removed(it is first as compared to delete and does not generate undo
information as Delete does.it performs implicit commit as it is a DDL.
DML: Data Manipulation Language:
DML is used to access, create and modify or delete data in the structures in the
database.
DML Statements:
Select: select data from the database.
Insert: it is used to insert data into table.
Update: It is used to update existing data with in a table.
Delete: it removes rows from the table.
-
8/6/2019 Oracle SQL and Plsql
2/4
DCL: Data Control Language
DCL Statements:
Commit: it will end current transaction making the changes permanent and visibleto all the users.
Savepoint: it will identify the point(named SAVEPOINT) in a transaction to which you
can later rollback.
Rollback: it will undo all the changes made by the current transactions.
Set-Transaction: it is used to define the properties of a transaction.
SQL syntax:
SQL Select statement:
SELECT* column name FROM table name
Example:
Select salary from emp;
SQL where:
SELECT column name
FROM table name
WHERE condition
Example:
Select salary from emp;
Where salary >2000
SQL Distinct:
SELECT DISTINCT column name
FROM table name
Example:
Select DISTINCT name from emp;
SQL And/or
-
8/6/2019 Oracle SQL and Plsql
3/4
SELECT column name
FROM table name
WHERE condition
{[ANDOR]condition}+
Example:
SELECT salary
FROM emp
WHERE salary >1000
OR (salary 275)
SQL Between
SELECT column name
FROM table name
WHERE column name BETWEEN value1 AND value2
Example:
SELECT*
FROM emp
WHERE Date BETWEEN Jan-01-1999 AND jan-15-1999
SQL in
SELECT column name
FROM table name
WHERE column name IN(value1,value2)
Example:
SELECT*
FROM emp
WHERE last_name IN (sharma, dhall)
SQL like
SELECT column name
FROM table name
-
8/6/2019 Oracle SQL and Plsql
4/4
WHERE column name LIKE{PATTERN}
Example:
SELECT*
FROM table name
[WHERE condition]
ORDER BY column name[ASC,DESC]
Example:
SELECT name, salary
FROM emp
ORDER BY name DESC
SQL Count
SELECT COUNT( column name)
FROM table name
Example:
SELECT COUNT( salary)
FROM emp
SELECT * FROM Table;
In the above query SELECT and FROM are SQL keywords,* is a wildcard which means all
columns