Download presentation
Presentation is loading. Please wait.
1
ORACLE
2
SQL*Plus Environment
3
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
4
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
5
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
6
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
7
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, 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
8
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
9
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
10
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
11
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
12
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)
13
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
14
Useful SQL*Plus Commands
To clear the current settings ttitle off btitle off clear columns clear breaks clear computes
15
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_C ’; Retrieving constraints defined by the user WHERE CONSTRAINT_NAME NOT LIKE '%SYS%';
16
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
17
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
18
PL/SQL Constructs PL/SQL based on Ada language constructs
Block Structure Error Handling Variables and Types Conditionals Looping Constructs Cursors
19
Introduction to PL / SQL
20
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
21
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; /
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.