Oracle Datatypes: Character Strings CHAR (Size)
Oracle Datatypes: Character Strings CHAR (Size)
LONG RAW - A variable-sized field of raw binary data. The maximum size for
this datatype is 2 GB.
BLOB – The Binary Large Object is a field that holds unstructured binary data.
The maximum size for this datatype is 4 GB.
CLOB – The Character Large Object is a field that holds single byte character
data. The maximum size for this datatype is 4 GB.
NCLOB – The National Character Large Object is a field that holds either single
byte of multibyte character data dependent on the national character set. The
maximum size for this datatype is 4 GB.
BFILE – An external binary file. The maximum size for this file is 4 GB. The size
is also limited by the operating system.
Rows
ROWID – A datatype that contains binary data that is used to identify a row.
Each ROWID is:
6 bytes for normal indexes on non-partitioned tables, local indexes on partitioned
tables and row pointers for chained/migrated rows.
10 bytes for global indexes on partitioned tables.
ROWID – The Universal ROWID is the datatype used to store both logical and
physical ROWID values as well as foreign tables accessed through a gateway.
DDL (Data Definition Language)
1. to Create an object
2. to alter the structure of an object
3. to drop an object created
How To Create Table?
• Syntax :
create table tablename
(columnname data type(size),
columnname data type(size), …);
Note:
If the user uses double quotes then upper & lower case are not
equivalent.
e.g. “info”, “INFO”, “Info” are not same.
Example To Create Table
Command: desc
If user wants to view the table structure above
command will achieve the same.
Syntax:
Desc (tablename);
Example:
desc client_master;
This will display structure of table client_master.
How to Insert Data Into Table?
• Insert Command:
Once table is created it remains
skeletal structure unless it is populated with data. The
insert command is used to add one or more records to
a table.
• Syntax:
insert into tablename values(expression,expression,…);
OR
insert into tablename
(columnname, coumnname,…)
values(expression,expression,…);
Insert Statement :
When inserting a single row of data into a table, the insert
operation,
creates a new row in the database table
loads that row with the values passed into all the columns
specified
If there are exactly same no. of values as per no. of columns &
values are in accordance with the way the column were created;
then no need to specify column name
If there are less values than the columns in the table then it is
mandatory to indicate both the column name & its corresponding
value in the insert statement.
(….continued)
Values must be entered in the same order as they are defined in the
table.
• Use Of ‘&’ In Insert Statement
Syntax:
Insert into tablename values(‘&expr1’, ‘&expr2’,…..);
• Discussion of example.
Viewing Data In The Table
Select Command:
Syntax:
select columnname ,columnname
from tablename;
Example:
select client_no, name
from client_master;
• selected rows and all columns
• Syntax
Select *
from tablename
where search condition;
Example
Select *
from client_master
where bal_due>0;
• Where Clause
Syntax:
select columnname, columnname
from tablename
where search condition;
Example:
Select client_no, client_name
from client_master
where bal_due>0;
• Elimination Of Duplicates:
Syntax:
select distinct columnname, columnname
from tablename;
Example:
select distinct job from employee;
(….continued)
Syntax:
select distinct *
from tablename;
The above syntax scans through entire rows, and eliminates rows
that have exactly the same contents in each column.
Example:
select distinct * from client_master;
This will select only unique row from client_master,
• Sorting Data In a Table
Syntax
select * from tablename
order by columnname, columname [sort order];
• Ascending Order:
• Descending Order:
For viewing the data in descending order the word ‘desc’ must
mentioned after the column name and before the semi colon in
order by clause.
In case there is no mention of sort order in order by clause
Oracle engine sorts in ascending order by default.
The above SQL statement will populate target table with the data from
source table.
• (….continued)
• Example:
Oracle allows to populate a table with data that already exist in another
table. (one row at a time into a table).
Example:
insert into Client_master
select client_name, addr
from client_info;
Insertion of data set from one table to another:
Syntax:
insert into tablename
select columnname, columnname
from tablename
where column=expr;
Example:
insert into Client_master
select client_name, addr
from client_info
where client_name=‘Akash’;
• Delete Operations:
Syntax:
delete from tablename
where search condition;
Example:
delete from client_master
where bal_due<1000;
• Updating Contents Of A Table:
Syntax:
update tablename
set columnname=‘expr’
where search condition;
Example:
update client_master
set bal_due=5000
where client_name=‘Thomus’;
• How to Modify Structure Of Table?
Syntax:
alter table tablename
modify(columnname newdatatype(newsize),…..n);
Example:
alter table client_master
add(client_tele numer(10));
• Restrictions on the Alter Table:
Syntax:
rename oldname to newname;
Example:
rename client_master to client_info;
• Destroying Table:
Syntax:
drop table tablename;
Example:
drop table client_master;
• Examining Objects Created By User: