Lab 1 Writing Interactive Queries CISB514 Advanced Database Systems.

Slides:



Advertisements
Similar presentations
Using the Set Operators
Advertisements

9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
Objectives After completing this lesson, you should be able to do the following: Describe various types of conversion functions that are available in.
Copyright © 2007, Oracle. All rights reserved Using Single-Row Functions to Customize Output Modified: October 21, 2014.
7 Copyright © Oracle Corporation, All rights reserved. Producing Readable Output with i SQL*Plus.
Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
Writing Basic SQL Statements
Restricting and Sorting Data. Consider the table employee(employee_id,last_name,job_id, department_id ) assume that you want to display all the employees.
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using the Set Operators Assist. Prof. Pongpisit Wuttidittachotti, Ph.D. Faculty.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
Ceng 356-Lab2. Objectives After completing this lesson, you should be able to do the following: Limit the rows that are retrieved by a query Sort the.
Ceng 356-Lab1. Objectives After completing this lesson, you should be able to do the following: Get Familiar with the development environment List the.
Objectives After completing this lesson, you should be able to do the following: Define subqueries Describe the types of problems that the subqueries.
Database Programming Sections 5– GROUP BY, HAVING clauses, Rollup & Cube Operations, Grouping Set, Set Operations 11/2/10.
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
Restricting and Sorting Data. ◦ Limiting rows with:  The WHERE clause  The comparison conditions using =,
2 Copyright © Oracle Corporation, All rights reserved. Restricting and Sorting Data.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
4 Copyright © 2006, Oracle. All rights reserved. Restricting and Sorting Data.
Interacting With The Oracle Server. Objectives After completing this lesson, you should be able to do the following: Write a successful SELECT statement.
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
Database control Introduction. The Database control is a tool that used by the database administrator to control the database. To enter to Database control.
8 Producing Readable Output with SQL*Plus. 8-2 Objectives At the end of this lesson, you should be able to: Produce queries that require an input variable.
Intermediate SQL: Aggregated Data, Joins and Set Operators.
INCLUDING CONSTRAINTS lecture5. Outlines  What are Constraints ?  Constraint Guidelines  Defining Constraint  NOT NULL constraint  Unique constraint.
2 第二讲 Restricting and Sorting Data. Objectives After completing this lesson, you should be able to do the following: Limit the rows retrieved by a query.
Conversion Functions.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
Queries SELECT [DISTINCT] FROM ( { }| ),... [WHERE ] [GROUP BY [HAVING ]] [ORDER BY [ ],...]
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Manipulating Data. Objectives After completing this lesson, you should be able to do the following: Describe each DML statement Insert rows into a table.
15 Copyright © Oracle Corporation, All rights reserved. Using SET Operators.
Oracle 11g DATABASE DEVELOPMENT LAB2. Chapter- 2  These commands, which could be issued from SQL*Plus or SQL Developer,  will make it possible to log.
Copyright © 2004, Oracle. All rights reserved. Using the Set Operators.
Copyright  Oracle Corporation, All rights reserved. 8 Producing Readable Output with SQL*Plus.
Working with Columns, Characters, and Rows. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Apply the concatenation.
Using SET Operators Fresher Learning Program January, 2012.
CS 111 – Nov. 8 Databases Database Management Systems (DBMS) Structured Query Language (SQL) Commitment –Please review sections 9.1 – 9.2.
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
Lab 2 Writing PL/SQL Blocks CISB514 Advanced Database Systems.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Limiting Selected Rows. 2-2 Objectives Sort row output using the ORDER BY clause. Sort row output using the ORDER BY clause. Enter search criteria using.
DAY 20: ACCESS CHAPTERS 5, 6, 7 Larry Reaves October 28,
Restricting and Sorting Data
Retrieving Data Using the SQL SELECT Statement
Writing Basic SQL SELECT Statements
Aggregating Data Using Group Functions
Basic select statement
Using the Set Operators
Restricting and Sorting Data
Writing Basic SQL SELECT Statements
ORACLE SQL Developer & SQLPLUS Statements
Using the Set Operators
Restricting and Sorting Data
(SQL) Manipulating Data
Manipulating Data.
Writing Basic SQL SELECT Statements
Restricting and Sorting Data
1 Manipulating Data. 2 Objectives After completing this lesson, you should be able to do the following:  Describe each data manipulation language (DML)
Reporting Aggregated Data Using the Group Functions
Using SQL*Plus.
Restricting and Sorting Data
Reporting Aggregated Data Using the Group Functions
Using the Set Operators
Reporting Aggregated Data Using the Group Functions
Producing Readable Output with iSQL*Plus
Restricting and Sorting Data
Presentation transcript:

Lab 1 Writing Interactive Queries CISB514 Advanced Database Systems

Objectives After completing this lesson, you should be able to:  Write ACCEPT commands to get numeric, character, or date input values from the user  Compose queries with substitution variables to utilize input values from the user

Using the ACCEPT Command The basic syntax: ACCEPT p_variable_name DATATYPE FORMAT ‘format_model’ PROMPT ‘message’ Use the p_ prefix to identify a substitution variable. By default, CHAR is assumed if no datatype is specified. Clearly indicate the expected value / format. Specify a format model as a form of data validation.

Using Substitution Variables Use it in any part of a SELECT statement to specify: What columns to display What tables to use What conditions to be met Etc Precede the variable name with a single ampersand character (&) when being used in a query

Example: Accepting a NUMBER Value for the Search Condition ACCEPT p_location_id NUMBER PROMPT ‘Enter a location ID: ’ SELECT * FROM departments WHERE location_id = &p_location_id Key in 1400, 1500, 1700, 1800, 2400, 2500, or 2700 for results.

Example: Accepting a CHAR Value for the Search Condition ACCEPT p_department_name PROMPT ‘Enter a department name (wildcard characters allowed): ’ SELECT * FROM departments WHERE UPPER(department_name) LIKE UPPER(‘&p_department_name’) Key in it, it%, or %it% and see the difference.

Example: Accepting a DATE Value for the Search Condition ACCEPT p_hire_date DATE FORMAT 'DD/MM/YYYY' PROMPT 'Enter a date (in DD/MM/YYYY format) : ' SELECT * FROM employees WHERE hire_date = TO_DATE('&p_hire_date’, 'DD/MM/YYYY') Key in 07/06/1994 for results. Specify the date format if other than the DD- MON-YYYY format.

Extras It is not mandatory to use the ACCEPT command and substitution variables together Substitution variables can replace any lexical unit (or combination of) in a query except for SELECT

Exercises 1. Write a script that:  Accepts two input values from the user:  minimum salary  maximum salary  Outputs job titles where minimum and maximum salaries fall between the two input values For results, enter 4000 and

Exercises 2. Write a script that:  Displays the names of departments and the their respective managers  Gets the user to specify whether to sort the results by department names or manager names. The user may specify actual column names (department_name or last_name) or use positional notation (1 or 2).

Exercises 3. Write a script that:  Outputs the number of people hired in each department  On a date specified by the user For results, enter 07-JUN-1994.

References For how to specify date format models, see 102/b14200/sql_elements004.htm#i /b14200/sql_elements004.htm#i34924