Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / SQL reference.pdf
Скачиваний:
24
Добавлен:
12.05.2015
Размер:
11.92 Mб
Скачать

CALL

CALL

Purpose

Use the CALL statement to execute a routine (a standalone procedure or function, or a procedure or function defined within a type or package) from within SQL.

See Also: PL/SQL User’s Guide and Reference for information on creating such routine

Prerequisites

You must have EXECUTE privilege on the standalone routine or on the type or package in which the routine is defined.

Syntax

call::=

 

 

type

 

.

 

 

schema

.

package

.

function

dblink_name

@

 

 

 

 

 

procedure

 

CALL

 

 

 

 

method

 

object_access_expression

 

 

 

 

 

,

 

 

 

 

INDICATOR

 

 

 

 

 

:

indicator_variable

 

 

 

 

 

expr

INTO

:

host_variable

 

 

(

)

 

 

 

 

;

Semantics

schema

Specify the schema in which the standalone routine (or the package or type containing the routine) resides. If you do not specify schema, then Oracle assumes the routine is in your own schema.

type or package

Specify the type or package in which the routine is defined.

12-68 Oracle9i SQL Reference

CALL

function | procedure | method

Specify the name of the function or procedure being called, or a synonym that translates to a function or procedure.

When you call a type’s member function or procedure, if the first argument (SELF) is a null IN OUT argument, then Oracle returns an error. If SELF is a null IN argument, then Oracle returns null. In both cases, the function or procedure is not invoked.

Restriction on Functions If the routine is a function, then the INTO clause is mandatory.

@dblink

In a distributed database system, specify the name of the database containing the standalone routine (or the package or function containing the routine). If you omit dblink, then Oracle looks in your local database.

See Also: "Calling a Procedure: Example" on page 12-70 for an example of calling a routine directly

object_access_expression

If you have an expression of an object type, such as a type constructor or a bind variable, you can use the object_access_expression syntax to call a routine defined within the type.

The syntax permitted in this context is a subset of object access expressions (see "Object Access Expressions" on page 4-12). Used within the CALL statement, you can invoke only methods (not attributes), and object_expr must be a literal (not a column name or other nonliteral expression). Therefore, the syntax allowed is:

expression.method

where expression is the literal expression of the object type and method is a member method of the object type.

See Also: "Calling a Procedure Using an Expression of an Object Type: Example" on page 12-70 for an example of calling a routine using an expression of an object type

argument

Specify one or more arguments to the routine, if the routine takes arguments.

SQL Statements: ALTER TRIGGER to COMMIT 12-69

CALL

Restrictions on Arguments to the Routine

An argument cannot be a pseudocolumn or either of the object reference functions VALUE or REF.

Any argument that is an IN OUT or OUT argument of the routine must correspond to a host variable expression.

INTO :host_variable

The INTO clause applies only to calls to functions. Specify which host variable will store the return value of the function.

:indicator_variable

Specify the value or condition of the host variable.

See Also: Pro*C/C++ Precompiler Programmer’s Guide for more information on host variables and indicator variables

Example

Calling a Procedure: Example The following statement uses the remove_dept procedure (created in "Creating a Package Body: Example" on page 14-59) to remove the Entertainment department (created in "Inserting Sequence Values: Example" on page 17-67):

CALL remove_dept(162);

Calling a Procedure Using an Expression of an Object Type: Example The following examples show how call a procedure by using an expression of an object type in the CALL statement. The example uses the warehouse_typ object type in the order entry sample schema OE:

ALTER TYPE warehouse_typ

ADD MEMBER FUNCTION ret_name

RETURN VARCHAR2

CASCADE;

CREATE OR REPLACE TYPE BODY warehouse_typ

AS MEMBER FUNCTION ret_name

RETURN VARCHAR2

IS

BEGIN

RETURN self.warehouse_name;

12-70 Oracle9i SQL Reference

CALL

END;

END;

/

VARIABLE x VARCHAR2(25);

CALL warehouse_typ(456, 'Warehouse 456', 2236).ret_name() INTO :x;

PRINT x; X

--------------------------------

Warehouse 456

The next example shows how to use an external function to achieve the same thing:

CREATE OR REPLACE FUNCTION ret_warehouse_typ(x warehouse_typ) RETURN warehouse_typ

IS

BEGIN RETURN x;

END;

/

CALL ret_warehouse_typ(warehouse_typ(234, 'Warehouse 234', 2235)).ret_name()

INTO :x;

PRINT x;

X

--------------------------------

Warehouse 234

SQL Statements: ALTER TRIGGER to COMMIT 12-71

Соседние файлы в папке Oracle selected docs