1. SQL Fundamentals
SQL: Structured Query Language is a simple and powerful
language used to create, access, and manipulate data and structure
in the database. SQL is like plain English: easy to understand and to
write. SQL statements into various categories, which are:
•Data Definition Language
•Data Manipulation Language
•Data Control Language.
•Transaction Control Language
•Embedded SQL statements
2. Data Definition Language (DDL) statements:
Thapar University, Oracle Short Term Course
DDL statements are used to define, alter, or drop database objects.
The following table gives an overview about usage of DDL
statements in ORACLE (a commercially used database):
3. Data Manipulation Language
(DML) statements
Once the tables have been created, the DML statements enable
users to query or manipulate data in existing schemas objects.
DML statements are normally the most frequently used
commands.
The following table gives an overview about the usage of DML
statements in ORACLE.
4.
5. Thapar University, Oracle Short Term Course
Data Control Language (DCL)
A privilege can either be granted to a User with the help of
GRANT statement. The privileges assigned can be SELECT,
ALTER, DELETE, EXECUTE, INSERT, INDEX etc. In addition
to granting of privileges, you can also revoke it by using
REVOKE command.
6. Transaction Control Statements (TCL) statements:
Thapar University, Oracle Short Term Course
TCL statements manage the change made by DML statements, and
group DML statements into transactions. The following table gives
an overview about the usage of TCL statements in ORACLE.
7. Embedded SQL statements
Thapar University, Oracle Short Term Course
The SQL statements used to incorporate DDL,DML and transaction
control statements within the body of a procedural language
program, are known as Embedded SQL statements. The following
table gives an overview about the usage of Embedded SQL
statements in ORACLE.
8. Oracle Data types
The information in a database is maintained in the
form of tables and each table consists of rows and
columns, which store data, and therefore this data
must have some data type i.e the type of data,
which is stored in a table.
10. The most commonly used data
types
ď‚· char
ď‚· varchar or varchar2
ď‚· number
ď‚· date
ď‚· long
ď‚· long raw/ raw
11. Let us now briefly describe these data types:
Char(n)
This data type is used to store character strings of fixed size. The size
of the character string is determined by the numeric value of n. This
data type can hold maximum of 255 characters.
When Oracle stores data in a CHAR data type, it will pad the value
stored in the column up to the length of the column as declared by the
table with blanks.
For example: If data type of address field is mentioned as CHAR(40)
and address information of a particular record complete in 20
characters, then remaining 20 characters space is padded with blank
characters.
12. Varchar(n) / Varchar2(n)
This data type is used to store variable length alphanumeric data. It can
store maximum of 2000 characters. In case of varchar data type, Oracle
will not store padded blank spaces if the value stored in a column
defined is less than length of the column as declared by the table with
data type VARCHAR2.
For example: If data type of address field is mentioned as
VARCHAR(40) and address information of a particular record complete
in 20 characters, then remaining 20 characters space is not padded with
blank characters and memory space of 20 characters is used for some
other purposes and not wasted as padded with blank characters.
13. Number (p,s)
This data type is used to store numbers fixed or floating point .
The precision (p) determines the length of the data while (s), the scale,
determines the number of places after the decimal.
The NUMBER data type that is used to store number data can be
specified either to store integers or decimals with the addition of a
parenthetical precision indicator.
For example, if you had a column defined to be data type
NUMBER(10,3), the number 546.3832 would be stored as 546.383,
because after the decimal point we can store 3 digits. It can store a
number of 10 digits including a decimal point for example a maximum
number of 999999.999 can be stored with data type of
NUMBER(10,3).
14. Date
This data type, stores date values in a special format internal to
Oracle.
It offers a great deal of flexibility to users who want to perform
date manipulation operations There are also numerous functions
that handle date operations more complex than simple
arithmetic.
The default format in which date is stored is DD-MON-YY. If
we want to store date in other format then we have to use the
appropriate functions.
15. Long
The developer can declare columns to be of LONG data type, which
can stores upto 2 gigabytes of alphanumeric text data. The values of
long data type cannot be indexed and normal characters functions such
as SUBSTR cannot be applied to long values.
Long Raw / Raw
It is useful to store graphics and sound files when used in conjunction
with LONG to form the LONG RAW data type, which can
accommodate up to 2 gigabytes of data.
Note: A table cannot contain more than one Long column. They cannot
be indexed and no integrity constraints can be applied on them (except
for NULL and NOT NULL constrain).