Introduction to Oracle PL/SQL Programming V2.1 - Lessons 11-End

Size: px
Start display at page:

Download "Introduction to Oracle PL/SQL Programming V2.1 - Lessons 11-End"

Transcription

1 Introduction to Oracle PL/SQL Programming V2.1 - Lessons 11-End

2 Introduction to Oracle PL/SQLProgramming Page i Table of Contents 0. How to Use This Course Lesson Objectives Target Audience Course Objectives Course Book Layout Conventions Used Getting Help Introduction to PL/SQL Lesson Objectives What is PL/SQL? Why Use PL/SQL? PL/SQL Program Structure Anonymous Blocks Compile Errors Output to SQL*Plus Procedures Procedure Compile Errors Functions Packages Data Dictionary Triggers Tools for Development Working in SQL*Plus Introduction to PL/SQL Workshops Language Fundamentals Lesson Objectives Statements PL/SQL Symbols Common PL/SQL Datatypes Declaring Variables %TYPE V2.1

3 Introduction to Oracle PL/SQLProgramming Page ii PL/SQL Records Records: %ROWTYPE Programmer Defined Records Language Fundamentals Workshop A Variable Scope Nested Blocks Functions IF Statement CASE Simple CASE Searched CASE Simple Loops Nested Loops Numeric FOR Loop PL/SQL Arrays Simple Array Example Array Methods Language Fundamentals Workshop B PL/SQL and SQL: Basics Lesson Objectives SELECT INTO Statement Implicit Cursor Loops Basics Workshop A (Cursor Loop) DML in PL/SQL Cursor Attributes Embedding DDL Basics Workshop B (NDS) PL/SQL and SQL: Cursors Lesson Objectives What is a Cursor? Cursor Processing Cursor Attributes Cursors Workshop A Dynamic Cursors Dynamic Cursor Example Variable Scope & Cursors Problem Example Cursor Parameters Cursor Record Cursor FOR LOOP FOR LOOP Example V2.1

4 Introduction to Oracle PL/SQLProgramming Page iii FOR LOOP Example Cursors Optional Workshop B Referencing the Current Row FOR UPDATE Example FOR UPDATE Example Cursors Optional Workshop C PL/SQL and SQL: Bulk Processing Lesson Objectives Bulk Processing Bulk Collect Bulk Collect: SELECT INTO Bulk Collect: Multiple Arrays Bulk Collect: Array of Records Bulk Collect: FETCH with LIMIT Bulk Processing Workshop A Bulk DELETE Bulk INSERT Returning into Arrays Summary Bulk Processing Workshop B Procedures Lesson Objectives What is a Procedure? Abbreviated Syntax Simple Example Review: Compile Errors Procedure Signatures Calling Procedures Procedure Synonyms Referencing Parameters by Name Returning Sets: REF CURSOR Dropping Procedures Dependencies ALTER COMPILE Privileges Execute Privilege The Data Dictionary Procedures Workshop V2.1

5 Introduction to Oracle PL/SQLProgramming Page iv 7. Functions Lesson Objectives What is a Function? Abbreviated Syntax Simple Example Calling Functions The Data Dictionary Functions Workshop A Table Functions Building a Table Function Using a Table Function Pipelined Functions Pipelined Example Test Data Generator Functions Workshop B Error Handling Lesson Objectives Types of Errors Runtime Errors Exception Concepts Predefined Named Exceptions Syntax Handling Exceptions Recovering from Errors Logging Exceptions RAISE_APPLICATION_ERROR RAE Example Error Handling Workshop Raising Exceptions Raising User Exceptions EXCEPTION_INIT Summary Packages Lesson Objectives Concepts Package Benefits Package Benefits Diagram Package Contents Package Specification Syntax Package Specification Example V2.1

6 Introduction to Oracle PL/SQLProgramming Page v Package Body Syntax Package Body Example Privileges Calling Packaged Objects Initialization Code Session Variables Package Body Variables Packages Workshop A Package Overloading Overloading Example Packages Workshop B Compiling Packages DROP Package Packages Workshop C Supplied Packages Summary Triggers Lesson Objectives Trigger Concepts Trigger Execution Create Trigger Syntax Row Trigger :OLD Reference Variable :NEW Reference Variable Trigger Attributes Audit Trigger Derived Value Trigger Restrictions Security Privileges Triggers Workshop A Statement Level Trigger Triggers Workshop B Autonomous Transactions Autonomous Trigger Triggers Workshop C INSTEAD OF Triggers Sybase / MS SQL Server vs. Oracle Triggers Triggers Workshop D File I/O Using UTL_FILE Lesson Objectives UTL_FILE Concepts V2.1

7 Introduction to Oracle PL/SQLProgramming Page vi Setup Unix File Permissions Opening Files Closing Files Reading Files Reading Files Example Writing Files Writing Files - PUT Writing Files - PUT_LINE Writing Files - NEW_LINE Writing Files - PUTF Writing Files Example UTL_FILE Workshop Using DBMS_JOB Lesson Objectives What is DBMS_JOB? Setup DBMS_JOB.SUBMIT SUBMIT Example Running a Job Cleaning Up Broken Jobs Removing a Job Changing Job Parameters Viewing Job Information Using DBMS_JOB Workshop Profile and Tune Lesson Objectives Introduction to Tuning PL/SQL DBMS_PROFILER Profiler Setup Using Profiler Testing Reporting Profile & Tune PLSQL Workshop A. Dynamic SQL... A.1 What is Dynamic SQL?...A.2 NDS vs. DBMS_SQL...A.3 NDS Statement Summary...A.5 NDS Single-Row Query Syntax...A.6 V2.1

8 Introduction to Oracle PL/SQLProgramming Page vii NDS Single-Row INSERT Example...A.7 NDS Multi-Row Query Syntax...A.8 NDS Multi-Row Query Example...A.9 NDS PL/SQL Example...A.10 DBMS_SQL Procedures Summary...A.11 DBMS_SQL Example...A.12 Privileges...A.13 Dynamic SQL Workshop...A.14 B. Table Descriptions... B.1 V2.1

9 File I/O Using UTL_FILE 11.1 Lesson 11 File I/O Using UTL_FILE SKILLBUILDERS V2.1

10 File I/O Using UTL_FILE Lesson Objectives File Input/Output in PL/SQL Open and close operating system files Read and write to operating system files Handling exceptions raised during file processing V2.1

11 File I/O Using UTL_FILE UTL_FILE Concepts Extension package Provides input and output to text files on the server Can be network drive accessible from server Supports common language I/O functions opening, closing reading, writing, appending UTL_FILE is an extension package of the original Oracle PL/SQL language that allows input and output to text files on the server. Note that the text files referred to are on the server only and not on the client. UTL_FILE supports common I/O functions such as opening, closing, reading, writing and appending of files. This package is available with versions of PL/SQL 2.3 and higher. UTL_FILE is different from the DBMS_OUTPUT package which allows input and output to a screen, not a file. Sybase and MS SQL Server do not have direct equivalents to UTL_FILE. Use their bcp utility to export and import ASCII files. V2.1

12 File I/O Using UTL_FILE 11.4 Setup Create a directory to point to OS file system 11.4 SQL> SQL> create or or replace directory class class as as 'c:\temp'; Directory created. SQL> SQL> grant grant read, read, write write on on directory class class to to public; Grant Grant succeeded. The starting point for using UTL_FILE is to create an Oracle directory. The directory is an Oracle object that points to a server-based operating system directory. Like all Oracle objects, the directory is protected from other database users. You must GRANT READ and write privileges on it to users who need to use UTL_FILE to access the directory. Supplemental Notes CREATE ANY DIRECTORY privilege is required to create a directory. The database will require OS privileges to read/write to the OS directory named in the CREATE DIRECTORY commands (typically, this is accomplished by granting the OS privileges to the OS user ORACLE ). Prior to 9i, access was made to the OS by setting the UTL_FILE_DIR parameter in the INIT.ORA file. V2.1

13 File I/O Using UTL_FILE 11.5 Unix File Permissions Using SQL*Plus on the server side $ -rw-rw-rw- 1 oracle dba dba 0 timestamp filename1 Using SQL*Plus on the client side $ -rw-rw-rw- 1 user user group group 0 timestamp filename2 Before executing a PL/SQL program on the client side, any files that don t exist need to be created $ touch touch filename $ chmod chmod filename 11.5 File Permissions Different file permission situations arise based on where a PL/SQL program is executed on a UNIX operating system. For Windows systems, the user only needs to have permission to access the directory in which the UTL_FILE package will be manipulating files. Server Side Execution When executing PL/SQL using SQL*Plus on the server side from either the command line or in batch mode all files will be created with the following owner, group and permissions. $ -rw-rw-rw- 1 oracle dba 0 timestamp filename1 Since the owner and group of the SQL*Plus executable file(which resides in your $ORACLE_HOME/bin sub directory) is owned by oracle and in the DBA group the file will get created with these settings Client Side Execution When executing PL/SQL using SQL*Plus on the client side all files will be created with the following owner, group and permissions $ -rw-rw-rw- 1 user group 0 timestamp filename2 continued... V2.1

14 File I/O Using UTL_FILE 11.6 File Initialization Before executing the PL/SQL programs from the client side any files that do not exist could be created in order to circumvent any permission problems. touch is a UNIX command that creates a zero length file if it does not exist or updates an already existing file with a current timestamp. $ touch filename $ chmod 777 filename After the file is created using touch, the permissions need to be set using the chmod command. V2.1

