Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to PL/SQL Oracle Database PL/SQL 10g Programming Chapter 1 & 2.

Similar presentations


Presentation on theme: "Introduction to PL/SQL Oracle Database PL/SQL 10g Programming Chapter 1 & 2."— Presentation transcript:

1 Introduction to PL/SQL Oracle Database PL/SQL 10g Programming Chapter 1 & 2

2 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 2 Introduction to PL/SQL SQL*Plus Environment SQL*Plus Environment Development Environments Development Environments Database Design Concepts Database Design Concepts SQL Concepts SQL Concepts PL/SQL Language PL/SQL Language

3 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 3 Introduction to PL/SQL SQL*Plus Environment The interactive and batch processing environment for SQL and PL/SQL statements. The interactive and batch processing environment for SQL and PL/SQL statements. Command line interface to Oracle. Command line interface to Oracle. The connection and session environment: The connection and session environment: Interactive scripting. Interactive scripting. Batch execution using silent option. Batch execution using silent option. Session environment when connecting by using OCI, ODBC and JDBC external programming models. Session environment when connecting by using OCI, ODBC and JDBC external programming models. Supports formatting commands. Supports formatting commands. Supports session scope variables, also known as bind variables. Supports session scope variables, also known as bind variables. Supports a GUI versions for Microsoft Windows, which is being deprecated. Supports a GUI versions for Microsoft Windows, which is being deprecated.

4 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 4 Introduction to PL/SQL SQL*Plus Environment SQL*Plus is run by using the sqlplus executable on Microsoft Windows, Linux or Unix. SQL*Plus is run by using the sqlplus executable on Microsoft Windows, Linux or Unix. SQL*Plus supports option flags: SQL*Plus supports option flags: -csets command compatibility to current or older version. -csets command compatibility to current or older version. -hprovides help screen. -hprovides help screen. -lsets the log on attempts to a number other than the default 3. -lsets the log on attempts to a number other than the default 3. -mlets you set a series of HTML formatting options. -mlets you set a series of HTML formatting options. -rrestricts user interaction with the file system. -rrestricts user interaction with the file system. -ssets silent mode for batch processing by suppressing console feedback. -ssets silent mode for batch processing by suppressing console feedback. -vreturns the version. -vreturns the version. SQL*Plus supports different connection models: SQL*Plus supports different connection models: DBA Administration connections using “/ AS SYSOPER” or “/ AS SYSDBA”. DBA Administration connections using “/ AS SYSOPER” or “/ AS SYSDBA”. Default connection, which enables a user to connect to a schema and database. Default connection, which enables a user to connect to a schema and database. Open environment not conneted to a database using “/NOLOG” mode. Open environment not conneted to a database using “/NOLOG” mode.

5 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 5 Introduction to PL/SQL SQL*Plus Environment SQL*Plus connection samples: SQL*Plus connection samples: sqlplus –h | -v sqlplus –h | -v sqlplus username/password[@sid] sqlplus username/password[@sid] sqlplus –s username/password[@sid] @script.sql sqlplus –s username/password[@sid] @script.sql SQL*Plus commands do not require semicolons to run. SQL*Plus commands do not require semicolons to run. SQL*Plus redirects output to files with a default.lst extension: SQL*Plus redirects output to files with a default.lst extension: SQL> spool C:\mydir\myoutputfile.log SQL*Plus runs files from local or qualified directories using the @ symbol: SQL*Plus runs files from local or qualified directories using the @ symbol: SQL> @C:\mydir\myfile.sql SQL*Plus runs scripts with a.sql extension when the extension is excluded. SQL*Plus runs scripts with a.sql extension when the extension is excluded.

6 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 6 Introduction to PL/SQL SQL*Plus Environment SQL*Plus can edit the current buffer: SQL*Plus can edit the current buffer: Microsoft is preconfigured, you need only type: Microsoft is preconfigured, you need only type: SQL> ed Linux or Unix requires: Linux or Unix requires: SQL> define _editor=vi SQL> ed SQL*Plus can edit a file: SQL*Plus can edit a file: Microsoft is preconfigured, you need only type: Microsoft is preconfigured, you need only type: SQL> ed C:\mydir\myfile.sql Linux or Unix requires: Linux or Unix requires: SQL> define _editor=vi SQL> ed C:\mydir\myfile.sql

7 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 7 Introduction to PL/SQL SQL*Plus Environment SQL*Plus has many environment variables: SQL*Plus has many environment variables: You can find the default settings by: You can find the default settings by: SQL> show all You change many environment variables by: You change many environment variables by: SQL> set echo on | off You set some environment variables by providing a value: You set some environment variables by providing a value: SQL> set sqlpluscompatibility 9.2.0 You set some environment variables by providing a delimited value: You set some environment variables by providing a delimited value: SQL> set null “ ” SQL> set suffix “pls” SQL*Plus common requirements: SQL*Plus common requirements: Suppress column headers: Suppress column headers: SQL> set pagesize 0 Enabling maximum standard out redirection from PL/SQL: Enabling maximum standard out redirection from PL/SQL: SQL> set serveroutput on size 1000000

8 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 8 Introduction to PL/SQL SQL*Plus Environment SQL*Plus can read only a file into the buffer: SQL*Plus can read only a file into the buffer: You use the GET command. You use the GET command. You cannot run the file without errors if there are SQL*Plus commands in it. You cannot run the file without errors if there are SQL*Plus commands in it. You should use the @ command to read and execute a script when it contains SQL*Plus commands. You should use the @ command to read and execute a script when it contains SQL*Plus commands. SQL*Plus supports global session variables, also known as bind variables, and they must be SQL types not subtypes, like: SQL*Plus supports global session variables, also known as bind variables, and they must be SQL types not subtypes, like:BINARY_DOUBLEBINARY_FLOAT CHAR (n char | byte) CLOBNUMBER REF CURSOR VARCHAR (n char | byte)

9 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 9 Introduction to PL/SQL SQL*Plus Environment SQL*Plus global session variables: SQL*Plus global session variables: Are declared in SQL*Plus. Are declared in SQL*Plus. Are defined in PL/SQL program units. Are defined in PL/SQL program units. SQL*Plus declares a global session variable using the following syntax: SQL*Plus declares a global session variable using the following syntax: SQL> variable mynum NUMBER SQL> variable mystr VARCHAR2(10) SQL*Plus defines the global session variables in PL/SQL program units, which can be: SQL*Plus defines the global session variables in PL/SQL program units, which can be: Anonymous block programs, or Anonymous block programs, or Named block programs. Named block programs.

10 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 10 Introduction to PL/SQL Development Environments SQL*Plus is the interface to the database. SQL*Plus is the interface to the database. SQL runs inside of the SQL*Plus environment. SQL runs inside of the SQL*Plus environment. PL/SQL runs inside of the SQL environment. PL/SQL runs inside of the SQL environment. Oracle development in SQL & PL/SQL is also supported by external Integrated Development Environments (IDEs). Oracle development in SQL & PL/SQL is also supported by external Integrated Development Environments (IDEs). External programs connect through the SQL*Plus environment. External programs connect through the SQL*Plus environment. User-defined libraries are declared by SQL. User-defined libraries are declared by SQL. User-defined libraries are wrapped by PL/SQL named blocks. User-defined libraries are wrapped by PL/SQL named blocks.

11 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 11 Introduction to PL/SQL Development Environments Oracle PL/SQL Development is supported by: Oracle PL/SQL Development is supported by: Oracle SQL*Plus Oracle SQL*Plus Oracle JDeveloper. Oracle JDeveloper. Oracle SQL Developer. Oracle SQL Developer. Oracle Application Developer. Oracle Application Developer. Quest Software’s Toad Developer. Quest Software’s Toad Developer. IDE tools provide: IDE tools provide: Diagnostic tools. Diagnostic tools. Debugging tools. Debugging tools. Syntax auto fill tools. Syntax auto fill tools. Syntax highlighting. Syntax highlighting.

12 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 12 Introduction to PL/SQL Development Environments The Oracle Transparent Network Substrate (TNS) implements an application layer of the OSI model. The Oracle Transparent Network Substrate (TNS) implements an application layer of the OSI model. Users connect through TNS to the database using TCP sockets or IPC connections. Users connect through TNS to the database using TCP sockets or IPC connections. Clients use the tnsnames.ora file like a host file, and map machine names to a combination of IP and port address. Clients use the tnsnames.ora file like a host file, and map machine names to a combination of IP and port address. Net service name resolves to machine name and port number. Net service name resolves to machine name and port number. The service name in the tnsnames.ora file maps to the Oracle database SID value. The service name in the tnsnames.ora file maps to the Oracle database SID value. The Oracle server listens on a port for incoming TNS requests, and uses three configuration files: The Oracle server listens on a port for incoming TNS requests, and uses three configuration files: listener.ora listener.ora sqlnet.ora sqlnet.ora tnsnames.ora tnsnames.ora

13 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 13 Introduction to PL/SQL Development Environments Oracle PL/SQL development is supported by: Oracle PL/SQL development is supported by: Oracle SQL*Plus Oracle SQL*Plus Oracle JDeveloper. Oracle JDeveloper. Oracle SQL Developer. Oracle SQL Developer. Oracle Application Developer. Oracle Application Developer. Quest Software’s Toad Developer. Quest Software’s Toad Developer. IDE tools provide: IDE tools provide: Diagnostic tools. Diagnostic tools. Debugging tools. Debugging tools. Syntax auto fill tools. Syntax auto fill tools. Syntax highlighting. Syntax highlighting.

