eng. mohammed alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/lab1_introduction_to_ora… ·...

18
Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Database Lab (ECOM 4113) Lab 1 Introduction to Oracle Eng. Mohammed Alokshiya September 30, 2014

Upload: others

Post on 18-Oct-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

Islamic University of Gaza

Faculty of Engineering

Computer Engineering Dept.

Database Lab (ECOM 4113)

Lab 1

Introduction to Oracle

Eng. Mohammed Alokshiya

September 30, 2014

Page 2: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

2

Oracle Database Management System

Oracle Database (commonly referred to as Oracle RDBMS or simply as Oracle) is an object-relational database management system produced and marketed by Oracle Corporation. Its last version is Oracle 12c (c refers to cloud) and its primary query language is PL/SQL.

For our lab, we will use Oracle Database Express Edition 11.2g, since this version does not have significant system overhead requirements.

Installing Oracle XE

Installing Oracle XE is an easy task. Just double click on “setup.exe” and follow the installation wizard:

Page 3: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

3

Do not hesitate to accept the terms in the license agreement

Page 4: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

4

Page 5: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

5

Now you have to assign a password for your database. Be careful at this step since the password will be used for both “SYS” and “SYSTEM” database accounts, which we will about them later.

Page 6: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

6

Finally, you will see a report of your database settings. Click “Install”.

Page 7: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

7

Ignore errors like this:

Be patient! Configuring database will take few minutes

Page 8: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

8

At this point, Oracle Express Edition has successfully installed and can be accessed through user accounts. Some of these accounts are automatically created administrative accounts—accounts with database administration privileges, and others are created but LOCKED by default and their passwords are expired. Before you can use a locked account, you must unlock it and reset its password. The following table lists some of the Oracle Database XE predefined user accounts:

User Account Name

Purpose

SYS Owns the data dictionary base tables and views. The account password is set upon installation.

SYSTEM

Log in with this account to perform routine database administration. The account password is set upon installation.

Page 9: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

9

HR For the HR sample schema. This account is initially expired and locked.

ANONYMOUS Internal. Used for anonymous HTTP access to the database. Required by the Oracle Database XE graphical user interface. This account must remain unlocked. The account password is set upon installation.

… …

Schemas and Common Schema Objects

A schema is a collection of database objects. A schema is owned by a database user and has the same name as that user. Schema objects are the logical structures that directly refer to the database's data. Schema objects include structures like tables, views, and indexes. Schema’s objects include:

Tables

Tables are the basic unit of data storage in an Oracle database. Database tables hold all user-accessible data. Each table has columns and rows. A table that has an employee database, for example, can have a column called employee number, and each row in that column is an employee's number. Indexes

Indexes are optional structures associated with tables. Indexes can be created to increase the performance of data retrieval. Just as the index in this manual helps you quickly locate specific information, an Oracle index provides an access path to table data.

Page 10: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

10

When processing a request, Oracle can use some or all of the available indexes to locate the requested rows efficiently. Indexes are useful when applications frequently query a table for a range of rows (for example, all employees with a salary greater than 1000 dollars) or a specific row.

Indexes are created on one or more columns of a table. After it is created, an index is automatically maintained and used by Oracle. Changes to table data (such as adding new rows, updating rows, or deleting rows) are automatically incorporated into all relevant indexes with complete transparency to the users. Views

Views are customized presentations of data in one or more tables or other views. A view can also be considered a stored query. Views do not actually contain data. Rather, they derive their data from the tables on which they are based, referred to as the base tables of the views.

Like tables, views can be queried, updated, inserted into, and deleted from, with some restrictions. All operations performed on a view actually affect the base tables of the view.

Views provide an additional level of table security by restricting access to a predetermined set of rows and columns of a table. They also hide data complexity and store complex queries. Synonyms

A synonym is an alias for any table, view, materialized view, sequence, procedure, function, package, type, Java class schema object, user-defined object type, or another synonym. Because a synonym is simply an alias, it requires no storage other than its definition in the data dictionary.

Page 11: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

11

HR Schema

As we said before, some accounts are automatically created while installing Oracle XE. One of these accounts is “HR” account, which has a sample schema that is full of objects and its tables is rich of data. This schema was created for academic purposes and targets students. Unfortunately, “HR” account is initially locked and expired, Therefore, we have to unlock it by using “ALTER USER ... ACCOUNT UNLOCK” statement.

Firstly, we will connect to our database using “SYSTEM” account, which has administrative privileges. From “start” menu, Run SQL Command Line:

Then connect to the database: “connect username/password” Finally, unlock “HR” account by using the “ALTER USER ... ACCOUNT UNLOCK” statement

Unlocking “hr” database account // Connecting to the database using “system” account connect system/manager; // unlocking “hr” account alter user hr identified by hr account unlock;

Page 12: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

12

Now you can discover schema objects that belong to “HR”,

like tables, by issuing “SELECT TABLE_NAME FROM USER_TABLES”

statement.

Retrieving Tables Names in a Schema SELECT TABLE_NAME FROM USER_TABLES;

Page 13: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

13

Oracle SQL Developer

Oracle SQL Developer is the Oracle Database IDE. A free graphical user interface, Oracle SQL Developer allows database users and administrators to do their database tasks in fewer clicks and keystrokes. A productivity tool, SQL Developer’s main objective is to help the end user save time and maximize the return on investment in the Oracle Database technology stack.

SQL Developer supports Oracle Database 10g, 11g, and 12c and will run on any operating system that supports Java.

Working with SQL Developer is very easy; even it does not have to be installed on your device! Just double click on “sqldeveloper.exe” and it will be ready to be used for managing database!

Page 14: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

14

Click on the green icon (+) to create a new connection to your DB.

Page 15: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

15

Connection details:

Page 16: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

16

Now, your connection is ready and you can use it for managing database, discovering the schema, and reviewing tables and its contents, etc…

Page 17: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

17

Running SQL commands:

Page 18: Eng. Mohammed Alokshiyasite.iugaza.edu.ps/mokshiya/files/2014/10/Lab1_Introduction_to_Ora… · They also hide data complexity and store complex queries. ... HR Schema As we said

18

Finally, reviewing tables’ contents: