A function is a subprogram that can take parameters and return a single value.
Topics:
Oracle Database SQL Language Reference for information about PL/SQL functions and Oracle Database PL/SQL Language Reference
To create a function:
On the Workspace home page, click SQL Workshop and then Object Browser.
Object Browser appears.
Click Create.
From the list of object types, select Function.
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 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.
Click Create Function.
To view a function in Object Browser:
On the Workspace home page, click SQL Workshop and then 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 edit the code in this view.
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:
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:
On the Workspace home page, click SQL Workshop and then 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 edit the code in this view.
Click Edit to activate manual edit mode.
Click Find & Replace to perform a basic search and replace.
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:
On the Workspace home page, click SQL Workshop and then Object Browser.
Object Browser appears.
From the Object list, select Functions.
From the Object Selection pane, select a function.
The Code view appears.
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.
To save a function to a file in Object Browser:
On the Workspace home page, click SQL Workshop and then Object Browser.
Object Browser appears.
From the Object list, select Functions.
From the Object Selection pane, select a function.
The Code view appears.
Click Download Source to save the current function as a file.
To drop a function in Object Browser:
On the Workspace home page, click SQL Workshop and then Object Browser.
Object Browser appears.
From the Object list, select Functions.
From the Object Selection pane, select a function.
The Code view appears.
Click Drop.
To confirm, click Finish.