A function is a subprogram that can take parameters and return a single value.
Topics:
See Also: SQL*Plus User's Guide and Reference for information about PL/SQL functions |
To create a function:
Navigate to Object Browser:
Click the SQL Workshop icon on the Workspace home page.
Click Object Browser.
Object Browser appears.
Click Create.
From the list of object types, select Functions.
Enter a function name, specify the return datatype, and click Next.
Define the arguments and click Next (optional):
Argument Name
Argument Type (datatype)
Default (value)
To add additional arguments, click Add Argument.
Enter P/LSQL block you want to use as the function body and click Next.
To link to the SQL Command Processor, click Command Processor. To view the previously defined arguments, click Defined Arguments.
A confirmation page appears. To view the SQL used to create the function, click Show SQL.
Click Finish.
To view a function in Object Browser:
Navigate to Object Browser:
Click the SQL Workshop icon on the Workspace home page.
Click Object Browser.
Object Browser appears.
From the Object list, select Functions.
From the Object Selection pane, select a function.
The Code view appears. You can copy the code in this view for use in other tools.
Click the tabs at the top of the page to view different reports about the function. Table 18-9 describes all available views.
Table 18-9 Available Views for Functions
View | Description |
---|---|
Code |
(Default) Displays the source code for the function. You can copy the code in this view for use in other tools. Actions you can perform in this view include:
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. |
When you edit a function you can edit the code manually, perform a search and replace, and compile the function.
To edit a function manually:
Navigate to Object Browser:
Click the SQL Workshop icon on the Workspace home page.
Click Object Browser.
Object Browser appears.
From the Object list, select Functions.
From the Object Selection pane, select a function.
The Code view appears. Be default, you can copy code from this view for use in other tools.
Click Edit to activate manual edit mode.
Click Find to perform a basic search and replace.
Note: You can expand the Edit pane by clicking the Full Screen icon in the upper right of the pane, beneath the Create button. |
If you edit and make changes to a function, you need to compile in order to save your changes. There is no save function because this is just a view of the object within the database.
Click Compile to compile the current function. Compiling re-creates the object in the database. If the compile fails, an error message display above the code.