You are on page 1of 10

University of Engineering and Technology, Taxila

Database Management System

Lab 02
Introduction to the Oracle Database Software

Engr. Rabia Arshad


University of Engineering and Technology, Taxila 1
Purpose

This lab manual gives the brief introduction about oracle and database connection in oracle.

Oracle Database Software tools:

Oracle has many tools such as SQL * PLUS, Oracle Forms, Oracle Report Writer, Oracle
Graphics etc.

 SQL * PLUS: The SQL * PLUS tool is made up of two distinct parts. These are
o Interactive SQL: Interactive SQL is designed to create access and manipulate
data structures like tables and indexes.
o PL/SQL: PL/SQL can be used to developed programs for different
applications.
 Oracle Forms: This tool allows you to create a data entry screen along with the suitable
menu objects. Thus, the oracle forms tool handles data gathering and data validation in
a commercial application.
 Report Writer: Report writer allows programmers to prepare innovative reports using
data from the oracle structures like tables, views etc. The report writer tool handles the
reporting section of commercial application.

Creating Database with Database Configuration Assistant:


If you do not create a database during installation, you can create one later using the DBCA in
standalone mode.

Engr. Rabia Arshad


University of Engineering and Technology, Taxila 2

Engr. Rabia Arshad


University of Engineering and Technology, Taxila 3

Accessing Oracle Database with Oracle SQL Developer:

To issue SQL and PL/SQL statements to Oracle Database, you can use SQL
Developer. All SQL and PL/SQL commands are supported as they are passed directly from the
SQL Worksheet to the Oracle Database.

To start SQL Developer:

1. From the Start menu, select All Programs, then Oracle - HOMENAME,
then Application Development, and then SQL Developer.

2. If you are asked to enter the full path name for java.exe, click Browse and find java.exe.
For example, C:\Program Files\Java\jdk1.6.0_25\bin\java.exe.
3. Once SQL Developer starts, perform the following steps:

 Right-click Connections.
 Select New Connection.
 In the New/Select Database Connection dialog box, enter a Connection name,
username, password, and for the host string, the name of the database to which
you want to connect.
 Click Connect.

Create/Edit/Select Database Connection

The database connection dialog box displays any existing connections. Depending on the
context, you can select a connection to connect to the database, edit the information about
existing connections, or specify information while creating a new connection.

Connection Name:

An alias for a connection to the database using the information that you enter. (The
connection name is not stored in the database, and the connection is not a database object.)

Username:

Name of the database user for the connection. This user must have sufficient
privileges to perform the tasks that you want to perform while connected to the database, such
as creating, editing, and deleting tables, views, and other objects.

Password:

Password associated with the specified database user.


Engr. Rabia Arshad
University of Engineering and Technology, Taxila 4

Save Password:

If this option is checked, the password is saved with the connection information, and
you will not be prompted for the password on subsequent attempts to connect using this
connection.

Basic connection type:

Hostname: Host system for the Oracle database.

Port: Listener port.

SID: Database name.

Service Name: Network service name of the database (for a remote database connection over
a secure connection).

Once connected, you can view, create, modify, and delete the database objects using the
Connection Navigator or issue any SQL or PL/SQL command using a SQL Worksheet (From
the Tools menu, select SQL Worksheet).

Reviewing User Accounts and Passwords:

All databases created by Oracle Database Configuration Assistant include


the SYS, SYSTEM, and DBSNMP database accounts. In addition, Oracle provides several other
administrative accounts. Before using these other accounts, you must unlock them and reset their
passwords.

SQL Developer User Interface:

You can use shortcut keys to access menus and menu items: for example Alt+F for the File
menu and Alt+E for the Edit menu; or Alt+H, then Alt+S for Help, then Search. You can also
display the File menu by pressing the F10 key (except in the SQL Worksheet, where F10 is the
shortcut for Explain Plan).

To close a window that has focus (such as the SQL Developer main window, a wizard or dialog
box, or the Help Center) and any of its dependent windows, you can press Alt+F4.

Icons under the menus perform various actions, including the following:

New creates a new database object.


Engr. Rabia Arshad
University of Engineering and Technology, Taxila 5
Open opens a file.

