0% found this document useful (0 votes)
22 views3 pages

Question

yyy

Uploaded by

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

Question

yyy

Uploaded by

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

East West University

Department of Computer Science and Engineering

CSE 302: LAB 01 (Handout)


Course Instructor: Dr. Mohammad Rezwanul Huq

Introduction to Oracle Database XE and SQLPlus Tool for writing SQL queries

Lab Objective

Familiarize students with Oracle database and SQLPlus tool for writing queries in SQL.

Lab Outcome

After completing this lab successfully, students will be able to:


1. Install and Use Oracle database 18c Express Edition and SQLPlus tool for writing queries.
2. Write SQL statements to perform most common and basic database operations.

Psychomotor Learning Levels

This lab involves activities that encompass the following learning levels in psychomotor domain.
Level Category Meaning Keywords
P1 Imitation Copy action of Relate, Repeat, Choose, Copy,
another; observe and Follow, Show, Identify, Isolate.
replicate.
P2 Manipulation Reproduce activity Copy, response, trace, Show,
from instruction or Start, Perform, Execute,
memory Recreate.

Lab Activities

1. Introducing Oracle Database XE


Oracle Database 18c Express Edition (Oracle Database XE) is a free, smaller-footprint edition of
Oracle Database. Oracle Database XE is easy to install and easy to manage. With Oracle Database XE
and related tools you can:
▪ Administer the database. Create tables, views, and other database objects
▪ Import, export, and view table data and Run queries and SQL scripts

2. Executing SQLPlus tool:


SQLPlus is the most basic Oracle Database utility, with a basic command-line interface, commonly
used by users, administrators, and programmers. Follow these steps to execute theSQLPlus tool.
i. Open a command prompt.
ii. Type sqlplus
iii. Then enter system as user-name
iv. And enter your password

3. Creating a Common Database User:


To perform database operations, you have to create a common user. Follow these steps to create a
common user. The username must start with c## in Oracle 18c.
i. Type create user <username> identified by <password>;
ii. Type GRANT RESOURCE, CONNECT, CREATE SESSION, CREATE TABLE,
CREATE VIEW, CREATE ANY TRIGGER, CREATE ANY PROCEDURE, CREATE
SEQUENCE, CREATE SYNONYM, UNLIMITED TABLESPACE TO <username>;
4. Connecting to the Database at Local Machine:
After successfully creating a database user lab, you could connect to the database in the following
way: connect <username>/<password>
To see the list of already created tables by any user:
select table_name from user_tables;

5. Connecting to the Database at Remote Server:


connect <username>/<password>@<server_ip_address>

Always login to remote server during the lab by writing


sqlplus <username>/<password>@<server_ip_address>

6. Creating a Table:
The general syntax for creating a table is given below.
CREATE TABLE table_name
(attribute1 datatype [ NULL | NOT NULL ],
attribute2 datatype [ NULL | NOT NULL ],
...);
There exist different data types in Oracle. Some of them are given below.
▪ char(n): value contains exactly n alpha-numeric characters
▪ varchar2(n): value contains at most n alpha-numeric characters
▪ number: any integer or real numbers
▪ date: DD-MON-YY format like ‘20-JAN-15’
Assume that you want to create a table named person with three attributes which are given below:
i. personId: number type
ii. personName: varchar2 type
iii. personDOB: date type
To create this table, you must write the following query
create table person (
personId number not null,
personName varchar2(50) not null,
personDOB date
);

7. Inserting Records/Rows into a Table:


The general format of inserting a new record is:
insert into table_name values (…,…,…);
Now type the following to insert a new record into person table.
insert into person values (2018001,’Alice’,’01-JAN-92’);

8. Writing Queries:
The basic SQL syntax of a query is given below.
select attribute1, attribute2
from table_name
where <conditional clause> ;

To find only the person id of all persons from person table, you have to type the following:
select personId from person;
9. Executing SQL Script in SQLPlus:
You can create a file with a.sql extension that contains your SQL statements. Then you can execute it
from the SQLPlus command line directly.
Suppose, you have written your SQL statements in a file ‘lab1.sql’ saved under d:\sampledirectory.
To execute that script, you must type
@ d:\sample\lab1.sql
East West University
Department of Computer Science and Engineering

CSE 302: LAB 01 (Exercise - Offline)


Course Instructor: Dr. Mohammad Rezwanul Huq

You must write all SQL statements in notepad first and save them with .sql extension.
Then execute your SQL scripts.

Lab Task # 01 (Creating a table):

Write SQL statement to create a table ‘instructor_your_student_id’ which has 4 attributes –


i) id (number)
ii) name(text)
iii) dept_name(text)
iv) salary(number)

Example: create table instructor_2020360001 ( …… );

Lab Task # 02 (Inserting data into a table):

Write SQL statements to insert the following records into ‘instructor_your_student_id’ table:

Lab Task # 03 (Writing Queries):

i. Show instructor name only.


ii. Show instructor name and department.
iii. Find name and department of instructors who have a salary more than 70000.
iv. Find name and department of instructors who have a salary in between 80000 and 100000 (bounds
are inclusive).
v. Display all records of instructor table.

Submission
Take screenshots of the execution and result of your queries in SQLPlus Tool and insert the captured image
in a doc file for each and every question. Name the file as your_student_id_lab01 and submit the file in the
following link: https://forms.gle/mLmoQYLDsTKWP2dh8

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy