ORACLE.

Slides:



Advertisements
Similar presentations
AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
Advertisements

7 Copyright © Oracle Corporation, All rights reserved. Producing Readable Output with i SQL*Plus.
PL/SQL (Procedural Language extensions to SQL) Prepared by: Manoj Kathpalia Edited by: M V Ramakrishna.
The SQL Language Presented by Reggie James, Isel Liunoras, and Chris Rollins.
Chapter 4B: More Advanced PL/SQL Programming
1 A GUIDE TO ORACLE8 CHAPTER 2: Creating and ModifyingDatabaseTables 2.
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
SQL Query Extras MIS 433. Rerunning the last Query n Type the forward slash “/” to rerun the last query that was entered.
SQL Within PL / SQL Chapter 4. 2 SQL Within PL / SQL SQL Statements DML in PL / SQL Pseudocolums Transaction Control.
Session Title: Using SQL and PL/SQL for Queries and Reporting Presented By: Stephen Frederic Institution: IHL September 16, 2013.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Oracle10g Developer: PL/SQL Programming1 Objectives Manipulating data with cursors Managing errors with exception handlers Addressing exception-handling.
ISYS 365 – SQL*Plus Environment. 2 Agenda What is SQL*Plus? Command Line Editor Useful SQL*Plus Commands Useful System Tables What is PL/SQL? PL/SQL Constructs.
Session Title: Using SQL and PL/SQL for Queries and Reporting Presented By: Stephen Frederic Institution: IHL September 16, 2014.
1 Reports. 2 Objectives  Use concatenation in a query  Change column headings and formats  Add a title to a report  Group data in a report  Include.
PL / SQL By Mohammed Baihan. What is PL/SQL? PL/SQL stands for Procedural Language extension of SQL. PL/SQL is a combination of SQL along with the procedural.
Programmatic SQL Shaista Khan CS 157B. Topic Embedded SQL statements in high-level programming languages.
Oracle Command Spool Spool C:\temp\Lab9.lst Select Hotel_no, room_no, type, price From Room Order by Hotel_no; Spool Off.
A Guide to SQL, Seventh Edition. Objectives Understand how to use functions in queries Use the UPPER and LOWER functions with character data Use the ROUND.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
Copyright  Oracle Corporation, All rights reserved. 8 Producing Readable Output with SQL*Plus.
Chapter 14 Formatting Readable Output. Chapter Objectives  Add a column heading with a line break to a report  Format the appearance of numeric data.
1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.
A Guide to SQL, Eighth Edition Chapter Eight SQL Functions and Procedures.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Use of Data Security Commands Security: Information is vital to success, but when damaged or in the wrong hands, it can threaten success. OREACLE provides.
Chapter Twelve Report Writing Objectives: -Writing reports -Page set up -Page layout.
Chapter 18: Exception Handling1 Chapter Eighteen Exception Handling Objective: – Define exceptions – List types of exception handlers – Trap errors – Exception.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Oracle PL/SQL SQL*Plus. EDIT Opens notepad with the buffer contents To use type: –Edit –Ed Opens notepad with the buffer contents To use type: –Edit –Ed.
Chapter 5 Introduction To Form Builder. Lesson C Objectives  Use sequences to automatically generate primary key values in a form  Create lists of values.
Last Updated : 27 th April 2004 Center of Excellence Data Warehousing Group Teradata RDBMS Concepts.
Chapter 21: Report writing1 Chapter Twenty One Producing Readable Output Objectives: Writing reports Page set up Page layout Queries with input.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
A Guide to SQL, Sixth Edition 1 Chapter 7 Reports.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
D Copyright © 2009, Oracle. All rights reserved. Using SQL*Plus.
Oracle: Programming Languages SQL and PL/SQL Introduction Toomas Lepikult
Dept. of Computer & Information Sciences
3 A Guide to MySQL.
CIT 214 Introduction to Database Management
Retrieving Data Using the SQL SELECT Statement
A Guide to SQL, Seventh Edition
SQL and SQL*Plus Interaction
Using SQL*Plus.
Creating LOVs and Editors
Chapter Twenty Producing Readable Output
Handling Exceptions.
Vi Editor.
ISYS 365 – SQL*Plus Environment
Using SQL*Plus.
ORACLE SQL Developer & SQLPLUS Statements
Instructor: Raul Cruz-Cano
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
An Introduction to Structured Program Design in COBOL
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Procedures Organized by Farrokh Alemi, Ph.D. Narrated by Yara Alemi
Oracle9i Developer: PL/SQL Programming Chapter 8 Database Triggers.
CHAPTER 17 The Report Writer Module
Chapter 2: Creating And Modifying Database Tables
Chapter 7 Using SQL in Applications
Using SQL*Plus.
Producing Readable Output with iSQL*Plus
Presentation transcript:

ORACLE

SQL*Plus Environment

What is SQL*Plus? Oracle’s development environment Used to write, test and debug SQL and PL/SQL code Hasn’t changed much in 20 years

Command Line Editor list or list # change del Example: /Featuer/Feature (can use any delimiter) del del (current line only) del 3 7 (range of lines) del 2 LAST (deletes from line 2 to the end of the buffer) Do NOT use the word “delete” clear buffer: clears out the SQL statement

Command Line Editor append input Places text at the end of the current line without any spaces between the existing text & the appended text input

Useful SQL*Plus Commands set headsep: identifies the character that tells SQL*Plus when to split a title or column onto 2 or more lines Default character: | SQL> SELECT LNAME "Last_Name|Of|Employee" will display Last_Name Of Employee --------------- Set headsep ! ttitle: sets the title at the top of each page ttitle ‘Sales by Product During 1901!Second Six Months’ If title should display an apostrophe, then use two single quotes btitle: sets the title at the bottom of each page

Useful SQL*Plus Commands column: tells SQL*Plus how to handle columns Can be used to re-label column headings column Item heading ‘What Was!Sold’ Can be used to specify column format column Item format a18 column Rate format 90.99 zero tells SQL*Plus to pad the number with a zero (if necessary) 999,999,999 99.90 Can be used to truncate data in column column Item truncated (OR column Item trunc) Can be used to wrap info column Item word_wrapped

Useful SQL*Plus Commands column: tells SQL*Plus how to handle columns Can be used to specify column format Alphanumeric: column Item format a18 Numeric: column Rate format 90.99 Use nines and zeros to specify the numeric pattern Examples: (a) 999,999,999 (b) 99.90 COLUMN Salary FORMAT $999,999.99 See “numeric formatting” in Oracle Complete Reference

Useful SQL*Plus Commands break on: tells SQL*Plus where to break for subtotals and totals break on Item skip 2 will not repeat the value in the Item column Create one line for each unique Item value and skip 2 lines break on Item duplicate skip 2 will repeat the value in the Item column must be coordinated with the order by clause break on report tells SQL*Plus to provide a grand total for the report Example: break on Item skip 2 on report break on report on Item skip 2 compute sum: tells SQL*Plus to calculate subtotals works in conjunction with the break on command

Useful SQL*Plus Commands Basic rules for computing subtotals & totals: Every break on must have a related order by Consecutive break on commands will override the previous break on command To create both subtotals & totals, combine the break on instructions as follows break on X skip # on report OR break on report on X skip # where X = column name & # = lines to skip between sections Every compute sum must have a related break on Clear breaks and computes before setting up new ones

Useful SQL*Plus Commands set linesize sets the maximum number of characters allowed on any line; usually 70 or 80 set pagesize sets the maximum number of lines per page; usually 66 lines set newpage sets the number of blank lines between pages

Useful SQL*Plus Commands spool & spool off Example: spool test.sql run (/) start (@) save saves the SQL statements, but not the SQL*Plus commands Example: save example.sql (or save example.sql replace) store saves the current SQL*Plus environment Example: store set my_settings.sql create (or …replace or …append)

Useful SQL*Plus Commands To check the current settings column (or column column_name) ttitle btitle break compute show headsep show linesize show pagesize show newpage

Useful SQL*Plus Commands To clear the current settings ttitle off btitle off clear columns clear breaks clear computes

Useful System Tables User_Constraints User_Cons_Columns Useful fields: constraint_name, table_name, constraint_type constraint_type: C, P, R & U User_Cons_Columns Useful fields: constraint_name, column_name, position SELECT column_name FROM user_cons_columns WHERE constraint_name=‘SYS_C0008791’; Retrieving constraints defined by the user WHERE CONSTRAINT_NAME NOT LIKE '%SYS%';

Useful System Tables user_sequences user_errors Contains sequences owned by the current user user_errors Contains compilation errors for the current user Use the ‘show errors’ SQL*Plus command to view the errors in the user_errors table

What Is PL/SQL? PL/SQL stands for Procedural Language operating on or using SQL Combines the flexibility of SQL (4GL) with the power and configurability of the procedural constructs of a 3GL Extends SQL by adding 3GL constructs such as: Variables and types (predefined and user defined) Control Structures (IF-THEN-ELSE, Loops) Procedures and functions Object types and methods

PL/SQL Constructs PL/SQL based on Ada language constructs Block Structure Error Handling Variables and Types Conditionals Looping Constructs Cursors

Introduction to PL / SQL

What Is PL / SQL PL/SQL stands for Procedural Language operating on or using SQL Combines power and flexibility of SQL (4GL) with procedural constructs of a 3GL Extends SQL by adding Variables and types Control Structures Procedures and functions Object types and methods

File 3gl_4gl.sql Demonstrates both SQL and PL/SQL commands DECLARE v_NewMajor VARCHAR2(10) := 'History'; v_FirstName VARCHAR2(10) := 'Scott'; v_LastName VARCHAR2(10) := 'Urman'; BEGIN UPDATE students SET major = v_NewMajor WHERE first_name = v_FirstName AND last_name = v_LastName; IF SQL%NOTFOUND THEN INSERT INTO students (ID, first_name, last_name, major) VALUES (student_sequence.NEXTVAL, v_FirstName, v_LastName, v_NewMajor); END IF; END; /