Navicat Blog

Query Customization Using Navicat-only Syntax Nov 13, 2024 by Robert Gravelle

Available in all editions of Navicat database administration and development tools (including Navicat Premium Lite!), Code Snippets allows you to insert reusable code into your SQL statements when working in the SQL Editor. Besides gaining access to a collection of built-in snippets, you can also define your own. One of the built-in categories supplies special Navicat-only Syntax for customizing the query results tab name as well as for supplying runtime parameters. Today's blog will demonstrate how to use both snippets in your queries using the free MySQL Sakila Database and Navicat Premium 17.

About the Code Snippet Pane

Located on the right-hand side of the SQL Editor, the Code Snippets Pane provides an easy way to insert reusable code into SQL statements when working in the SQL Editor. If the editor window is docked to the Navicat main window, you can click the () icon in the Information pane to view the snippets library.

query_editor_with_code_snippets_pane (158K)

You can bring up the two code snippets that we'll be learning about today by selecting the "Navicat-only Syntax" item in the Code-Snippets drop-down menu:

navicat-only_syntax_drop-down_item (21K)

Customizing the Result Tab Name

Every result set generated by a query is displayed in a separate tab below the Query Editor. Each tab is given the name "Result n" by default where "n" is the order in which the query was executed. For example, the first query will be named "Result 1", the second "Result 2", etc.

Clicking the "Customize Result Tab Name" snippet will insert some special Navicat-only syntax at the current cursor position in the editor:

customize_result_tab_name_syntax (9K)

Once we've replaced the "tab_name" text with the desired tab name and the "Statement..." placeholder with the SQL, executing the query will now display the results with the name that we specified:

custom_result_tab (91K)

There are a couple of other ways to insert a Code Snippet in the Query Editor. We can:

  • drag and drop a snippet from the library into the editor, or
  • start typing the name of a snippet in the editor. Smart code completion will pop up a list of suggestions for the word completion automatically. From there, we can select the snippet from the list to insert to the code into the editor.

    auto-complete (49K)

Supplying a Runtime Parameter

One of the advantages of using a stored procedure is that you can supply one or more input parameters rather than hard-code values. Thanks to Navicat's Runtime Parameter Code Snippet, you can achieve the same result using regular SELECT statements.

Clicking the "Runtime Parameter" Snippet will insert a placeholder for the parameter at the current cursor position in the editor:

runtime_parameter_syntax (29K)

Now, when we execute the query, Navicat will present an input parameter dialog for us to provide the value to use:

input_parameter_dialog (70K)

Conclusion

In today's blog we learned how to use Navicat-only Syntax Code Snippets for customizing the query results tab name as well as for supplying runtime parameters to our queries. These were executed in Navicat Premium 17. Interested in giving Navicat Premium 17 a try? You can download it for a 14-day fully functional FREE trial. It's available for Windows, macOS, and Linux operating systems.

Navicat Blogs
Feed Entries
Blog Archives
Share