2.14 Managing Functions

A function is a subprogram that can take parameters and return a single value. You can use Object Browser to create, browse, edit, compile, download, drop functions and view report.

See Also:

2.14.1 Creating a Function

Create a function using Object Browser.

To create a function:

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

    Object Browser appears.

  2. Click the Create icon.
  3. From the list of object types, select Function.
  4. For Name:
    1. Function Name - Enter the name of the function.

      Note:

      Object names must conform to Oracle naming conventions and cannot contain spaces, or start with a number or underscore.

    2. Return Data Type - Select a data type.

    3. Specify whether to Include Arguments or Preserve Case.

    4. Click Next.

  5. For Arguments, define the arguments by specifying the following information (optional):
    • Argument Name

    • Argument Type (datatype)

    • Default (value)

    • Move

    To add additional arguments, click Add Argument.

  6. Click Next.
  7. For Function Body, enter PL/SQL block you want to use and click Next.

    A confirmation page appears.

  8. Click Create Function.

2.14.2 Browsing a Function

Select a function from the Object Selection pane and view different reports about the 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.

  4. Click the tabs at the top of the page to view different reports about the function.

See Also:

"Reports for Functions"

2.14.3 Reports for Functions

Alternative views available when browsing a function in Object Browser.

Table 2-9 describes all available reports for functions.

Table 2-9 Available Reports 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

  • Auto Complete

  • Undo

  • Redo

  • Download Source

  • Drop

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.

2.14.4 Editing a Function Manually

Select a function from the Object Selection pane and click Edit.

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

  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. To perform a basic search, click the Find icon (which resembles a magnifying glass).
  6. To replace existing code, click the Replace icon (which resembles a two-sided arrow).

2.14.5 Compiling a Function

Select a function from the Object Selection pane click Save & Compile.

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.

2.14.6 Downloading a Function

Select a function from the Object Selection pane click Download Source to save the current function as a file.

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.

2.14.7 Dropping a Function

Select a function from the Object Selection pane and click Drop.

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.