Oracle9i SQL Reference
Release 1 (9.0.1)

Part Number A90125-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to beginning of chapter Go to next page

SQL Statements:
CREATE LIBRARY to CREATE SPFILE, 10 of 16


CREATE PROCEDURE

Purpose

Use the CREATE PROCEDURE statement to create a standalone stored procedure or a call specification.

A procedure is a group of PL/SQL statements that you can call by name. A call specification ("call spec") declares a Java method or a third-generation language (3GL) routine so that it can be called from SQL and PL/SQL. The call spec tells Oracle which Java method to invoke when a call is made. It also tells Oracle what type conversions to make for the arguments and return value.

Stored procedures offer advantages in the areas of development, integrity, security, performance, and memory allocation.

See Also:

  • Oracle9i Application Developer's Guide - Fundamentals for more information on stored procedures, including how to call stored procedures and for information about registering external procedures

  • CREATE FUNCTION for information specific to functions, which are similar to procedures in many ways

  • CREATE PACKAGE for information on creating packages. (The CREATE PROCEDURE statement creates a procedure as a standalone schema object. You can also create a procedure as part of a package.)

  • ALTER PROCEDURE and DROP PROCEDURE for information on modifying and dropping a standalone procedure

  • CREATE LIBRARY for more information about shared libraries

 

Prerequisites

Before creating a procedure, the user SYS must run a SQL script commonly called DBMSSTDX.SQL. The exact name and location of this script depends on your operating system.

To create a procedure in your own schema, you must have the CREATE PROCEDURE system privilege. To create a procedure in another user's schema, you must have CREATE ANY PROCEDURE system privilege. To replace a procedure in another schema, you must have the ALTER ANY PROCEDURE system privilege.

To invoke a call spec, you may need additional privileges (for example, EXECUTE privileges on the C library for a C call spec).

To embed a CREATE PROCEDURE statement inside an Oracle precompiler program, you must terminate the statement with the keyword END-EXEC followed by the embedded SQL statement terminator for the specific language.

See Also:

PL/SQL User's Guide and Reference or Oracle9i Java Stored Procedures Developer's Guide for more information  

Syntax

create_procedure::=


Text description of statements_625.gif follows
Text description of create_procedure

invoker_rights_clause::=


Text description of statements_626.gif follows
Text description of invoker_rights_clause

call_spec::=


Text description of statements_627.gif follows
Text description of call_spec

Java_declaration::=


Text description of statements_610a.gif follows
Text description of java_declaration

C_declaration::=


Text description of statements_628.gif follows
Text description of c_declaration

Keywords and Parameters

OR REPLACE

Specify OR REPLACE to re-create the procedure if it already exists. Use this clause to change the definition of an existing procedure without dropping, re-creating, and regranting object privileges previously granted on it. If you redefine a procedure, Oracle recompiles it.

Users who had previously been granted privileges on a redefined procedure can still access the procedure without being regranted the privileges.

If any function-based indexes depend on the package, Oracle marks the indexes DISABLED.

See Also:

ALTER PROCEDURE for information on recompiling procedures 

schema

Specify the schema to contain the procedure. If you omit schema, Oracle creates the procedure in your current schema.

procedure

Specify the name of the procedure to be created.

If creating the procedure results in compilation errors, Oracle returns an error. You can see the associated compiler error messages with the SQL*Plus command SHOW ERRORS.

argument

Specify the name of an argument to the procedure. If the procedure does not accept arguments, you can omit the parentheses following the procedure name.

IN

Specify IN to indicate that you must specify a value for the argument when calling the procedure.

OUT

Specify OUT to indicate that the procedure passes a value for this argument back to its calling environment after execution.

IN OUT

Specify IN OUT to indicate that you must specify a value for the argument when calling the procedure and that the procedure passes a value back to its calling environment after execution.

If you omit IN, OUT, and IN OUT, the argument defaults to IN.

NOCOPY

Specify NOCOPY to instruct Oracle to pass this argument as fast as possible. This clause can significantly enhance performance when passing a large value like a record, an index-by table, or a varray to an OUT or IN OUT parameter. (IN parameter values are always passed NOCOPY.)

These effects may or may not occur on any particular call. You should use NOCOPY only when these effects would not matter.

datatype

Specify the datatype of the argument. An argument can have any datatype supported by PL/SQL.

Datatypes cannot specify length, precision, or scale. For example, VARCHAR2(10) is not valid, but VARCHAR2 is valid. Oracle derives the length, precision, and scale of an argument from the environment from which the procedure is called.

invoker_rights_clause

The invoker_rights_clause lets you specify whether the procedure executes with the privileges and in the schema of the user who owns it or with the privileges and in the schema of CURRENT_USER.

This clause also determines how Oracle resolves external names in queries, DML operations, and dynamic SQL statements in the procedure.

AUTHID CURRENT_USER

Specify CURRENT_USER to indicate that the procedure executes with the privileges of CURRENT_USER. This clause creates an invoker-rights procedure.

This clause also specifies that external names in queries, DML operations, and dynamic SQL statements resolve in the schema of CURRENT_USER. External names in all other statements resolve in the schema in which the procedure resides.

AUTHID DEFINER

Specify DEFINER to indicate that the procedure executes with the privileges of the owner of the schema in which the procedure resides, and that external names resolve in the schema where the procedure resides. This is the default and creates a definer-rights procedure.

See Also:

 

IS | AS Clause

pl/sql_subprogram_body

Declare the procedure in a PL/SQL subprogram body.

See Also:

Oracle9i Application Developer's Guide - Fundamentals for more information on PL/SQL subprograms 

call_spec

Use the call_spec to map a Java or C method name, parameter types, and return type to their SQL counterparts.

T Java_declaration 'string' identifies the Java implementation of the method.

See Also:

 
AS EXTERNAL

The AS EXTERNAL clause is an alternative way of declaring a C method. This clause has been deprecated and is supported for backward compatibility only. Oracle Corporation recommends that you use the AS LANGUAGE C syntax.

Examples

CREATE PROCEDURE Example

The following statement creates the procedure credit in the schema oe:

CREATE PROCEDURE oe.credit 
   (acc_no IN NUMBER, amount IN NUMBER) AS 
   BEGIN
      UPDATE accounts 
      SET balance = balance + amount 
      WHERE account_id = acc_no; 
   END;

The credit procedure credits a specified bank account with a specified amount. When you call the procedure, you must specify the following arguments:

The procedure uses an UPDATE statement to increase the value in the balance column of the accounts table by the value of the argument amount for the account identified by the argument acc_no.

In the following example, external procedure c_find_root expects a pointer as a parameter. Procedure find_root passes the parameter by reference using the BY REFERENCE phrase:

CREATE PROCEDURE find_root
   ( x IN REAL ) 
   IS LANGUAGE C
      NAME "c_find_root"
      LIBRARY c_utils
      PARAMETERS ( x BY REFERENCE );

Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2001, Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback