Function/Procedure Management

Creating a Function/Procedure

  1. In the Object Browser pane, right-click Functions/Procedures under the schema where you want to create the function/procedure. Then select Create Function, Create SQL Function, Create Procedure, or Create C Function as required.

    Right-click Functions/Procedures and a menu is displayed.

  2. The selected template is displayed in the new tab of Data Studio.

  3. After adding a function or procedure, you can choose Run > Compile/Execute Statement from the main menu or right-click the tab and select Compile to compile the function or procedure.

  4. The new function/procedure is displayed under Object Browser.

    • The asterisk (*) next to the procedure name indicates that the procedure is not compiled or added to Object Browser.
    • Refresh Object Browser by pressing F5 to view the newly added debugging object.
    • C functions do not support debugging operations.
    • A pop-up message displays the status of the completed operation, which is not displayed in the status bar.

Editing a Function/Procedure

  1. In the Object Browser pane, double-click or right-click the required function/procedure or SQL function and select View Source.

    The selected function/procedure or SQL function is displayed in the PL/SQL Viewer tab page.

    • You must refresh Object Browser to view the latest DDL.
    • If multiple functions/procedures or SQL functions have the same schema, name, and input parameters, only one of them can be opened at a time.

  2. After editing or updating, compile and execute the PL/SQL program or SQL function.

    If you execute the function/procedure or SQL function before compilation, the Source Code Change dialog box is displayed.

  3. Click Yes to compile and execute the PL/SQL function/procedure. The status of the completed operation is displayed in the Message tab page.
  4. After compiling the function/procedure or SQL function, press F5 to refresh Object Browser to view the updated code.

Granting or Revoking a Permission

  1. Right-click Function/Procedure Group and select Grant/Revoke. The Grant/Revoke dialog box is displayed.
  2. Open the Object Selection tab to select the desired objects, and click Next.
  3. The Privilege Selection tab is displayed. Select the role from the Role drop-down list.
  4. On the SQL Preview tab, you can check the automatically generated SQL query. If the result does not meet the expectation, return to the previous step until the result meets the expectation.
  5. Click Finish.

Debugging a Function/Procedure

A breakpoint is used to stop a PL/SQL program on the line where the breakpoint is set. You can use breakpoints to control the execution and debug the procedure. When a line with a breakpoint set is reached, the PL/SQL program on this line will be stopped, and you can perform other debugging operations.

Controlling Execution

Exporting a Function or Procedure DDL

Follow the steps below to export the function/procedure DDL:

  1. In the Object Browser pane, right-click the selected function or procedure and select Export DDL.

    You need to customize the export path. To compress data, select .zip.

    You must select I agree under Security Disclaimer, then click OK. You can disable the security disclaimer. After the disclaimer is disabled, it will not be displayed when you export the DDL. For details, see Table 1.

  2. Click OK. The operation progress is displayed on the status bar in the lower right corner.

    • If the file name contains characters that are not supported by Windows, the file name will be different from the schema name.
    • MS Visual C runtime file (msvcrt100.dll) is required to complete this operation. For details, see Troubleshooting.

    The Data Exported Successfully dialog box and status bar display the status of the completed operation.

    Table 1 Supported DDL encoding formats

    Database Encoding

    File Encoding

    Support for Exporting a DDL

    UTF-8

    UTF-8

    Yes

    GBK

    Yes

    LATIN1

    Yes

    GBK

    GBK

    Yes

    UTF-8

    Yes

    LATIN1

    No

    LATIN1

    LATIN1

    Yes

    GBK

    No

    UTF-8

    Yes

Deleting a Function/Procedure

You can delete functions or programs one by one or in batches.

  1. In the Object Browser pane, right-click the selected function/procedure object and select Drop Object.
  2. Select one or more function or procedure objects and choose Delete Object.
  3. In the dialog box that is displayed, click Yes.

    The status bar displays the status of the completed operation.