All Products
Search
Document Center

:Snippet

Last Updated:Jan 03, 2023

As an enterprise-grade database development platform, OceanBase Developer Center (ODC) provides the code snippet module to facilitate database development. If you forget about the usage of some statements, you can query in the code snippet module. The code snippet module provides suitable code snippets based on whether you are in Oracle or MySQL mode. In addition to the built-in code snippets, you can also create custom code snippets to store frequently used code segments. A custom code snippet can be viewed only by its creator.

To open the Snippets panel, click Snippets in the toolbar of an SQL window, an anonymous block window, or a PL object editing page.Image 225

View code snippets

In the Snippets panel, the code snippets are displayed in a list of cards. Each card displays information about a code snippet, such as its name, description, and type. When you place the pointer over the tips iconSnippet tips icon next to a code snippet name, a tip window appears, displaying the entire code in the snippet.

You can directly search for specific code snippets in the search box above the card list. A filter is provided below the search box for you to filter code snippets by type. The filter provides the following options: Others, DML, DDL, Process Control Statement, and All Types. By default, All Types is selected.

Create a code snippet

Click the +Create button in the upper-right corner of the code snippet list. The Create Snippets panel appears. Specify the following information in the panel:

  • Snippet Name: specifies the name of the code snippet. It can contain letters, digits, and underscores (_), and can contain a maximum of 60 characters. This parameter must be specified.

  • Snippet Type: specifies the type of the code snippet. The types include Others, DML, DDL, and Process Control Statement. By default, Others is selected.

  • Snippets: specifies the actual code of the snippet. The length cannot exceed 2000 characters. This parameter must be specified. Similar to the SQL window, the toolbar of the editing area also provides buttons such as Format, Find and Replace, Undo, Redo, Case Sensitivity, Indent, and Comment. It also provides code highlighting and association features.

  • Snippet Description: provides additional notes on the code snippet. The length cannot exceed 200 characters. This parameter is optional.

    Note

    If you specified an additional notes in the description field, the snippet card in the Snippets panel displays the notes. Otherwise, the first 30 characters of the code are displayed.

Image 224

Reference a code snippet

You not only can view the content of a created code snippet when you edit scripts, but also can reference it in your script. You can reference a code snippet by using one of the following three methods:

  • Method 1: Drag the target card from the code snippet list to the editing area, and the code in the code snippet is copied to the editing area.

  • Method 2: Click the copy icon in the lower-right corner of the target code snippet card to copy the code, and then press Ctrl+V or Cmd+V to paste the code to the editing area.

  • Method 3: The editing area of the SQL window supports code association. When you edit a script in the editing area, existing code snippets appear in the code association window for you to view and reference.

Manage code snippets

ODC provides the Edit and Delete options for you to manage custom code snippets. You cannot edit or delete built-in code snippets.

  • Edit: Click the management icon (···) in the upper-right corner of the target code snippet card. In the menu that appears, click the Edit button to go to the Edit Snippet panel. The panel displays parameters such as Snippet Name, Snippet Type, Snippets, and Snippet Description that were specified at creation of the code snippet. You can modify the information as needed.

  • Delete: Click the management icon (···) in the upper-right corner of the target code snippet card. In the menu that appears, click the Delete button to delete the code snippet.