Unit 2
Unit 2
1
2.1 Structured Query Language (SQL):-
• Overview of SQL,
• Data Types in Oracle,
• Sublanguages of SQL-
– Data Definition Language (create, alter, truncate, drop),
– Data Manipulation Language (insert, select, update, delete),
• Sorting of data,
• Aggregate functions,
• Grouping data from tables (Group by and having clause), and
• SET operators in oracle (Union, Intersect, Minus),
• Oracle transactions.
2
3
Introduction to Oracle
• Way back in June 1970, Dr E. F. Codd published a paper entitled A
Relational Model of Data for Large Shared Data Bank.
4
Introduction to Oracle
• In 1979 a company called Relational Software Inc released the
first commercially available implementation of SQL.
5
Introduction to Structured Query Language
• Structured Query language is a language that provides an interface to
relational database systems.
• SQL was developed by IBM in the 1970s for use in System R and is a de-
facto standard, as well as an ISO and ANSI standard.
• SQL is often pronounced SEQUEL.
• The standard was revised again in in 1992 and was called SQL-
92.
7
Introduction to Structured Query Language
• When an SQL statement is entered it is stored in a part of
memory called the SQL buffer and remains there until a new
statement is entered.
8
Introduction to Structured Query Language
• Features of SQL*PLUS
– SQL*PLUS accepts ad-hoc entries of statements
– Accepts apps SQL input from files
– It provides a line editor for modifying SQL statements
– It controls environmental settings
– It formats query results into basic reports
– It access is local and remote data bases
•
• SQL*PLUS- It is an extension to SQL. It has been introduced to
eliminate SQL limitations. It has hundreds of SQL commands. SQL
is a subset of SQL*PLUS. It is used for setting up the environment.
• Each column of a table will have a specific data type bound to it.
• Oracle and shows that only data which is identical to the data type
of the column, will be stored within the columns.
10
Oracle Data types
• Data types come in several forms and sizes, allowing the
programmer to create tables suited to the scope of the project.
• The size in brackets determines the number of characters the cell can
hold.
• The maximum number of characters (i.e. the size) this data type can hold is
255 characters.
• The data held is right padded with spaces to whatever the length
specified
• For example:
– In case of Name CHAR(60), if the data held in the variable Name is
only 20 characters in length, then the entry will be provided with 40
characters worth of spaces.
12
VARCHAR(size) / VARCHAR2(size)
• This data type is used to store variable length alphanumeric data.
• It is a more flexible form of the CHAR data type.
• The maximum this data type can hold up to 4000 characters.
• One difference between this data type and the CHAR data type is Oracle
compares VARCHAR values using non-padded comparison semantics
i.e. the inserted values will not be padded with spaces.
• It also represents data of type String, yet stores this data in variable
length format.
• VARCHAR can hold 1 to 255 characters.
• VARCHAR is usually a wiser choice than CHAR, due to its variable
length format characteristic.
13
DATE
• This data type is used to represent date and time.
• The standard format is DD-MON-YY as in 21-JUN-04.
• To enter dates other than the standard format, use the appropriate
functions.
• Date-Time stores date in 24-hour format.
• By default, the time in a date field is 12:00:00 am, if no time
portion is specified.
• The default date for a date field is the first day of the current month.
• Valid dates range from January 1, 4712 B.C. to 2 December 31,
4712 A.D.
14
NUMBER(P,S)
• The NUMBER data type is used to store numbers ( fixed or floating
point).
• Numbers of Virtually any magnitude maybe stored upto 38 digits of
precision.
• Valid values are 0, and positive and negative numbers with magnitude
1.0E- 130 to 9.9...E125.
• Numbers may be expressed in two ways: first, with the numbers 0 to 9, the
signs + And -, and a decimal point (.); second, in scientific notation, such
as 1.85E3 for 1850.
• The precision (P), determines the maximum length of the data, whereas
the scale (S), determines the number of places to the right of the decimal.
• If scale is omitted then the default is zero.
• If precision is omitted, values are stored with their original precision upto
the maximum of 38 digits.
15
LONG
• This data type is used to store variable length character strings up to 2GB.
• LONG data can be used to store arrays of binary data in ASCII format.
• Only one LONG value can be defined per table.
• Data loaded into columns of these data types are stored without any
further conversion.
17
18
References
• https://docs.oracle.com/cd/B19306_01/server.102/b14200/
statements_5001.htm#:~:text=A%20cluster%20is%20a
%20schema,share%20the%20same%20cluster%20key.&text=Oracle
%20Database%20Performance%20Tuning%20Guide%20for
%20suggestions%20on%20when%20to%20use%20clusters
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35