15 File I/O Using UTL_FILE 11.7 FILE_TYPE Opening Files A file is pointed to by a handle which is its own type A file handle, like any other variable, must be declared before a file can be opened v_filehandle_name FOPEN UTL_FILE.FILE_TYPE; The UTL_FILE function used to open a file UTL_FILE.FOPEN(location, filename, mode [, [, max_linesize]); 11.7 There are 2 subprograms within the UTL_FILE package that handle the opening of files, FILE_TYPE and FOPEN. FILE_TYPE is used to type a variable of the correct type to hold the handle returned by the FOPEN function. When FOPEN is called, it returns a file handle (pointer) to the file it opened. The variable that receives that file handle must be typed correctly using FILE_TYPE before the FOPEN function is called. FOPEN Parameters: location - the fully qualified directory path filename - the actual file name mode - mode for opening the file (r: read, w: write, a: append) max_linesize allows lines larger than the default (1023 bytes) up to 32K to be accepted. The maximum number of files that can be opened using FOPEN at once is 50. Supplemental Notes Testing FOPEN with IS_OPEN A file can be tested to see if it is already open by using the IS_OPEN function. The IS_OPEN function takes one parameter as input, a file handle of type FILE_TYPE and returns one value as output, a boolean (true for open, false for closed). UTL_FILE.IS_OPEN (file_handle) ; continued.... V2.1

16 File I/O Using UTL_FILE 11.8 Exceptions There are several possible exceptions (errors) that may occur when attempting to open a file: UTL_FILE.INVALID_PATH UTL_FILE.INVALID_MODE Directory of filename is incorrect Incorrect open mode specified UTL_FILE.INVALID_OPERATION Operating system error (i.e. File permissions or file does not exist) UTL_FILE.INTERNAL_ERROR Oracle internal error So, your EXCEPTION block might contain: EXCEPTION WHEN UTL_FILE.INVALID_PATH THEN RAISE_APPLICATION_ERROR (-20051, 'Invalid Path'); WHEN UTL_FILE.INVALID_MODE THEN RAISE_APPLICATION_ERROR (-20052, 'Invalid Mode'); WHEN UTL_FILE.INTERNAL_ERROR THEN RAISE_APPLICATION_ERROR (-20053, 'Internal Error'); WHEN UTL_FILE.INVALID_OPERATION THEN RAISE_APPLICATION_ERROR (-20054, 'Invalid Operation'); END; V2.1

17 File I/O Using UTL_FILE Closing Files FCLOSE The UTL_FILE function used to close a file UTL_FILE.FCLOSE(file handle); FCLOSE_ALL The UTL_FILE function used to close all open files at once UTL_FILE.FCLOSE_ALL; An open file can be closed by the UTL_FILE package using the FCLOSE procedure. The FCLOSE procedure takes one parameter as input, a file handle of type FILE_TYPE and has no return value. All open files can also be closed at once using the UTL_FILE procedure FCLOSE_ALL. The FCLOSE_ALL procedure takes no input parameters and has no return values. Exceptions UTL_FILE.INVALID_FILEHANDLE UTL_FILE.WRITE_ERROR UTL_FILE.INTERNAL_ERROR File handle does not point to an open file Oracle error during write Oracle internal error V2.1

18 File I/O Using UTL_FILE Closing Files Example (including exception processing block) CREATE OR REPLACE PROCEDURE p_utl_close IS v_filehandle_input UTL_FILE.FILE_TYPE; BEGIN IF NOT UTL_FILE.IS_OPEN (v_filehandle_input) THEN v_filehandle_input := UTL_FILE.FOPEN( CLASS, 'input_file.txt', 'r'); END IF; UTL_FILE.FCLOSE (v_filehandle_input); EXCEPTION WHEN UTL_FILE.INVALID_PATH THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR (-20051, 'Invalid Path'); WHEN UTL_FILE.INVALID_MODE THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR (-20052, 'Invalid Mode'); WHEN UTL_FILE.INTERNAL_ERROR THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR (-20053, 'Internal Error'); WHEN UTL_FILE.INVALID_OPERATION THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR (-20054, 'Invalid Operation'); WHEN UTL_FILE.WRITE_ERROR THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR (-20055, 'Write Error'); WHEN OTHERS THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR (-20056, 'Others Error'); END; / V2.1

19 File I/O Using UTL_FILE Reading Files GET_LINE The UTL_FILE function used to read a file UTL_FILE.GET_LINE(file handle, buffer); A file can be read by the UTL_FILE package using the GET_LINE procedure. The GET_LINE procedure takes one parameter as input, a file handle of type FILE_TYPE and returns one line of text into a buffer variable of type VARCHAR2. Note: The maximum length of an input line that can be read by the UTL_FILE procedure GET_LINE is 32K. Exceptions UTL_FILE.INVALID_FILEHANDLE UTL_FILE.READ_ERROR UTL_FILE.INTERNAL_ERROR UTL_FILE.INVALID_OPERATION VALUE_ERROR NO_DATA_FOUND File handle does not point to an open file Oracle error during read Oracle internal error File not properly opened Line of text does not fit into buffer variable Last line of text is read from file V2.1

20 File I/O Using UTL_FILE Reading Files Example SQL> SQL> CREATE CREATE OR OR REPLACE REPLACE PROCEDURE PROCEDURE readit readit 2 IS IS 3 v_filehandle_input UTL_FILE.FILE_TYPE; 4 v_newline v_newline VARCHAR2(32767); 5 BEGIN BEGIN 6 v_filehandle_input := := 7 UTL_FILE.FOPEN( CLASS','functions.sql', 'r', 'r', ); ); 8 loop loop 9 BEGIN BEGIN UTL_FILE.GET_LINE(v_filehandle_input,v_newline); DBMS_OUTPUT.PUT_LINE(v_newline); EXCEPTION EXCEPTION WHEN WHEN NO_DATA_FOUND NO_DATA_FOUND THEN THEN EXIT EXIT ; END; END; end end loop; loop; UTL_FILE.FCLOSE (v_filehandle_input) ; end; end; SQL> / SQL> exec exec readit readit select select unistr('\0300') unistr('\0300') from from dual; dual; Procedure Procedure created. created. select select compose('de' compose('de' unistr('\0300') unistr('\0300') ) ) from from dual; dual; PL/SQL PL/SQL procedure procedure successfully successfully completed. completed In this example, the GET_LINE procedure is executed within a loop until the NO_DATA_FOUND exception is raised. At that time, the loop is exited and processing continues. Why is there a nested BEGIN END within the LOOP construct? Recall that when an exception is raised, control passes to the EXCEPTION block. By nesting another BEGIN END within the outer one, we can code the inner block s exceptions to handle only the specific errors that are related to the GET_LINE procedure. The outer EXCEPTION block would handle exceptions related to the outer BEGIN END. This helps to tighten up code and insures that exceptions are handled immediately within the block that caused the error rather than having to propagate the error to a calling, or outer, block. Refer to the supplied script UTL_FILE_DEMO.SQL for a working copy of this example. continued V2.1

21 File I/O Using UTL_FILE Another Reading Files Example CREATE OR REPLACE PROCEDURE p_utl_read IS v_filehandle_input UTL_FILE.FILE_TYPE; v_newline VARCHAR2 (32767); BEGIN IF NOT UTL_FILE.IS_OPEN (v_filehandle_input) THEN v_filehandle_input := UTL_FILE.FOPEN('CLASS','input_file.txt', 'r'); END IF; LOOP BEGIN UTL_FILE.GET_LINE (v_filehandle_input, v_newline); DBMS_OUTPUT.PUT_LINE (v_newline); EXCEPTION WHEN NO_DATA_FOUND THEN EXIT; END; END LOOP; UTL_FILE.FCLOSE (v_filehandle_input); EXCEPTION WHEN UTL_FILE.INVALID_PATH THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR (-20051, 'Invalid Path'); WHEN UTL_FILE.INVALID_MODE THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR (-20052, 'Invalid Mode'); WHEN UTL_FILE.INTERNAL_ERROR THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR (-20053, 'Internal Error');.... continued.... V2.1

22 File I/O Using UTL_FILE Reading Files Example (continued).... WHEN UTL_FILE.INVALID_OPERATION THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR (-20054, 'Invalid Operation'); WHEN UTL_FILE.WRITE_ERROR THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR (-20055, 'Invalid Operation'); WHEN UTL_FILE.INVALID_FILEHANDLE THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR(-20056, 'Invalid Filehandle ); WHEN UTL_FILE.READ_ERROR THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR (-20057, 'Read Error'); WHEN VALUE_ERROR THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR (-20058, 'Value Error'); WHEN OTHERS THEN UTL_FILE.FCLOSE_ALL; RAISE_APPLICATION_ERROR (-20059, 'Others Error'); END; / V2.1

23 File I/O Using UTL_FILE Writing Files PUT Outputs a text string to a file without a newline PUT_LINE Outputs a text string to a file with a newline NEW_LINE Outputs a single newline to a file PUTF Outputs a formatted string to a file without a newline and accepts up to 5 substitution strings into the formatted string A file can be written to by the UTL_FILE package using any of the following procedures: PUT, PUT_LINE, NEW_LINE or PUTF. All procedures use a file handle of type FILE_TYPE and other various input parameters based on their individual functionality. Before a UTL_FILE write procedure may be used, the output file must be opened with a mode of w or a. NOTE: Release has a bug that can produce a no_data_found exception on the PUT_LINE call. This is fixed in Workaround is to OPEN w/o specifying length, CLOSE, then reopen with the length. Visit and search on no_data_found utl_file.put_line for a complete description. V2.1

24 File I/O Using UTL_FILE Writing Files - PUT PUT Outputs a text string to the specified file pointed to by the file handle without a newline character at the end of the string UTL_FILE.PUT (file handle, buffer); The PUT procedure takes two arguments as input, a file handle of type FILE_TYPE and a buffer variable of type VARCHAR2. The PUT procedure outputs a text string to the specified file pointed to by the file handle. The PUT procedure has no return values. Supplemental Notes The maximum length of an output line that can be written by the UTL_FILE procedure PUT is 32K. The PUT command will not add a newline character to the end of the string. Exceptions UTL_FILE.INVALID_FILEHANDLE UTL_FILE.INVALID_OPERATION UTL_FILE.WRITE_ERROR UTL_FILE.INTERNAL_ERROR File handle does not point to an open file File not properly opened for reading Oracle error during write Oracle internal error V2.1

25 File I/O Using UTL_FILE Writing Files - PUT_LINE PUT_LINE Outputs a text string to the specified file pointed to by the file handle with a newline character at the end of the string UTL_FILE.PUT_LINE (file handle, buffer); The PUT_LINE procedure takes two arguments as input, a file handle of type FILE_TYPE and a buffer variable of type VARCHAR2. The PUT_LINE procedure outputs a text string to the specified file pointed to by the file handle. The PUT_LINE procedure has no return values. Notes The maximum length of an output line that can be written by the UTL_FILE procedure PUT_LINE is 32K. The PUT command will add a newline character to the end of the string. Exceptions UTL_FILE.INVALID_FILEHANDLE UTL_FILE.INVALID_OPERATION UTL_FILE.WRITE_ERROR UTL_FILE.INTERNAL_ERROR File handle does not point to an open file File not properly opened for reading Oracle error during write Oracle internal error V2.1

26 File I/O Using UTL_FILE Writing Files - NEW_LINE NEW_LINE Outputs a single newline character to the specified file pointed to by the file handle UTL_FILE.NEW_LINE (file handle, lines:=#); The NEW_LINE procedure takes two arguments as input, a file handle of type FILE_TYPE and a lines variable of type NATURAL. The NEW_LINE procedure outputs a single newline character to the specified file pointed to by the file handle. The default number for the lines variable is one. The NEW_LINE procedure has no return values. Exceptions UTL_FILE.INVALID_FILEHANDLE UTL_FILE.INVALID_OPERATION UTL_FILE.WRITE_ERROR UTL_FILE.INTERNAL_ERROR File handle does not point to an open file File not properly opened for reading Oracle error during write Oracle internal error V2.1

27 File I/O Using UTL_FILE PUTF Writing Files - PUTF Outputs a formatted string UTL_FILE.PUTF (file handle, format, substitution string 1-5); Similar to the FPRINTF function in C PUTF is a put with Formatting. It outputs a formatted string to the file pointed to by the file handle without a newline character at the end of the string and accepts up to 5 substitution strings into the formatted string V2.1

28 File I/O Using UTL_FILE Writing Files Example UTL_FILE.PUT(v_filehandle_output, v_newline) ; UTL_FILE.NEW_LINE(v_filehandle_output) ; UTL_FILE.PUT_LINE(v_filehandle_output, v_newline); UTL_FILE.PUTF(v_filehandle_output,'This %s %s will %s %s a \n \n %s %s %s %s value %s' %s','string','have','single','null');.... In this example, each of the 4 procedures for writing to files is demonstrated. This code would be added immediately following the GET_LINE loop construct in the reading files example to write out the information read from the input file. String arguments are substituted in the format string, in order, for each %s. Additional %s gets <NULL>. /n in the string represents a newline character. If the V_NEWLINE variable contained the string This is your life Charlie Brown, the information written to the output file from the example code would appear as follows: This is your life Charlie Brown This is your life Charlie Brown This string will have a single NULL value <null> <-- PUT & NEW_LINE <-- PUT_LINE <-- PUTF V2.1

29 File I/O Using UTL_FILE UTL_FILE UTL_FILE Workshop Workshop UTL_FILE 1. Create a DIRECTORY if a DIRECTORY is not already created for your classroom environment. 2. Create a PL/SQL program SP_UTLFILE_WRITE 1. Use the UTL_FILE.FOPEN function to create and open a file called INPUT_FILE.TXT in write mode. 2. Test that the file is not already open using the UTL_FILE.IS_OPEN function. 3. Write a few lines of text to the file using the UTL_FILE.PUT_LINE procedure. 4. Use the UTL_FILE.FCLOSE procedure to close the file INPUT_FILE.TXT. 5. Include the exceptions that may be raised by the UTL_FILE.FOPEN and UTL_FILE.FCLOSE procedure. 6. Use the UTL_FILE.FLCLOSE_ALL procedure in the exceptions portion of the program to close any open files in the event an exception is raised. 7. Execute your PL/SQL program. 3. Create a PL/SQL program SP_UTLFILE_READ 1. Use the UTL_FILE.GET_LINE procedure to read the file INPUT_FILE.TXT. 2. Use the DBMS_OUTPUT.PUT_LINE procedure to write the contents read from the file to the SQL*Plus environment (make sure to SET SERVEROUTPUT ON). 3. Include the exceptions that may be raised by the UTL_FILE.GET_LINE procedure. 4. Have a loop statement control the execution of the UTL_FILE.GET_LINE statement. 5. Exit gracefully from the loop statement by capturing the NO_DATA_FOUND exception triggered by the end of file condition. 6. Execute your PL/SQL program. V2.1

30 Using DBMS_JOB 12.1 Lesson 12 Using DBMS_JOB Scheduling Jobs with DBMS_JOB SKILLBUILDERS V2.1

31 Using DBMS_JOB Lesson Objectives Scheduling stored procedures and functions for execution Managing existing job schedules V2.1

32 Using DBMS_JOB What is DBMS_JOB? A way to schedule PL/SQL jobs Use DBMS_JOB to put job on queue Database process CJQ0 periodically scans queue Spawns processes Jnnn to execute jobs when necessary DBMS_JOB is an Oracle supplied package that provides a way to schedule PL/SQL jobs to run in the background at specific times. Job scheduling is controlled by the database process CJQ0 which is responsible for periodically checking the job queue for background jobs that need to be executed. (Look in the V$BGPROCESS data dictionary view to see a list of processes.) Sybase and MS SQL Server have equivalent job scheduling capabilities V2.1

33 Using DBMS_JOB 12.4 Setup Check initialization parameter file JOB_QUEUE_PROCESSES 12.4 SQL> SQL> show show parameter job_queue NAME NAME TYPE TYPE VALUE VALUE job_queue_processes integer 0 SQL> SQL> alter alter system set set job_queue_processes=10 scope=both; System altered. The following INIT.ORA parameter is required for job scheduling: JOB_QUEUE_PROCESSES: A value between 0 and 1000 that indicates the maximum number of Jnnn processes that can be started. The default value is 0. The value must be non-zero for job scheduling to occur. A non-zero value starts the CJQ0 process. ALTER SYSTEM privilege is required to adjust initialization parameters; this will likely require assistance from your DBA. V2.1

34 Using DBMS_JOB 12.5 DBMS_JOB.SUBMIT SUBMIT procedure puts job on the job queue 12.5 SQL> SQL> desc desc dbms_job dbms_job PROCEDURE PROCEDURE SUBMIT SUBMIT Argument Argument Name Name Type Type In/Out In/Out Default? Default? JOB JOB BINARY_INTEGER OUT OUT WHAT WHAT VARCHAR2 VARCHAR2 IN IN NEXT_DATE NEXT_DATE DATE DATE IN IN DEFAULT DEFAULT INTERVAL INTERVAL VARCHAR2 VARCHAR2 IN IN DEFAULT DEFAULT NO_PARSE NO_PARSE BOOLEAN BOOLEAN IN IN DEFAULT DEFAULT INSTANCE INSTANCE BINARY_INTEGER IN IN DEFAULT DEFAULT FORCE FORCE BOOLEAN BOOLEAN IN IN DEFAULT DEFAULT The SUBMIT procedure is used to submit a job to the job queue for later execution. Users require EXECUTE privilege on DBMS_JOB and privilege on the procedure they want to schedule. Parameters job Job number created by the sequence SYS.JOBSEQ. This is an OUT parameter. what The PL/SQL job name; the PL/SQL job name is usually a call to a stored procedure. The job name should be enclosed in single quotes and terminated with a semicolon. next_date The date a job will run next (after the initial SUBMIT and COMMIT). Default is SYSDATE. interval Function to calculate the next job run time. Evaluated before next_date. Every 3 hours: SYSDATE + 3/24, every Sunday at 6am: NEXT_DAY(TRUNC(SYSDATE), SUN ) + 6/24. Default is NULL, meaning it will not be run again. no_parse Determines if a job will be parsed at submit time (FALSE) or at execute time (TRUE). The default is FALSE. instance Specifies which instance can run the job (default is any instance). Refer to the Oracle9i Supplied PL/SQL Packages and Types Reference for a complete description of the parameters. V2.1

35 Using DBMS_JOB 12.6 SUBMIT Example 12.6 SQL> SQL> CREATE CREATE OR OR REPLACE REPLACE PROCEDURE PROCEDURE p_run_insert p_run_insert IS IS 2 BEGIN BEGIN 3 INSERT INSERT INTO INTO run_table run_table VALUES VALUES ('Execution ('Execution at at ' to_char(sysdate, 'dd-mon-yy 'dd-mon-yy hh:mi:ss') hh:mi:ss') ) ; 4 COMMIT COMMIT ; 5 END; END; 6 / Procedure Procedure created. created. SQL> SQL> VARIABLE VARIABLE p_jobno p_jobno number number SQL> SQL> BEGIN BEGIN 2 DBMS_JOB.SUBMIT (:p_jobno,'p_run_insert;', SYSDATE, SYSDATE, 'SYSDATE 'SYSDATE + (10/(24*60*60))'); 3 COMMIT; COMMIT; /* /* must must commit commit after after SUBMIT SUBMIT */ */ 4 END; END; SQL> 5 / SQL> PRINT PRINT p_jobno p_jobno P_JOBNO PL/SQL PL/SQL procedure procedure successfully successfully completed. P_JOBNO completed This example submits the procedure P_RUN_INSERT to run immediately (SYSDATE is passed to the NEXT_DATE parameter) and schedules it to run again every 10 seconds (based on the interval parameter). The P_RUN_INSERT procedure requires this table: SQL> CREATE TABLE run_table (message VARCHAR2(40)); Note that the job parameter is an OUT parameter. This value is generated from the sequence SYS.JOBSEQ. Once a job number is assigned, it never changes. In order to determine the job number assigned you can check the USER_JOBS data dictionary table or you could submit the job using an anonymous PL/SQL block from SQL*Plus as shown above. NOTE: You must issue a COMMIT after DBMS_JOB.SUBMIT, or your job will NOT be processed. Interestingly, you will see the job listed in in USER_JOBS, but it will not be processed until you COMMIT. We can see that the job is running by querying the RUN_TABLE table: SQL> select * from run_table; MESSAGE Execution at 30-jun-04 04:46:38 Execution at 30-jun-04 04:47:19 V2.1

36 Using DBMS_JOB 12.7 Running a Job 12.7 RUN procedure will execute a job immediately Run job on demand Run a broken job Fix a broken job Debug a job SQL> SQL> select job, job, what, what, to_char(last_date, 'mm/dd hh:mi') 2 from from user_jobs; JOB JOB WHAT WHAT TO_CHAR(LAS P_RUN_INSERT; 06/30 06/30 04:57 04:57 SQL> SQL> exec exec dbms_job.run(2) PL/SQL procedure successfully completed. The RUN procedure is used to cause immediate execution of a job on the job queue (use the SUBMIT procedure to put a job on the queue). A call to SUBMIT must precede a call to RUN. When a job is run immediately, it is run using the current process and not by a Jnnn background process. In addition to running a job before its next scheduled run, the RUN procedure can be used to run broken jobs. Question: What is a broken job? Answer: If a job fails it is resubmitted one minute after the first failure. If it fails again, it is resubmitted two minutes later, and if it fails once again, it is resubmitted after four minutes and so on for a total of 16 attempts. After that point, a job is considered broken. You can use RUN to execute the job; if it succeeds it is marked as not broken (see the BROKEN column of USER_JOBS). Parameters job Job number. The job number is created when the job is submitted. As shown above, you can query the USER_JOBS dictionary view to find jobs and job numbers. V2.1

37 Using DBMS_JOB 12.8 Cleaning Up Broken Jobs 12.8 Jobs are broken after 16 failures Will no longer execute BROKEN procedure can set job to not broken SQL> SQL> select job, job, what, what, broken 2 from from user_jobs; JOB JOB WHAT WHAT B GATHER_MY_STATS; Y SQL> SQL> exec exec dbms_job.broken(3,false); PL/SQL procedure successfully completed. Job Job is is broken broken Fix Fix job job If a job fails 16 times, Oracle marks the job as broken. The BROKEN procedure is used to break or, more commonly, to un-break a broken job. Parameters job Job number created at SUBMIT. broken TRUE - job is flagged as broken; FALSE - job is flagged as not broken next_date The date the job will run next (default is SYSDATE) A broken job can also be executed using the RUN procedure. V2.1

38 Using DBMS_JOB 12.9 Removing a Job The REMOVE procedure will remove a job from the queue 12.9 SQL> exec dbms_job.remove(2) PL/SQL procedure successfully completed. You may remove a job from the queue at any time by calling the REMOVE procedure. The REMOVE procedure takes only one parameter, the job number. If a job is currently running when a call to REMOVE is made, it will be removed from the queue after it finishes executing. V2.1

39 Using DBMS_JOB Changing Job Parameters CHANGE DBMS_JOB.CHANGE(job,what,next_date,interval,instance,force); WHAT DBMS_JOB.WHAT(job,what); NEXT_DATE DBMS_JOB.NEXT_DATE(job,next_date); INTERVAL DBMS_JOB.INTERVAL(job,interval); INSTANCE DBMS_JOB.INSTANCE(job,instance); The parameters for a job can be changed after the job has been submitted using the procedures CHANGE, WHAT, NEXT_DATE, INSTANCE and INTERVAL. The CHANGE procedure changes more than one job parameter at once while the other procedures change only the specific characteristic. All the parameters behave the same as they do in the SUBMIT procedure. Refer to the Oracle9i Supplied PL/SQL Packages and Types Reference for a complete description of the procedures. V2.1

40 Using DBMS_JOB Viewing Job Information DBA_JOBS and USER_JOBS Information about queued jobs DBA_JOBS_RUNNING Information about currently running jobs Information about currently executing jobs and the success or failure of previously submitted jobs is available in the data dictionary. USER_JOBS provide information about a job such as job number, last run date and next run date. DBA_JOBS_RUNNING provides information about jobs that are currently running. There is no ALL nor USER version of this view. V2.1

41 Using DBMS_JOB Using DBMS_JOB Workshop DBMS_JOB Workshop DBMS_JOB 1. Verify that the JOB_QUEUE_PROCESSES parameter is not zero: SHOW PARAMETER JOB_QUEUE_PROCESSES If it is zero, modify it from a DBA account as follows: ALTER SYSTEM SET JOB_QUEUE_PROCESSES = 5; 2. Schedule a 3 AM nightly job to gather statistics on all the objects in your schema. 1. First, execute the supplied script DBMS_JOB_WORKSHOP_SETUP.SQL to create the required test table and procedure. 2. Next, submit a job to the queue to execute immediately and then again every night at 3 AM. 3. Verify that the job ran. Note that it may take a little time before the job completes. V2.1

42 Profile and Tune 13.1 Lesson 13 Profile and Tune Profile and tune PL/SQL with DBMS_PROFILER. SKILLBUILDERS V2.1

43 Profile and Tune Lesson Objectives What can be tuned? Using DBMS_PROFILER V2.1

44 Profile and Tune Introduction to Tuning PL/SQL Biggest gains often from tuning embedded SQL TKPROF, EXPLAIN, AUTOTRACE V$SQL_PLAN, V$SQL_PLAN_STATISTICS Use DBMS_PROFILER for PL/SQL code Find problem areas Test different techniques to find fastest SQL Tuning Course This lesson V2.1

45 Profile and Tune DBMS_PROFILER Collect and store performance data for PL/SQL programs Data stored in tables PLSQL_PROFILER_RUNS PLSQL_PROFILER_UNITS PLSQL_PROFILER_DATA DBMS_PROFILER collects and saves performance data for PL/SQL programs. The data is stored in tables. V2.1

46 Profile and Tune Profiler Setup If DBMS_PROFILER not available Run PROFLOAD.SQL as SYSDBA Run PROFTAB.SQL under your username Creates tables Run PROFREP.SQL under your username Creates views & packages for reporting If DBMS_PROFILER is not available, the following script will need to be run: $ORACLE_HOME/rdbms/admin/profload.sql (must be logged in as SYSDBA). DESCRIBE DBMS_PROFILER to determine if it is available. Next, run the following script to create tables to hold the performance data: ORACLE_HOME/rdbms/admin/proftab.sql (logged in as your USER id). This script ( ) is supplied with the course. The username requires the following privileges: create sequence create view create procedure Next, run the $ORACLE_HOME/plsql/demo/profrep.sql script to create some views and packages needed for reporting. This script ( ) is also supplied with the course. V2.1

47 Profile and Tune 13.6 Using Profiler Start profiler with DBMS_PROFILER.START_PROFILER Consider a LOGON trigger Run your code Stop profiler DBMS_PROFILER.STOP_PROFILER Run PROFSUM.SQL script to create report Use version supplied with this course Optionally run PROFRESET.SQL to clear data 13.6 The use of this package is very simple. You start the profiler, run your code and stop the profiler. The PL/SQL engine will have populated the 3 profiler tables with the performance and code coverage information. Then run the Oracle script PROFSUM.SQL to create a report. There are 3 basic subprograms within the DBMS_PROFILER package. The START_PROFILER function starts profiling in the current session. You can provide an optional string to give a name to the profiling session if you do not want to use only the default, SYSDATE. Starting the profiler can be done in a LOGON trigger or directly in the application code. The STOP_PROFILER function ends profiling in the current session. This function also implicitly flushes the data into the profiler tables. The profiler data is collected in memory data structures until it is flushed or written to the profiler tables. STOP_PROFILER does an implicit FLUSH_DATA when it is executed. The FLUSH_DATA function allows profiler data collected in memory to be flushed or written to the profiler tables. You may want to call FLUSH_DATA at intermediate points within your application during the profiling session to write the collected data into the profiler tables and free the memory used to collect profile data. V2.1

48 Profile and Tune 13.7 Testing 13.7 SQL> SQL> create or or replace procedure modtest 2 as as 3 begin begin 4 dbms_profiler.start_profiler('mod'); 5 for for x in in loop loop 6 if if mod(x,100) = 0 then then null; null; end end if; if; 7 end end loop; loop; 8 dbms_profiler.stop_profiler; 9 end; end; / SQL> SQL> exec exec modtest Procedure created. PL/SQL procedure successfully completed. SQL> SQL> exec exec countertest PL/SQL procedure successfully completed. The profiler is good for comparing the performance of similar routines. In this example I am comparing the performance of the MOD function to a manual counter as shown in this routine: SQL> create or replace procedure countertest 2 as 3 counter number := 0; 4 begin 5 dbms_profiler.start_profiler('counter'); 6 for x in loop 7 counter := counter + 1; 8 if counter = 100 then counter := 0; end if; 9 end loop; 10 dbms_profiler.stop_profiler; 11 end; 12 / Procedure created. Execute the supplied script PROFILER.SQL to test this on your system. V2.1

49 Profile and Tune 13.8 Reporting 13.8 SQL> Total Total time time spent spent on on each each run Counter run was was MOD MOD faster faster than than function took took RUNID RUNID RUN_COMMENT RUN_COMMENT SECS SECS MOD MOD most most of of the the mod mod 1.77 time 1.77 time counter counter Lines Lines taking taking more more than than 1% 1% of of the the total total time, time, each each run run separate separate RUNID RUNID HSECS HSECS PCT PCT OWNER OWNER UNIT_NAME UNIT_NAME LINE# LINE# TEXT TEXT DAVE DAVE MODTEST MODTEST 6 if if mod(x,100)=0 mod(x,100)=0 then then null; null; end end if; if; DAVE DAVE COUNTERTEST COUNTERTEST 6 for for x in in loop loop Here is an excerpt of the report created by the PROFSUM.SQL script (this script is provided by Oracle; a copy is included in your class scripts). We can see that the MOD function was the main reason that the MODTEST routine was slower than the COUNTER routine. Bug Report The timings reported on an Intel/Windows server are not always accurate. Oracle Corp claims this is an Intel bug: This is a vendor/os problem rather than an oracle problem because the RDTSC instruction is reporting wrong time stamp counter. Found in some INTEL Pentium processor Errata that there is indeed such as problem and no plans to fix that. Also the problem only exists on Windows as this is port specific bug. Metalink Bug V2.1

50 Profile and Tune 13.9 Profile & Tune PLSQL Workshop Using DBMS_PROFILER 13.9 Workshop Using DBMS_PROFILER If your database is running on an Intel Windows platform, it is likely that the timings reported by the Profiler will be incorrect. As Oracle claims this is an Intel bug, there s not much we can do about this. 1. Profile the two different routines supplied in the script WORKSHOP_PROFILER_SETUP.SQL. One routine use row-at-a-time processing; the other routine uses bulk processing to accomplish the same task. 2. Which routine is faster? V2.1

51 Dynamic SQL A.1 A. Dynamic SQL What is dynamic SQL? Execute DDL, DML and Anonymous PL/SQL Blocks dynamically Constructs needed to perform dynamic SQL Benefits of dynamic SQL Contrast NDS with DBMS_SQL SKILLBUILDERS V2.1

52 Dynamic SQL A.2 A.2 What is Dynamic SQL? Allows SQL statements that are not known at compile time to be parsed at run time Dynamic SQL can process: DML: INSERT, UPDATE, DELETE, SELECT DDL: CREATE, ALTER, DROP DCL: GRANT, REVOKE PL/SQL: Anonymous blocks, calls to other PL/SQL programs from within an anonymous block What is Dynamic SQL? Dynamic SQL is, as its name implies, dynamic as compared to normal in-line SQL statements. A static SQL statement knows, at compile time, exactly which table and columns within the table are used/effected as well as what the WHERE clause specifies. Dynamic SQL allows many of the things that need to be known at compile time to be postponed until runtime. Dynamic SQL also provides a work around for the PL/SQL restriction disallowing DDL in PL/SQL blocks. With Dynamic SQL, not only can DML be executed, but so can DDL and DCL statements as well as PL/SQL anonymous blocks. Dynamic SQL can be implemented using the DBMS_SQL package or through the use of Native Dynamic SQL. Prior to Oracle8i, dynamic SQL was implemented through the DBMS_SQL package. But there were some problems with DBMS_SQL: it is a very complicated package, it has a number of restrictions and it is relatively slow. So, with Oracle8i, dynamic SQL was re-implemented directly in the PL/SQL language itself and was called Native Dynamic SQL, or NDS. In general, NDS is faster and is easier to build, read and maintain. Sybase supports the EXECUTE IMMEDIATE syntax similar to Oracle s Native Dynamic SQL (NDS) support. MS SQL Server uses the equivalent syntax EXEC sp_executesql 'sql Statement' V2.1

53 Dynamic SQL A.3 A.3 NDS vs. DBMS_SQL Exclusive NDS capabilities: Works with all datatypes (objects, collections, etc) Allows fetching of multiple columns directly into a PL/SQL record Exclusive DBMS_SQL capabilities: Allows you to use DESCRIBE Supports SQL statements > 32KB in length Supports the use of the RETURNING clause into an array of values Allows you to reuse your dynamic SQL cursors DBMS_SQL vs. NDS Given the fact that NDS executes faster and is easier to build, read and maintain, why would anyone ever use DBMS_SQL again? Well, NDS may not do everything you want it to do and DBMS_SQL is your only choice in pre-8i environments. There are some capabilities only available to you with DBMS_SQL and some capabilities only available with NDS as shown here. Exclusive NDS Capabilities NDS works with all datatypes whereas DBMS_SQL only works with Oracle7-compatible datatypes. NDS allows fetching of multiple columns directly into a PL/SQL record. With DBMS_SQL, you must fetch into individual variables. Exclusive DBMS_SQL Capabilities DBMS_SQL allows you to describe the columns of your dynamic cursor, obtaining column information in an index-by table of records. DBMS_SQL supports large SQL statements whereas NDS is constrained to a 32KB limit.... continued.... V2.1

54 Dynamic SQL A.4 Exclusive DBMS_SQL Capabilities (continued) DBMS_SQL supports the use of the RETURNING clause into an array of values. NDS only allows the use of RETURNING for a single statement. DBMS_SQL allows you to reuse your dynamic SQL cursors, which can improve performance. DBMS_SQL can be executed from client-side (Oracle Developer) applications whereas NDS cannot. From these lists, we can conclude that NDS implementation should be able to handle the majority of the dynamic SQL requirements you are likely to encounter. But, in those instances when NDS just does not do it all, DBMS_SQL is still a viable alternative. V2.1

55 Dynamic SQL A.5 A.5 NDS Statement Summary EXECUTE IMMEDIATE Executes a specified SQL statement immediately OPEN FOR Allows you to perform multi-row dynamic queries NDS Statement Summary One of the selling points for NDS is its simplicity. Unlike DBMS_SQL, which has dozens of programs and lots of rules to follow, NDS has been integrated into the PL/SQL language by adding one new statement, EXECUTE IMMEDIATE, and by enhancing the existing OPEN FOR statement. V2.1

56 Dynamic SQL A.6 NDS Single-Row Query Syntax A.6 EXECUTE IMMEDIATE statement-string [INTO {define-variable [, [, define_variable] record}] [USING [IN [IN OUT OUT IN IN OUT] bind-argument [,[IN OUT OUT IN IN OUT] bind-argument]...]; NDS Single-Row Query Syntax (EXECUTE IMMEDIATE) statement-string = string expression that represents a SQL statement (without the terminator) or PL/SQL block (with the terminator) INTO (used only for single-row queries) specifies the variables or record into which column values are retrieved define-variable = variable that stores a selected column value record = a user-defined or %ROWTYPE record that stores a selected row USING specifies all bind arguments; default parameter mode is IN but can specify all modes. At run time, any bind arguments in the USING clause replace corresponding placeholders in the SQL statement or PL/SQL block. So, every placeholder must be associated with a bind argument in the USING clause. bind_argument = an expression whose value is passed to or returned by the dynamic SQL statement or PL/SQL block V2.1

57 Dynamic SQL A.7 NDS Single-Row INSERT Example A.7 CREATE OR OR REPLACE PROCEDURE insert_into_dept (dept_no number, dept_name varchar2, loc loc varchar2) IS IS stmt_str varchar2(200); BEGIN stmt_str := := 'INSERT INTO dept VALUES (:1,:2,:3)'; EXECUTE IMMEDIATE stmt_str USING IN IN dept_no, IN IN dept_name, IN IN loc; END; NDS Single-Row Query Example The example shows how the EXECUTE IMMEDIATE statement can perform dynamic single-row queries. You specify bind variables in the USING clause (dept_no, dept_name and loc) which map to the placeholders (:1, :2, :3) listed in the statement STRING (STMT_STR). Note that the placeholders are positional and the names do not have to match the bind variables in the USING clause. As a matter of fact, the substitution variables can be named anything you want and can even have duplicate names. V2.1

58 Dynamic SQL A.8 NDS Multi-Row Query Syntax A.8 OPEN {cursor_variable :host_cursor_variable} FOR FOR stmnt-string [USING bind-argument[, bind-argument]...] ; FETCH {cursor_variable :host_cursor_variable} INTO {define_variable[, define_variable]... record} ; CLOSE {cursor_variable :host_cursor_variable}; NDS Multi-Row Query Syntax OPEN-FOR cursor_variable = a cursor variable without a return type host_cursor_variable = a cursor variable declared in a PL/SQL host environment stmnt-string = string expression that represents a multi-row query FETCH cursor_variable = a cursor variable without a return type host_cursor_variable = a cursor variable declared in a PL/SQL host environment define-variable = variable that stores a selected column value record = a user-defined or %ROWTYPE record that stores a selected row CLOSE cursor_variable = a cursor variable without a return type host_cursor_variable = a cursor variable declared in a PL/SQL host environment V2.1

59 Dynamic SQL A.9 NDS Multi-Row Query Example A.9 DECLARE TYPE TYPE DeptCurTyp IS IS REF REF CURSOR ; dept_cv DeptCurTyp ; dept_rec dept%rowtype ; stmt_str varchar2(200); v_dept_no dept.dept_no%type ; BEGIN BEGIN v_dept_no := := 1; 1; stmt_str := := 'SELECT * FROM FROM dept dept WHERE WHERE dept_no = :1'; :1'; OPEN OPEN dept_cv FOR FOR stmt_str USING USING v_dept_no ; LOOP LOOP FETCH FETCH dept_cv INTO INTO dept_rec ; EXIT EXIT WHEN WHEN dept_cv%notfound; further processing END END LOOP; LOOP; CLOSE CLOSE dept_cv; END; END; NDS Multi-Row Query Example To perform a multi-row query, you take the following steps: Declare a REF CURSOR type Declare a cursor variable based on the REF CURSOR OPEN the cursor variable FOR your query string Use the FETCH statement to fetch one row at a time from your query Check cursor attributes (%NOTFOUND, %ROWCOUNT, etc) as necessary Close the cursor variable using the normal CLOSE statement REF CURSOR REF (short for REFERENCE) CURSOR is used in the TYPE declaration to create a user-defined type which is simply a pointer to a memory location. This type is then used to create a cursor variable which is used in the OPEN FOR statement. Basically, the REF allows you to create a memory location into which the dynamic SQL statement will be retrieved and manipulated at run-time. V2.1

60 Dynamic SQL A.10 NDS PL/SQL Example CREATE OR OR REPLACE PROCEDURE p_nds_plsql (p_database IN IN info.database_name%type) IS IS v_sql_stmt VARCHAR2(256); v_instance info.instance_name%type; BEGIN BEGIN v_sql_stmt := := 'BEGIN ' 'SELECT instance_name ' 'INTO 'INTO :sid_name ' 'FROM 'FROM info info ' 'WHERE database_name = :db_name; ' 'END; 'END; ' ; EXECUTE IMMEDIATE v_sql_stmt USING USING OUT OUT v_instance, IN IN p_database ; DBMS_OUTPUT.PUT_LINE( Instance: v_instance) ; END END ; A.10 NDS PL/SQL Example To execute an anonymous PL/SQL block, you take the following steps: Declare OUT variables, if any Create a string containing the PL/SQL block Make sure to include a semicolon (;) within the string to terminate the block EXECUTE the string V2.1

Oracle Database: Program with PL/SQL

Oracle Database: Program with PL/SQL Oracle Database: Program with PL/SQL Duration: 5 Days What you will learn This Oracle Database: Program with PL/SQL training starts with an introduction to PL/SQL and then explores the benefits of this

More information

Database Programming with PL/SQL: Learning Objectives

Database Programming with PL/SQL: Learning Objectives Database Programming with PL/SQL: Learning Objectives This course covers PL/SQL, a procedural language extension to SQL. Through an innovative project-based approach, students learn procedural logic constructs

More information

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals Oracle University Contact Us: 1.800.529.0165 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This course is designed to deliver the fundamentals of SQL and PL/SQL along

More information

Duration Vendor Audience 5 Days Oracle Developers, Technical Consultants, Database Administrators and System Analysts

Duration Vendor Audience 5 Days Oracle Developers, Technical Consultants, Database Administrators and System Analysts D80186GC10 Oracle Database: Program with Summary Duration Vendor Audience 5 Days Oracle Developers, Technical Consultants, Database Administrators and System Analysts Level Professional Technology Oracle

More information

Oracle For Beginners Page : 1

Oracle For Beginners Page : 1 Oracle For Beginners Page : 1 Chapter 24 NATIVE DYNAMIC SQL What is dynamic SQL? Why do we need dynamic SQL? An Example of Dynamic SQL Execute Immediate Statement Using Placeholders Execute a Query Dynamically

More information

Handling Exceptions. Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 8-1

Handling Exceptions. Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 8-1 Handling Exceptions Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 8-1 Objectives After completing this lesson, you should be able to do the following: Define PL/SQL

More information

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals NEW Oracle University Contact Us: + 38516306373 Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training delivers the

More information

Oracle Database 10g: Program with PL/SQL

Oracle Database 10g: Program with PL/SQL Oracle University Contact Us: Local: 1800 425 8877 Intl: +91 80 4108 4700 Oracle Database 10g: Program with PL/SQL Duration: 5 Days What you will learn This course introduces students to PL/SQL and helps

More information

ORACLE 9I / 10G / 11G / PL/SQL COURSE CONTENT

ORACLE 9I / 10G / 11G / PL/SQL COURSE CONTENT ORACLE 9I / 10G / 11G / PL/SQL COURSE CONTENT INTRODUCTION: Course Objectives I-2 About PL/SQL I-3 PL/SQL Environment I-4 Benefits of PL/SQL I-5 Benefits of Subprograms I-10 Invoking Stored Procedures

More information

Oracle Database: Program with PL/SQL

Oracle Database: Program with PL/SQL Oracle University Contact Us: +33 15 7602 081 Oracle Database: Program with PL/SQL Duration: 5 Days What you will learn This course is available in Training On Demand format This Oracle Database: Program

More information

Oracle Database: Program with PL/SQL

Oracle Database: Program with PL/SQL Oracle University Contact Us: 1.800.529.0165 Oracle Database: Program with PL/SQL Duration: 5 Days What you will learn View a newer version of this course /a/b/p/p/b/pulli/lili/lili/lili/lili/lili/lili/lili/lili/lili/lili/lili/li/ul/b/p/p/b/p/a/a/p/

More information

Oracle Database: Program with PL/SQL

Oracle Database: Program with PL/SQL Oracle University Contact Us: +52 1 55 8525 3225 Oracle Database: Program with PL/SQL Duration: 5 Days What you will learn View a newer version of this course This Oracle Database: Program with PL/SQL

More information

Handling Exceptions. Schedule: Timing Topic 45 minutes Lecture 20 minutes Practice 65 minutes Total

Handling Exceptions. Schedule: Timing Topic 45 minutes Lecture 20 minutes Practice 65 minutes Total Handling Exceptions Schedule: Timing Topic 45 minutes Lecture 20 minutes Practice 65 minutes Total Objectives After completing this lesson, you should be able to do the following: Define PL/SQL exceptions

More information

Oracle Database: Develop PL/SQL Program Units

Oracle Database: Develop PL/SQL Program Units Oracle University Contact Us: 1.800.529.0165 Oracle Database: Develop PL/SQL Program Units Duration: 3 Days What you will learn This Oracle Database: Develop PL/SQL Program Units course is designed for

More information

Oracle Database: Program with PL/SQL

Oracle Database: Program with PL/SQL Oracle University Contact Us: 0845 777 7711 Oracle Database: Program with PL/SQL Duration: 5 Days What you will learn This course starts with an introduction to PL/SQL and proceeds to list the benefits

More information

Handling Exceptions. Schedule: Timing Topic. 45 minutes Lecture 20 minutes Practice 65 minutes Total

Handling Exceptions. Schedule: Timing Topic. 45 minutes Lecture 20 minutes Practice 65 minutes Total 23 Handling Exceptions Copyright Oracle Corporation, 1999. All rights reserved. Schedule: Timing Topic 45 minutes Lecture 20 minutes Practice 65 minutes Total Objectives After completing this lesson, you

More information

Topics Advanced PL/SQL, Integration with PROIV SuperLayer and use within Glovia

Topics Advanced PL/SQL, Integration with PROIV SuperLayer and use within Glovia Topics Advanced PL/SQL, Integration with PROIV SuperLayer and use within Glovia 1. SQL Review Single Row Functions Character Functions Date Functions Numeric Function Conversion Functions General Functions

More information

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals Oracle University Contact Us: +966 12 739 894 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training is designed to

More information

Oracle Database 11g: Program with PL/SQL

Oracle Database 11g: Program with PL/SQL Oracle University Entre em contato: 0800 891 6502 Oracle Database 11g: Program with PL/SQL Duração: 5 Dias Objetivos do Curso This course introduces students to PL/SQL and helps them understand the benefits

More information

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. est: Final Exam Semester 1 Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 6 1. How can you retrieve the error code and error message of any

More information

Oracle 11g PL/SQL training

Oracle 11g PL/SQL training Oracle 11g PL/SQL training Course Highlights This course introduces students to PL/SQL and helps them understand the benefits of this powerful programming language. Students learn to create PL/SQL blocks

More information

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Test: Final Exam Semester 1 Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 6 1. The following code does not violate any constraints and will

More information

Oracle(PL/SQL) Training

Oracle(PL/SQL) Training Oracle(PL/SQL) Training 30 Days Course Description: This course is designed for people who have worked with other relational databases and have knowledge of SQL, another course, called Introduction to

More information

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff D80198GC10 Oracle Database 12c SQL and Fundamentals Summary Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff Level Professional Delivery Method Instructor-led

More information

Oracle 10g PL/SQL Training

Oracle 10g PL/SQL Training Oracle 10g PL/SQL Training Course Number: ORCL PS01 Length: 3 Day(s) Certification Exam This course will help you prepare for the following exams: 1Z0 042 1Z0 043 Course Overview PL/SQL is Oracle's Procedural

More information

Creating PL/SQL Blocks. Copyright 2007, Oracle. All rights reserved.

Creating PL/SQL Blocks. Copyright 2007, Oracle. All rights reserved. What Will I Learn? In this lesson, you will learn to: Describe the structure of a PL/SQL block Identify the different types of PL/SQL blocks Identify PL/SQL programming environments Create and execute

More information

Introduction to PL/SQL Programming

Introduction to PL/SQL Programming Introduction to PL/SQL Programming Introduction to PL/SQL Programming i-ii Introduction to PL/SQL Programming 1997-2001 Technology Framers, LLC Introduction to PL/SQL Programming This publication is protected

More information

Course -Oracle 10g SQL (Exam Code IZ0-047) Session number Module Topics 1 Retrieving Data Using the SQL SELECT Statement

Course -Oracle 10g SQL (Exam Code IZ0-047) Session number Module Topics 1 Retrieving Data Using the SQL SELECT Statement Course -Oracle 10g SQL (Exam Code IZ0-047) Session number Module Topics 1 Retrieving Data Using the SQL SELECT Statement List the capabilities of SQL SELECT statements Execute a basic SELECT statement

More information

Handling Exceptions. Copyright 2008, Oracle. All rights reserved.

Handling Exceptions. Copyright 2008, Oracle. All rights reserved. Handling Exceptions Handling Exceptions What Will I Learn? In this lesson, you will learn to: Describe several advantages of including exception handling code in PL/SQL Describe the purpose of an EXCEPTION

More information

PL/SQL Overview. Basic Structure and Syntax of PL/SQL

PL/SQL Overview. Basic Structure and Syntax of PL/SQL PL/SQL Overview PL/SQL is Procedural Language extension to SQL. It is loosely based on Ada (a variant of Pascal developed for the US Dept of Defense). PL/SQL was first released in ١٩٩٢ as an optional extension

More information

Oracle10g PL/SQL Programming V1.0

Oracle10g PL/SQL Programming V1.0 Oracle10g PL/SQL Programming V1.0 Oracle10g PL/SQL Programming SkillBuilders, Inc. 24 Salt Pond Road, Unit C-4 South Kingstown, RI 02880 www.skillbuilders.com knowledge@skillbuilders.com Author: David

More information

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals NEW Oracle University Contact Us: 001-855-844-3881 & 001-800-514-06-97 Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals

More information

Training Guide. PL/SQL for Beginners. Workbook

Training Guide. PL/SQL for Beginners. Workbook An Training Guide PL/SQL for Beginners Workbook Workbook This workbook should be worked through with the associated Training Guide, PL/SQL for Beginners. Each section of the workbook corresponds to a section

More information

Oracle Database 12c: Introduction to SQL Ed 1.1

Oracle Database 12c: Introduction to SQL Ed 1.1 Oracle University Contact Us: 1.800.529.0165 Oracle Database 12c: Introduction to SQL Ed 1.1 Duration: 5 Days What you will learn This Oracle Database: Introduction to SQL training helps you write subqueries,

More information

Oracle For Beginners Page : 1

Oracle For Beginners Page : 1 Oracle For Beginners Page : 1 Chapter 17 EXCEPTION HANDLING What is an? How to handle s? Predefined s When NO_DATA_FOUND is not raised? User-defined Reraising an Associating an With An Oracle Error Exception

More information

Oracle Database 10g: Introduction to SQL

Oracle Database 10g: Introduction to SQL Oracle University Contact Us: 1.800.529.0165 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database technology.

More information

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC MyOra 3.0 SQL Tool for Oracle User Guide Jayam Systems, LLC Contents Features... 4 Connecting to the Database... 5 Login... 5 Login History... 6 Connection Indicator... 6 Closing the Connection... 7 SQL

More information

Oracle SQL. Course Summary. Duration. Objectives

Oracle SQL. Course Summary. Duration. Objectives Oracle SQL Course Summary Identify the major structural components of the Oracle Database 11g Create reports of aggregated data Write SELECT statements that include queries Retrieve row and column data

More information

MyOra 3.5. User Guide. SQL Tool for Oracle. Kris Murthy

MyOra 3.5. User Guide. SQL Tool for Oracle. Kris Murthy MyOra 3.5 SQL Tool for Oracle User Guide Kris Murthy Contents Features... 4 Connecting to the Database... 5 Login... 5 Login History... 6 Connection Indicator... 6 Closing the Connection... 7 SQL Editor...

More information

When an exception occur a message which explains its cause is received. PL/SQL Exception message consists of three parts.

When an exception occur a message which explains its cause is received. PL/SQL Exception message consists of three parts. ERROR HANDLING IN PLSQL When an SQL statement fails, the Oracle engine recognizes this as an Exception Condition. What is Exception Handling? PLSQL provides a feature to handle the Exceptions which occur

More information

Monitoring Audit Trails Using Enterprise Manager

Monitoring Audit Trails Using Enterprise Manager Enhancing Database Security: Monitoring Audit Trails Using Enterprise Manager Peter J. Magee, CDA SQRIBE Technologies Gail VanderKolk Reynolds & Reynolds Abstract Maintaining the security and integrity

More information

Oracle9i: Develop PL/SQL Program Units

Oracle9i: Develop PL/SQL Program Units Oracle9i: Develop PL/SQL Program Units Student Guide Volume 2 40056GC10 Production 1.0 July 2001 D33491 Author Nagavalli Pataballa Technical Contributors and Reviewers Anna Atkinson Bryan Roberts Caroline

More information

Best Practices for Dynamic SQL

Best Practices for Dynamic SQL The PL/SQL Channel Writing Dynamic SQL in Oracle PL/SQL Best Practices for Dynamic SQL Steven Feuerstein steven@stevenfeuerstein.com www.stevenfeuerstein.com www.plsqlchallenge.com Quick Reminders Download

More information

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to: D61830GC30 for Developers Summary Duration Vendor Audience 5 Days Oracle Database Administrators, Developers, Web Administrators Level Technology Professional Oracle 5.6 Delivery Method Instructor-led

More information

Oracle PL/SQL Programming

Oracle PL/SQL Programming FOURTH EDITION Oracle PL/SQL Programming Steven Feuerstein with Bill Pribvl O'REILLY' Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo Table of Contents Preface xiii Part 1. Programming in

More information

SQL Programming. CS145 Lecture Notes #10. Motivation. Oracle PL/SQL. Basics. Example schema:

SQL Programming. CS145 Lecture Notes #10. Motivation. Oracle PL/SQL. Basics. Example schema: CS145 Lecture Notes #10 SQL Programming Example schema: CREATE TABLE Student (SID INTEGER PRIMARY KEY, name CHAR(30), age INTEGER, GPA FLOAT); CREATE TABLE Take (SID INTEGER, CID CHAR(10), PRIMARY KEY(SID,

More information

Advanced SQL Injection in Oracle databases. Esteban Martínez Fayó

Advanced SQL Injection in Oracle databases. Esteban Martínez Fayó Advanced SQL Injection in Oracle databases Esteban Martínez Fayó February 2005 Outline Introduction SQL Injection attacks How to exploit Exploit examples SQL Injection in functions defined with AUTHID

More information

Oracle PL/SQL Best Practices

Oracle PL/SQL Best Practices Achieving PL/SQL Excellence Oracle PL/SQL Best Practices Steven Feuerstein Me - www.stevenfeuerstein.com PL/Solutions - www.plsolutions.com RevealNet - www.revealnet.com 7/5/99 Copyright 1999 Steven Feuerstein

More information

1 Stored Procedures in PL/SQL 2 PL/SQL. 2.1 Variables. 2.2 PL/SQL Program Blocks

1 Stored Procedures in PL/SQL 2 PL/SQL. 2.1 Variables. 2.2 PL/SQL Program Blocks 1 Stored Procedures in PL/SQL Many modern databases support a more procedural approach to databases they allow you to write procedural code to work with data. Usually, it takes the form of SQL interweaved

More information

Darshan Institute of Engineering & Technology PL_SQL

Darshan Institute of Engineering & Technology PL_SQL Explain the advantages of PL/SQL. Advantages of PL/SQL Block structure: PL/SQL consist of block of code, which can be nested within each other. Each block forms a unit of a task or a logical module. PL/SQL

More information

PL/SQL (Cont d) Let s start with the mail_order database, shown here:

PL/SQL (Cont d) Let s start with the mail_order database, shown here: PL/SQL (Cont d) Let s start with the mail_order database, shown here: 1 Table schemas for the Mail Order database: 2 The values inserted into zipcodes table: The values inserted into employees table: 3

More information

Oracle Database 11g Express Edition PL/SQL and Database Administration Concepts -II

Oracle Database 11g Express Edition PL/SQL and Database Administration Concepts -II Oracle Database 11g Express Edition PL/SQL and Database Administration Concepts -II Slide 1: Hello and welcome back to the second part of this online, self-paced course titled Oracle Database 11g Express

More information

Fine Grained Auditing In Oracle 10G

Fine Grained Auditing In Oracle 10G Fine Grained Auditing In Oracle 10G Authored by: Meenakshi Srivastava (meenaxi.srivastava@gmail.com) 2 Abstract The purpose of this document is to develop an understanding of Fine Grained Auditing(FGA)

More information

Oracle Internal & Oracle Academy

Oracle Internal & Oracle Academy Declaring PL/SQL Variables Objectives After completing this lesson, you should be able to do the following: Identify valid and invalid identifiers List the uses of variables Declare and initialize variables

More information

Best Practices for Oracle Databases Hardening Oracle 10.2.0.3 / 10.2.0.4

Best Practices for Oracle Databases Hardening Oracle 10.2.0.3 / 10.2.0.4 Best Practices for Oracle Databases Hardening Oracle 10.2.0.3 / 10.2.0.4 Alexander Kornbrust Table of Content Passwords (Security) Patches Database Settings PUBLIC Privileges Database Trigger Compiling

More information

Basic Unix/Linux 1. Software Testing Interview Prep

Basic Unix/Linux 1. Software Testing Interview Prep Basic Unix/Linux 1 Programming Fundamentals and Concepts 2 1. What is the difference between web application and client server application? Client server application is designed typically to work in a

More information

Instant SQL Programming

Instant SQL Programming Instant SQL Programming Joe Celko Wrox Press Ltd. INSTANT Table of Contents Introduction 1 What Can SQL Do for Me? 2 Who Should Use This Book? 2 How To Use This Book 3 What You Should Know 3 Conventions

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: +381 11 2016811 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn Understanding the basic concepts of relational databases ensure refined code by developers.

More information

Developing SQL and PL/SQL with JDeveloper

Developing SQL and PL/SQL with JDeveloper Seite 1 von 23 Developing SQL and PL/SQL with JDeveloper Oracle JDeveloper 10g Preview Technologies used: SQL, PL/SQL An Oracle JDeveloper Tutorial September 2003 Content This tutorial walks through the

More information

SQL/PSM. Outline. Database Application Development Oracle PL/SQL. Why Stored Procedures? Stored Procedures PL/SQL. Embedded SQL Dynamic SQL

SQL/PSM. Outline. Database Application Development Oracle PL/SQL. Why Stored Procedures? Stored Procedures PL/SQL. Embedded SQL Dynamic SQL Outline Embedded SQL Dynamic SQL Many host languages: C, Cobol, Pascal, etc. JDBC (API) SQLJ (Embedded) Java Database Application Development Oracle PL/SQL Stored procedures CS430/630 Lecture 15 Slides

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: 1.800.529.0165 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn View a newer version of this course This Oracle Database: Introduction to SQL training

More information

Writing Control Structures

Writing Control Structures Writing Control Structures Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 5-1 Objectives After completing this lesson, you should be able to do the following: Identify

More information

ORACLE DATABASE 11G: COMPLETE

ORACLE DATABASE 11G: COMPLETE ORACLE DATABASE 11G: COMPLETE 1. ORACLE DATABASE 11G: SQL FUNDAMENTALS I - SELF-STUDY COURSE a) Using SQL to Query Your Database Using SQL in Oracle Database 11g Retrieving, Restricting and Sorting Data

More information

Answers to the Try It Yourself Sections

Answers to the Try It Yourself Sections APPENDIX D Answers to the Try It Yourself Sections Chapter 1, PL/SQL Concepts 1) To calculate the area of a circle, you must square the circle s radius and then multiply it by π. Write a program that calculates

More information

Oracle SQL Developer for Database Developers. An Oracle White Paper June 2007

Oracle SQL Developer for Database Developers. An Oracle White Paper June 2007 Oracle SQL Developer for Database Developers An Oracle White Paper June 2007 Oracle SQL Developer for Database Developers Introduction...3 Audience...3 Key Benefits...3 Architecture...4 Key Features...4

More information

Oracle. Brief Course Content This course can be done in modular form as per the detail below. ORA-1 Oracle Database 10g: SQL 4 Weeks 4000/-

Oracle. Brief Course Content This course can be done in modular form as per the detail below. ORA-1 Oracle Database 10g: SQL 4 Weeks 4000/- Oracle Objective: Oracle has many advantages and features that makes it popular and thereby makes it as the world's largest enterprise software company. Oracle is used for almost all large application

More information

Maintaining Stored Procedures in Database Application

Maintaining Stored Procedures in Database Application Maintaining Stored Procedures in Database Application Santosh Kakade 1, Rohan Thakare 2, Bhushan Sapare 3, Dr. B.B. Meshram 4 Computer Department VJTI, Mumbai 1,2,3. Head of Computer Department VJTI, Mumbai

More information

Oracle Database 11g: Advanced PL/SQL

Oracle Database 11g: Advanced PL/SQL Oracle Database 11g: Advanced PL/SQL Volume I Student Guide D52601GC10 Edition 1.0 March 2008 D54299 Authors Nancy Greenberg Rick Green Marcie Young Technical Contributors and Reviewers Claire Bennett

More information

Oracle to MySQL Migration

Oracle to MySQL Migration to Migration Stored Procedures, Packages, Triggers, Scripts and Applications White Paper March 2009, Ispirer Systems Ltd. Copyright 1999-2012. Ispirer Systems Ltd. All Rights Reserved. 1 Introduction The

More information

Programming Database lectures for mathema

Programming Database lectures for mathema Programming Database lectures for mathematics students April 25, 2015 Functions Functions are defined in Postgres with CREATE FUNCTION name(parameter type,...) RETURNS result-type AS $$ function-body $$

More information

Handling PL/SQL Errors

Handling PL/SQL Errors Handling PL/SQL Errors In PL/SQL, a warning or error condition is called an exception. Exceptions can be internally defined (by the run-time system) or user defined. Examples of internally defined exceptions

More information

Lesson 5 Administrative Users

Lesson 5 Administrative Users Administrative Users 5.1 Lesson 5 Administrative Users A practical and hands-on lesson on creating and using Oracle administrative users. SKILLBUILDERS Administrative Users 5.2 Lesson Objectives Understand

More information

Page 1 of 7 Welcome brendan ( Account Help Sign Out ) United States Communities I am a... I want to... Secure Search Products and Services Solutions Downloads Store Support Training Partners About Oracle

More information

Intro to Embedded SQL Programming for ILE RPG Developers

Intro to Embedded SQL Programming for ILE RPG Developers Intro to Embedded SQL Programming for ILE RPG Developers Dan Cruikshank DB2 for i Center of Excellence 1 Agenda Reasons for using Embedded SQL Getting started with Embedded SQL Using Host Variables Using

More information

STUDY OF PL/SQL BLOCK AIM: To Study about PL/SQL block.

STUDY OF PL/SQL BLOCK AIM: To Study about PL/SQL block. Ex.No.6 STUDY OF PL/SQL BLOCK AIM: To Study about PL/SQL block. DESCRIPTION: PL/SQL PL/SQL stands for Procedural Language extension of SQL. PL/SQL is a combination of SQL along with the procedural features

More information

COMS20700 DATABASES 13 PL/SQL. COMS20700 Databases Dr. Essam Ghadafi

COMS20700 DATABASES 13 PL/SQL. COMS20700 Databases Dr. Essam Ghadafi 13 PL/SQL COMS20700 Databases Dr. Essam Ghadafi PL/SQL - OVERVIEW PL/SQL: Procedure Language/Structured Query Language. Provides programming languages features: IF, Loops, subroutines,... Code can be compiled

More information

Oracle SQL Developer for Database Developers. An Oracle White Paper September 2008

Oracle SQL Developer for Database Developers. An Oracle White Paper September 2008 Oracle SQL Developer for Database Developers An Oracle White Paper September 2008 Oracle SQL Developer for Database Developers Introduction...3 Audience...3 Key Benefits...3 Architecture...4 Key Features...4

More information

StreamServe Persuasion SP5 Oracle Database

StreamServe Persuasion SP5 Oracle Database StreamServe Persuasion SP5 Oracle Database Database Guidelines Rev A StreamServe Persuasion SP5 Oracle Database Database Guidelines Rev A 2001-2011 STREAMSERVE, INC. ALL RIGHTS RESERVED United States patent

More information

14 Triggers / Embedded SQL

14 Triggers / Embedded SQL 14 Triggers / Embedded SQL COMS20700 Databases Dr. Essam Ghadafi TRIGGERS A trigger is a procedure that is executed automatically whenever a specific event occurs. You can use triggers to enforce constraints

More information

Handling PL/SQL Errors

Handling PL/SQL Errors 7 Handling PL/SQL Errors There is nothing more exhilarating than to be shot at without result. Winston Churchill Run-time errors arise from design faults, coding mistakes, hardware failures, and many other

More information

DECLARATION SECTION. BODY STATEMENTS... Required

DECLARATION SECTION. BODY STATEMENTS... Required 1 EXCEPTION DECLARATION SECTION Optional BODY STATEMENTS... Required STATEMENTS Optional The above Construction is called PL/SQL BLOCK DATATYPES 2 Binary Integer (-2 **31-1,2**31+1) signed integer fastest

More information

Database 10g Edition: All possible 10g features, either bundled or available at additional cost.

Database 10g Edition: All possible 10g features, either bundled or available at additional cost. Concepts Oracle Corporation offers a wide variety of products. The Oracle Database 10g, the product this exam focuses on, is the centerpiece of the Oracle product set. The "g" in "10g" stands for the Grid

More information

Oracle PL/SQL Injection

Oracle PL/SQL Injection Oracle PL/SQL Injection David Litchfield What is PL/SQL? Procedural Language / Structured Query Language Oracle s extension to standard SQL Programmable like T-SQL in the Microsoft world. Used to create

More information

PL/SQL Developer 7.1 User s Guide. March 2007

PL/SQL Developer 7.1 User s Guide. March 2007 PL/SQL Developer 7.1 User s Guide March 2007 PL/SQL Developer 7.1 User s Guide 3 Contents CONTENTS... 3 1. INTRODUCTION... 9 2. INSTALLATION... 13 2.1 SYSTEM REQUIREMENTS... 13 2.2 WORKSTATION INSTALLATION...

More information

A basic create statement for a simple student table would look like the following.

A basic create statement for a simple student table would look like the following. Creating Tables A basic create statement for a simple student table would look like the following. create table Student (SID varchar(10), FirstName varchar(30), LastName varchar(30), EmailAddress varchar(30));

More information

CHAPTER 2 DATABASE MANAGEMENT SYSTEM AND SECURITY

CHAPTER 2 DATABASE MANAGEMENT SYSTEM AND SECURITY CHAPTER 2 DATABASE MANAGEMENT SYSTEM AND SECURITY 2.1 Introduction In this chapter, I am going to introduce Database Management Systems (DBMS) and the Structured Query Language (SQL), its syntax and usage.

More information

Firebird. Embedded SQL Guide for RM/Cobol

Firebird. Embedded SQL Guide for RM/Cobol Firebird Embedded SQL Guide for RM/Cobol Embedded SQL Guide for RM/Cobol 3 Table of Contents 1. Program Structure...6 1.1. General...6 1.2. Reading this Guide...6 1.3. Definition of Terms...6 1.4. Declaring

More information

Oracle For Beginners Page : 1

Oracle For Beginners Page : 1 Oracle For Beginners Page : 1 Chapter 22 OBJECT TYPES Introduction to object types Creating object type and object Using object type Creating methods Accessing objects using SQL Object Type Dependencies

More information

SQL Server An Overview

SQL Server An Overview SQL Server An Overview SQL Server Microsoft SQL Server is designed to work effectively in a number of environments: As a two-tier or multi-tier client/server database system As a desktop database system

More information

Oracle Database 11g SQL

Oracle Database 11g SQL AO3 - Version: 2 19 June 2016 Oracle Database 11g SQL Oracle Database 11g SQL AO3 - Version: 2 3 days Course Description: This course provides the essential SQL skills that allow developers to write queries

More information

Virtual Private Database Features in Oracle 10g.

Virtual Private Database Features in Oracle 10g. Virtual Private Database Features in Oracle 10g. SAGE Computing Services Customised Oracle Training Workshops and Consulting. Christopher Muir Senior Systems Consultant Agenda Modern security requirements

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: 1.800.529.0165 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn This Oracle Database: Introduction to SQL training teaches you how to write subqueries,

More information

An Introduction to SQL Injection Attacks for Oracle Developers. January 2004 INTEGRIGY. Mission Critical Applications Mission Critical Security

An Introduction to SQL Injection Attacks for Oracle Developers. January 2004 INTEGRIGY. Mission Critical Applications Mission Critical Security An Introduction to SQL Injection Attacks for Oracle Developers January 2004 INTEGRIGY Mission Critical Applications Mission Critical Security An Introduction to SQL Injection Attacks for Oracle Developers

More information

3.GETTING STARTED WITH ORACLE8i

3.GETTING STARTED WITH ORACLE8i Oracle For Beginners Page : 1 3.GETTING STARTED WITH ORACLE8i Creating a table Datatypes Displaying table definition using DESCRIBE Inserting rows into a table Selecting rows from a table Editing SQL buffer

More information

The Sins of SQL Programming that send the DB to Upgrade Purgatory Abel Macias. 1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

The Sins of SQL Programming that send the DB to Upgrade Purgatory Abel Macias. 1 Copyright 2011, Oracle and/or its affiliates. All rights reserved. The Sins of SQL Programming that send the DB to Upgrade Purgatory Abel Macias 1 Copyright 2011, Oracle and/or its affiliates. All rights reserved. Who is Abel Macias? 1994 - Joined Oracle Support 2000

More information

SQL Server Database Coding Standards and Guidelines

SQL Server Database Coding Standards and Guidelines SQL Server Database Coding Standards and Guidelines http://www.sqlauthority.com Naming Tables: Stored Procs: Triggers: Indexes: Primary Keys: Foreign Keys: Defaults: Columns: General Rules: Rules: Pascal

More information

AV-004: Administering and Programming with ORACLE

AV-004: Administering and Programming with ORACLE AV-004: Administering and Programming with ORACLE Oracle 11g Duration: 140 hours Introduction: An Oracle database is a collection of data treated as a unit. The purpose of a database is to store and retrieve

More information

RMAN BACKUP & RECOVERY. Recovery Manager. Veeratteshwaran Sridhar

RMAN BACKUP & RECOVERY. Recovery Manager. Veeratteshwaran Sridhar RMAN Recovery Manager BACKUP & RECOVERY Veeratteshwaran Sridhar Why Backup & Recovery? The purpose of a backup and recovery strategy is to protect the database against data loss and reconstruct the database

More information

Sybase Adaptive Server Enterprise

Sybase Adaptive Server Enterprise technical white paper Sybase Adaptive Server Enterprise Data Transfer Utility www.sybase.com Contents 1. Executive Summary..........................................................................................................

More information