Question
Question
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
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
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
);
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
You must write all SQL statements in notepad first and save them with .sql extension.
Then execute your SQL scripts.
Write SQL statements to insert the following records into ‘instructor_your_student_id’ 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