# Snippets

Use and customise PL/SQL code snippets to accelerate database code authoring.

Source: https://www.nexosqlstudio.com/docs/snippets
Language: en
Type: docs

# Snippets

## Database support

Database support does not imply identical features. Connections and SQL worksheets are the starting point; editing, DDL, modeling, transfers, administration and AI operations depend on the engine and workflow. Check the installed version and the relevant guide before relying on an advanced operation.

[Supported databases and feature availability](https://www.nexosqlstudio.com/databases) · [Connection guides](https://www.nexosqlstudio.com/docs/getting-started)

Nexo SQL Studio ships with PL/SQL and SQL snippets that save you from boilerplate. Snippets are triggered by a short prefix keyword and expanded by pressing `Tab`.

## Using Snippets

Type the snippet prefix in any `.sql`, `.pls`, `.pkb`, `.pks`, `.prc`, or `.fnc` file and press `Tab` (or select from the completion list with `Ctrl+Space`).

**Example — Create a procedure:**

Type `proc` and press Tab:

```plsql
CREATE OR REPLACE PROCEDURE procedure_name (
    p_param1 IN VARCHAR2
) AS
BEGIN
    -- TODO
    NULL;
END procedure_name;
/
```

**Example — Exception block:**

Type `excep`:

```plsql
EXCEPTION
    WHEN OTHERS THEN
        ROLLBACK;
        DBMS_OUTPUT.PUT_LINE('Error: ' || SQLERRM);
        RAISE;
```

## Built-in Snippet Library

| Prefix     | Expands to                            |
|------------|---------------------------------------|
| `proc`     | `CREATE OR REPLACE PROCEDURE …`       |
| `func`     | `CREATE OR REPLACE FUNCTION …`        |
| `pkg`      | Package spec skeleton                 |
| `pkgb`     | Package body skeleton                 |
| `trigger`  | `CREATE OR REPLACE TRIGGER …`         |
| `cursor`   | Cursor declaration + loop             |
| `begin`    | `BEGIN … EXCEPTION … END;`            |
| `if`       | `IF … THEN … END IF;`                 |
| `loop`     | `LOOP … EXIT WHEN … END LOOP;`        |
| `forloop`  | `FOR i IN … LOOP … END LOOP;`         |
| `pldoc`    | PL/SQL documentation block            |
| `excep`    | Exception handler block               |
| `bulk`     | `BULK COLLECT INTO … FORALL …`        |
| `dyn`      | `EXECUTE IMMEDIATE …`                 |

## Snippets View

Use the **Snippets / Reports** view to create folders, create snippets, filter entries, edit associated connections, and insert snippets into the active editor.

### Call a snippet by alias

Assign a snippet an alias in **Snippets / Reports**, then type that alias in a SQL or PL/SQL worksheet and choose it from the completion list. Aliases begin with an underscore, for example `_active_sessions`; press `Ctrl+Space` to open completions. The underscore is part of the alias.

### Assisted SQL generation

In a worksheet, open completions with `Ctrl+Space` and choose **select (assisted)** or **group by (assisted)**. Nexo prompts you to choose a table and columns, then inserts the generated statement. The completion list also offers assisted `INSERT`, `UPDATE`, `DELETE`, and `MERGE` statements.

## Documentation Snippets (pldoc)

The `pldoc` snippet inserts a structured documentation block above a procedure or function:

```plsql
/**
 * <Short description>
 *
 * @param p_param1  Description of parameter
 * @return          Description of return value
 */
```

You can customise the pldoc template by referencing a folder that contains your own `pldoc.json` file:

```json
// settings.json
"nexo-sql-studio.pldoc.path": ".vscode"
```


