How to Create Parameter Queries in LibreOffice Base
This article explains how to create and use parameterized queries in LibreOffice Base to prompt users for input values dynamically at runtime. You will learn the syntax required to trigger parameter dialogs, how to set them up using both the graphical Query Design interface and standard SQL View, and how to use advanced operators like wildcards with your parameters.
What Are Parameter Queries in LibreOffice Base?
A parameter query in LibreOffice Base is a dynamic query that pauses execution to request specific criteria from the user via a pop-up dialog box. Instead of hardcoding filter values into the query design, you define variable placeholders. Whenever the query is run, LibreOffice Base prompts the user for input and uses those values to filter the resulting dataset.
The Parameter Syntax
LibreOffice Base identifies a parameter by a colon (:)
immediately preceding the parameter name without any spaces.
- Syntax:
:ParameterName - Example:
:Enter_City
When the query executes, Base uses the text following the colon as the label in the runtime input prompt.
Method 1: Creating a Parameter Query in Design View
To build a parameter query using the graphical interface:
Open your LibreOffice Base database file (
.odb).In the main database window, click Queries in the left pane, then select Create Query in Design View.
Add the tables or views needed for your query and close the Add Table or Query dialog.
Double-click or drag the required fields into the query grid.
Locate the field you want to filter and find its Criterion row.
Type a colon followed by your custom prompt name. For example, under a
Countryfield, enter::Enter_CountrySave the query and click the Run Query button (F5).
A Parameter Input dialog box will appear. Enter your value and click OK to view the filtered results.
Method 2: Creating a Parameter Query in SQL View
You can write parameter queries directly using SQL commands:
- Under the Queries tab, click Create Query in SQL View.
- Write your SQL statement, placing the parameter indicator in the
WHEREclause.
Exact Match Example
SELECT "CustomerID", "FirstName", "LastName", "City"
FROM "Customers"
WHERE "City" = :Enter_Target_City;Multiple Parameters Example
You can define multiple prompts within a single query by declaring distinct parameter names:
SELECT "OrderID", "OrderDate", "TotalAmount"
FROM "Orders"
WHERE "OrderDate" >= :Start_Date AND "OrderDate" <= :End_Date;Using Wildcards with Parameters
To allow partial matches (such as searching for names beginning with
a specific letter), combine the LIKE operator with string
concatenation using the parameter:
SELECT "FirstName", "LastName", "Email"
FROM "Employees"
WHERE "LastName" LIKE :Enter_Last_Name_Prefix || '%';When prompted, typing the letter S will return all
records where the last name starts with āSā.
Runtime Execution Behavior
- Dialog Prompt: LibreOffice Base parses the query,
detects all tokens prefixed with
:, and automatically generates a single input window listing each parameter name alongside a text field. - Data Types: Base automatically converts the runtime input into the expected data type based on the underlying table column definition (such as Date, Integer, or Text).
- Reusability: Forms and reports built on top of parameter queries will also prompt the user for input before loading the relevant dataset.