Managing Functions

A function is a subprogram that can take parameters and return a single value.

Topics:

See Also:

Oracle Database SQL Language Reference for information about PL/SQL functions and Oracle Database PL/SQL Language Reference

Creating a Function

To create a function:

  1. On the Workspace home page, click SQL Workshop and then Object Browser.

    Object Browser appears.

  2. Click Create.

  3. From the list of object types, select Function.

  4. Enter a function name, specify the return datatype, and click Next.

  5. Define the arguments and click Next (optional):

    • Argument Name

    • Argument Type (datatype)

    • Default (value)

    To add additional arguments, click Add Argument.

  6. Enter PL/SQL block you want to use as the function body and click Next.

    A confirmation page appears, which displays the SQL used to create the function.

  7. Click Create Function.

Browsing a Function

To view a function in Object Browser:

  1. On the Workspace home page, click SQL Workshop and then Object Browser.

    Object Browser appears.

  2. From the Object list, select Functions.

  3. From the Object Selection pane, select a function.

    The Code view appears. You can edit the code in this view.

Summary of Available Views

Click the tabs at the top of the page to view different reports about the function. Table 1-9 describes all available views.


Table 1-9 Available Views for Functions

View Description

Code

(Default) Displays the source code for the function. You can edit the code in this view. Actions you can perform in this view include:

  • Edit the code manually

  • Save & Compile

  • Find & Replace

  • Undo

  • Redo

  • Download Source

  • Drop

See Also: "Editing a Function", "Compiling a Function", "Downloading a Function", and "Dropping a Function"

Dependencies

Displays objects that use (or depend) on the current function and objects the function depends on.

Errors

Displays errors related to the current function.

Grants

Lists details of grants for the current function, including privilege, grantee, grantable, grantor, and object name.


Editing a Function

When you edit a function you can edit the code manually, perform a search and replace, and compile the function.

Editing a Function Manually

To edit a function manually:

  1. On the Workspace home page, click SQL Workshop and then Object Browser.

    Object Browser appears.

  2. From the Object list, select Functions.

  3. From the Object Selection pane, select a function.

    The Code view appears. You can edit the code in this view.

  4. Click Edit to activate manual edit mode.

  5. Click Find & Replace to perform a basic search and replace.

Compiling a Function

If you edit and make changes to a function, you must compile to save your changes. There is no save function because this is just a view of the object within the database.

To compile a function in Object Browser:

  1. On the Workspace home page, click SQL Workshop and then Object Browser.

    Object Browser appears.

  2. From the Object list, select Functions.

  3. From the Object Selection pane, select a function.

    The Code view appears.

  4. Click Save & Compile to compile the current function.

    Compiling re-creates the object in the database. If the compilation fails, an error message displays above the code.

Downloading a Function

To save a function to a file in Object Browser:

  1. On the Workspace home page, click SQL Workshop and then Object Browser.

    Object Browser appears.

  2. From the Object list, select Functions.

  3. From the Object Selection pane, select a function.

    The Code view appears.

  4. Click Download Source to save the current function as a file.

Dropping a Function

To drop a function in Object Browser:

  1. On the Workspace home page, click SQL Workshop and then Object Browser.

    Object Browser appears.

  2. From the Object list, select Functions.

  3. From the Object Selection pane, select a function.

    The Code view appears.

  4. Click Drop.

  5. To confirm, click Finish.