0% found this document useful (0 votes)
61 views

Databases Laboratory 1: Marin Iuliana

Here are the activities with answers: 1. Yes, the SELECT statement will execute successfully. It retrieves the last_name, job_id, and salary columns, aliasing salary as Sal. 2. The errors are: - Missing comma after last_name - Missing AS keyword before sal x 12 - Missing FROM keyword - ANNUAL SALARY is not quoted 3. See previous slide titled "Structure of table EMPLOYEES" 4. SELECT last_name||','||job_id||','||salary||','||etc AS THE_OUTPUT FROM employees; This concatenates each column with commas in between and aliases the output as a single column named THE

Uploaded by

Marcela Dobre
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)
61 views

Databases Laboratory 1: Marin Iuliana

Here are the activities with answers: 1. Yes, the SELECT statement will execute successfully. It retrieves the last_name, job_id, and salary columns, aliasing salary as Sal. 2. The errors are: - Missing comma after last_name - Missing AS keyword before sal x 12 - Missing FROM keyword - ANNUAL SALARY is not quoted 3. See previous slide titled "Structure of table EMPLOYEES" 4. SELECT last_name||','||job_id||','||salary||','||etc AS THE_OUTPUT FROM employees; This concatenates each column with commas in between and aliases the output as a single column named THE

Uploaded by

Marcela Dobre
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/ 17

Databases

Laboratory 1

Marin Iuliana
[email protected]
Lab Objectives

-> Create your Dev/Test Environment with


Oracle Application Express or SQL Developer

-> Retrieve Data Using the SQL SELECT


Statement
Login to Oracle Application Express

 Open a browser and access the following website


(https://iacademy3.oracle.com/) with your account details
from the SQL_Accounts_DB.xlsx file. Password: gPqKX20*
How to add tables and data to the APEX account

 Download the SQL_Schema.sql script file.


 Open APEX in your browser and login.
 Select “SQL Workshop”
How to add tables and data to the APEX account

 Select “SQL Scripts”

 Click “Upload”
How to add tables and data to the APEX account

 Click Browse and navigate to the .sql file you downloaded.


 Add a Script Name - “SQL add all tables”, leave “File
Character Set” as default (Unicode UTF-8), and click
“Upload”.
 You will now see the Script listed.
 Click the Run icon.
 Click “Run Now”.
How to add tables and data to the APEX account

 This will take you to the Manage Script Results Page.


 Click "View Results"
 The first attempt will generate errors for the DROP statements due to
the tables not already existing in the schema. These statements are
necessary in the script, if it becomes necessary to restore the tables to
the original state.
 Click the “SQL Workshop” tab
 Click “Object Browser” .

 You should now see the tables listed on the left of the Object Browser
page. These are the tables (and data) that will be used in the curriculum
for your course.
Tables that can be used
Running a query
Setting Oracle SQL Developer

 Install Oracle Database 11g Express Edition and


Oracle SQL Developer.
 Create a new connection.
Oracle SQL Developer Connection

 Unlock the hr username.

password
SQL Syntax

 SELECT column_name, aggregate_function(column_name)


FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value;
Structure of table EMPLOYEES
Queries. Retrieving Data Using the SQL SELECT Statement

 The HR department wants a query to display all unique


job IDs from the EMPLOYEES table.
SELECT DISTINCT job_id
FROM employees;
 The HR department wants a query to display the last
name, job ID, hire date, and employee ID for each
employee, with the employee ID appearing first.
Provide an alias STARTDATE for the HIRE_DATE
column.
SELECT employee_id, last_name, job_id, hire_date StartDate
FROM employees;
 If you want to name the column Start Date instead of
the single word StartDate, then use double quotes.

SELECT employee_id, last_name, job_id, hire_date "Start Date"


FROM employees;
Queries. Retrieving Data Using the SQL SELECT Statement

 The HR department has requested a report


of all employees and their job IDs. Display
the last name concatenated with the job ID
(separated by a comma and space ‘, ‘) and
name the column “Employee and Title”.

SELECT last_name||', '||job_id "Employee and Title"


FROM employees;

Use || and simple


quotes ‘, ‘ for
concatenation
Activities

 1. Does the following SELECT statement execute


successfully?
SELECT last_name, job_id, salary AS Sal
FROM employees;

 2. There are four coding errors in the following


statement. Can you identify them?
SELECT employee_id, last_name
sal x 12 ANNUAL SALARY
FROM employees;
Activities

 3. Determine the structure of the EMPLOYEES table.

 4. Create a query to display all the data from the


EMPLOYEES table. Separate each column output by
a comma. Name the column THE_OUTPUT.

You might also like