Save saves any changes to the currently selected object.

Save All saves any changes to all open objects.

Back moves to the pane that you most recently visited. (Alternatively, use the drop-down arrow
to specify a tab view.)

Forward moves to the pane after the current one in the list of visited panes. (Alternatively, use
the drop-down arrow to specify a tab view.)

Open SQL Worksheet opens the SQL Worksheet .If you do not use the drop-down arrow to
specify the database connection to use, you are asked to select a connection.

Metadata

The metadata tree in the Connections pane displays all the objects (categorized by object
type) accessible to the defined connections. To select an object, expand the appropriate tree
node or nodes, and then click the object. The right side of the SQL Developer window has
tabs and panes for objects that you select or open, as shown in the following figure, which
displays information about a table named BOOKS. (If you hold the mouse pointer over the
tab label -- BOOKS in this figure -- a tooltip displays the object’s owner and the database
connection.)

Engr. Rabia Arshad


University of Engineering and Technology, Taxila 6
SQL (Structured Query Language):

Structured Query Language is a database computer language designed for


managing data in relational database management systems (RDBMS. Its scope includes data
query and update, schema creation and modification, and data access control.

DATA TYPES:

CHAR (Size): This data type is used to store character strings values of fixed length. The size in
brackets determines the number of characters the cell can hold. The maximum number of character
is 255 characters.

1. VARCHAR (Size) / VERCHAR2 (Size): This data type is used to store variable length
alphanumeric data. The maximum character can hold is 2000 character.
2. NUMBER (P, S): The NUMBER data type is used to store number (fixed or floating point).
Number of virtually any magnitude may be stored up to 38 digits of precision. Number as large
as 9.99 * 10 124. The precision (p) 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 up to the maximum of 38 digits.
3. DATE: This data type is used to represent date and time. The standard format is dd-mm-yy as
in 17-SEP-2009. To enter dates other than the standard format, use the appropriate functions.
Date time stores date in the 24-Hours 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 the current month.
4. LONG: This data type is used to store variable length character strings containing up to 2GB.
Long data can be used to store arrays of binary data in ASCII format. LONG values cannot be
indexed, and the normal character functions such as SUBSTR cannot be applied.
5. RAW: The RAW data type is used to store binary data, such as digitized picture or image. Data
loaded into columns of these data types are stored without any further conversion. RAW data
type can have a maximum length of 255 bytes. LONG RAW data type can contain up to 2GB.
There are five types of SQL statements. They are:

1. Data definition LANGUAGE (ddl)

2. Data manipulation language (dml)

3. DATA RETRIEVAL LANGUAGE (DRL)

4. TRANSATIONAL CONTROL LANGUAGE (TCL)

Engr. Rabia Arshad


University of Engineering and Technology, Taxila 7
5. DATA CONTROL LANGUAGE (DCL)

1. DATA DEFINITION LANGUAGE (DDL): The Data Definition Language (DDL) is used
to create and destroy databases and database objects. These commands will primarily
be used by database administrators during the setup and removal phases of a
database project. Let's take a look at the structure and usage of four basic DDL
commands:

1. CREATE 2. ALTER 3. DROP 4. RENAME

1. CREATE:

(a)CREATE TABLE: This is used to create a new relation and the corresponding

Syntax: CREATE TABLE relation_name

CREATE TABLE table_name


(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
);

The column_name parameters specify the names of the columns of the table.
The data_type parameter specifies what type of data the column can hold (e.g. varchar,
integer, decimal, date, etc.).
The size parameter specifies the maximum length of the column of the table.

Engr. Rabia Arshad


University of Engineering and Technology, Taxila 8
Example:

CREATE TABLE Persons


(
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);

(b)CREATE TABLE..AS SELECT....: This is used to create the structure of a new relation
from the structure of an existing relation.

The syntax for the SQL CREATE TABLE AS statement copying all of the columns is:

Syntax: CREATE TABLE new_table

AS (SELECT * FROM old_table);

Engr. Rabia Arshad


University of Engineering and Technology, Taxila 9

TASKS:

1) Create all the tables given above with columns specified:


Coulmn_ID should be Int type, Name is VarChar

Engr. Rabia Arshad

You might also like