0% found this document useful (0 votes)
5 views2 pages

Oracle SQL Tutorial

The document provides a tutorial on Oracle SQL, covering the creation of a database schema, management of tables, and performing CRUD operations. It includes examples for creating users, tables, and sequences, as well as executing insert, select, update, and delete statements. The tutorial serves as a foundational guide for working with databases in Oracle SQL.

Uploaded by

smmuhad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Oracle SQL Tutorial

The document provides a tutorial on Oracle SQL, covering the creation of a database schema, management of tables, and performing CRUD operations. It includes examples for creating users, tables, and sequences, as well as executing insert, select, update, and delete statements. The tutorial serves as a foundational guide for working with databases in Oracle SQL.

Uploaded by

smmuhad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

An Najah University

Databases Fundamentals

Oracle SQL Tutorial


1. Create a Database Schema
A schema in Oracle is created by creating a user. Below are the steps:

CREATE USER my_schema IDENTIFIED BY my_password;

GRANT CONNECT, RESOURCE TO my_schema;


ALTER USER my_schema QUOTA UNLIMITED ON USERS;

CONNECT my_schema/my_password;

2. Create and Manage Tables


You can create, modify, and manage tables in Oracle. Below are examples:

-- Create Table
CREATE TABLE employees (
emp_id NUMBER PRIMARY KEY,
emp_name VARCHAR2(50) NOT NULL,
department VARCHAR2(30),
salary NUMBER(10, 2),
hire_date DATE DEFAULT SYSDATE
);

-- Add Column
ALTER TABLE employees ADD phone_number VARCHAR2(15);

-- Modify Column
ALTER TABLE employees MODIFY salary NUMBER(12, 2);

-- Drop Column
ALTER TABLE employees DROP COLUMN phone_number;

3. Perform CRUD Operations (Create, Read, Update, Delete)


CRUD refers to Create, Read, Update, and Delete operations. Examples are shown below:

Create (Insert Data)


Insert rows into the table using the INSERT statement.

INSERT INTO employees (emp_id, emp_name, department, salary)


VALUES (1, 'John Doe', 'HR', 5000);

1
An Najah University
Databases Fundamentals

Read (Retrieve Data)


Retrieve data using the SELECT statement.

SELECT * FROM employees;

SELECT emp_name, department FROM employees;

SELECT emp_name, salary FROM employees


WHERE department = 'HR';

SELECT emp_name AS "Employee Name", salary AS "Monthly Salary" FROM


employees;

Update (Modify Data)


Update rows using the UPDATE statement.

UPDATE employees SET salary = 5500 WHERE emp_id = 1;

UPDATE employees SET salary = salary * 1.10;

Delete (Remove Data)


Delete rows using the DELETE statement.

DELETE FROM employees WHERE emp_id = 2;

DELETE FROM employees; -- Deletes all rows (Use carefully!)

4. Use Auto-Generated IDs with Sequences


Oracle uses sequences to auto-generate unique IDs for tables.

CREATE SEQUENCE emp_seq START WITH 1 INCREMENT BY 1;

INSERT INTO employees (emp_id, emp_name, department, salary)


VALUES (emp_seq.NEXTVAL, 'Charlie Green', 'IT', 8000);

You might also like