14 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 14 Introduction to PL/SQL Database Design Concepts Database Tables are: Database Tables are: 2-dimensional arrays of rows and columns. 2-dimensional arrays of rows and columns. Columns can hold a scalar or compound variable: Columns can hold a scalar or compound variable: Scalar variables hold only one thing at a time. Scalar variables hold only one thing at a time. Compound variables hold: Compound variables hold: A list of one thing, which can be scalar or compound. A list of one thing, which can be scalar or compound. A structure, which is also known as a record. A structure, which is also known as a record. Normalized tables with a primary key. Normalized tables with a primary key. Normalized tables with one or more foreign keys. Normalized tables with one or more foreign keys. Foreign keys hold a copy of a primary key in another table. Foreign keys hold a copy of a primary key in another table. Foreign keys hold a copy of a primary key in the same table. Foreign keys hold a copy of a primary key in the same table. Normalized tables with one or more superkey: Normalized tables with one or more superkey: Super keys identify one or more rows in a table. Super keys identify one or more rows in a table. Super keys identify one row in a relation. Super keys identify one row in a relation.

15 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 15 Introduction to PL/SQL Database Design Concepts Database Tables hold data. Database Tables hold data. Database Tables have a binary or n-ary relationships: Database Tables have a binary or n-ary relationships: Binary relations exist between two tables and are: Binary relations exist between two tables and are: One-to-one One-to-one One-to-many One-to-many Many-to-many between two tables. Many-to-many between two tables. N-ary relations exist between three or more tables and are: N-ary relations exist between three or more tables and are: Typically many-to-many Typically many-to-many Occasionally one-to-many. Occasionally one-to-many. Rarely one-to-one. Rarely one-to-one.

16 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 16 Introduction to PL/SQL Database Design Concepts Database tables are normalized in: Database tables are normalized in: 3 rd or higher normal form 3 rd or higher normal form Domain Key Normal Form (DKNF): Domain Key Normal Form (DKNF): DKNF uses a surrogate key, also known as automatic numbering. DKNF uses a surrogate key, also known as automatic numbering. DKNF cannot use a natural key. DKNF cannot use a natural key. Database tables have constraints on column values. Database tables have constraints on column values.

17 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 17 Introduction to PL/SQL Database Design Concepts Unique: Unique: A unique constraint tells the database to disallow a column to hold two or more equal values, and typically made using “out-of-line” constraint syntax. A unique constraint tells the database to disallow a column to hold two or more equal values, and typically made using “out-of-line” constraint syntax.

18 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 18 Introduction to PL/SQL Database Design Concepts Not null : Not null : A not null constraint tells the database to disallow entry of a null value into the column from an INSERT or UPDATE statement, a not null constraint must be made using “inline” syntax or it is a check constraint. A not null constraint tells the database to disallow entry of a null value into the column from an INSERT or UPDATE statement, a not null constraint must be made using “inline” syntax or it is a check constraint.

19 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 19 Introduction to PL/SQL Database Design Concepts Check: Check: A check constraint tells the database to disallow entry or update of a column value that fails to meet the expression governing the constraint, and is typically made using “out of line” constraint syntax. A check constraint tells the database to disallow entry or update of a column value that fails to meet the expression governing the constraint, and is typically made using “out of line” constraint syntax.

20 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 20 Introduction to PL/SQL Database Design Concepts Primary key: Primary key: A primary key tells the database to allow entry or update of a column value that is only both unique and not null, and it enables a foreign key constraint to reference the column or set of columns defined as the primary key, and typically made using “out-of-line” constraint syntax. A primary key tells the database to allow entry or update of a column value that is only both unique and not null, and it enables a foreign key constraint to reference the column or set of columns defined as the primary key, and typically made using “out-of-line” constraint syntax.

21 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 21 Introduction to PL/SQL Database Design Concepts Foreign key: Foreign key: A foreign key constraint tells the database to disallow entry or update of a column value that is not found in the referenced primary key column list of values, and typically made using “out-of-line” constraint syntax. A foreign key constraint tells the database to disallow entry or update of a column value that is not found in the referenced primary key column list of values, and typically made using “out-of-line” constraint syntax.

22 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 22 Introduction to PL/SQL SQL Concepts Structured Query Language (SQL) Structured Query Language (SQL) Structured English QUEry Language (SEQUEL) Structured English QUEry Language (SEQUEL) ANSI Standards ANSI Standards ANSI SQL-86 ANSI SQL-86 ANSI SQL-89 ANSI SQL-89 ANSI SQL-92 ANSI SQL-92 ANSI SQL:1999 ANSI SQL:1999 ANSI SQL:2003 ANSI SQL:2003

23 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 23 Introduction to PL/SQL SQL Concepts Security is tiered by ANSI-SPARC rules Security is tiered by ANSI-SPARC rules Superuser – holds internal data Superuser – holds internal data Administrator – holds conceptual data Administrator – holds conceptual data User – holds external data User – holds external data Superuser grants privileges to users Superuser grants privileges to users Grants individual privileges one at a time. Grants individual privileges one at a time. Creates roles as groups of privileges. Creates roles as groups of privileges. Grants grouped privileges as roles. Grants grouped privileges as roles. Data can be restricted at various levels Data can be restricted at various levels

24 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 24 Introduction to PL/SQL SQL Concepts Data Control Language (DCL) Data Control Language (DCL) Manages transaction controls. Manages transaction controls. Uses the COMMIT, ROLLBACK, and SAVEPOINT commands. Uses the COMMIT, ROLLBACK, and SAVEPOINT commands. Data Definition Language (DDL) Data Definition Language (DDL) Creates or modifies data structures in the database. Creates or modifies data structures in the database. Uses the ALTER, CREATE, DROP, FLASHBACK, GRANT, PURGE, RENAME, REVOKE, and TRUNCATE commands. Uses the ALTER, CREATE, DROP, FLASHBACK, GRANT, PURGE, RENAME, REVOKE, and TRUNCATE commands. Uses the recycle bin in Oracle 10g Release 2. Uses the recycle bin in Oracle 10g Release 2. Data Manipulation Language (DML) Data Manipulation Language (DML) Inserts, updates and deletes data from tables. Inserts, updates and deletes data from tables. Uses the INSERT, UPDATE, and DELETE commands. Uses the INSERT, UPDATE, and DELETE commands.

25 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 25 Introduction to PL/SQL PL/SQL Language Procedural Language/Structured Query Language (PL/SQL) Procedural Language/Structured Query Language (PL/SQL) Introduced in Oracle 6 as a report formatting language. Introduced in Oracle 6 as a report formatting language. Improved to a useful programming language in Oracle 7. Improved to a useful programming language in Oracle 7. Improved to include collections in Oracle 8. Improved to include collections in Oracle 8. Improved to include instantiable object types in Oracle 9i Release 2. Improved to include instantiable object types in Oracle 9i Release 2. Improved to include conditional compilation in Oracle 10g. Improved to include conditional compilation in Oracle 10g. PL/SQL Legacy PL/SQL Legacy Derived syntax from Ada programming language. Derived syntax from Ada programming language. Inherited operators and structure from Pascal through Ada. Inherited operators and structure from Pascal through Ada. PL/SQL Block Structure PL/SQL Block Structure Implemented as a strongly typed language. Implemented as a strongly typed language. Implemented as a formal blocked language. Implemented as a formal blocked language.

26 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 26 Introduction to PL/SQL PL/SQL Language PL/SQL Integration PL/SQL Integration Tightly integrated with SQL. Tightly integrated with SQL. Shares SQL data types. Shares SQL data types. Includes PL/SQL only data types. Includes PL/SQL only data types. Enables user-defined data types. Enables user-defined data types. Interface between external procedures and SQL*Plus. Interface between external procedures and SQL*Plus. Interface between external libraries and SQL*Plus. Interface between external libraries and SQL*Plus.

27 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 27 Introduction to PL/SQL PL/SQL Language PL/SQL Advanced Features PL/SQL Advanced Features Full object-oriented programming is available from Oracle 9i Release 2. Full object-oriented programming is available from Oracle 9i Release 2. Full support for dynamic SQL. Full support for dynamic SQL. Full support for pass-by-value and pass-by-reference models. Full support for pass-by-value and pass-by-reference models. Full support for wrapping solutions in other programming languages. Full support for wrapping solutions in other programming languages. Full catalog definitions act like OO class files. Full catalog definitions act like OO class files. Robust extensions made through built-in packages. Robust extensions made through built-in packages. Conditional compilation available in Oracle 10g Release 2. Conditional compilation available in Oracle 10g Release 2.

28 2006 Oracle Database PL/SQL 10g Programming (Chapter 1 & 2)Page 28 Summary SQL*Plus Environment SQL*Plus Environment Development Environments Development Environments Database Design Concepts Database Design Concepts SQL Concepts SQL Concepts PL/SQL Language PL/SQL Language


Download ppt "Introduction to PL/SQL Oracle Database PL/SQL 10g Programming Chapter 1 & 2."

Similar presentations


Ads by Google