Oracle template variables
Use template variables to create dynamic, reusable dashboards. Instead of hard-coding details such as server names, applications, or regions in your queries, you can use variables that appear as drop-down selectors at the top of the dashboard.
Before you begin
Supported variable types
Create a query variable
To create a query variable:
- Navigate to Dashboard settings > Variables.
- Click Add variable.
- Select Query as the variable type.
- Select the Oracle data source.
- Enter a SQL query that returns the values you want as variable options.
For detailed instructions, refer to Add a query variable.
Query examples
An Oracle variable query returns column values that populate the variable drop-down.
Single column
Return all values from a single column:
SELECT hostname FROM hostMultiple columns
A query can return multiple columns. Grafana creates a combined list from all returned columns:
SELECT host.hostname, other_host.hostname2
FROM host
JOIN other_host ON host.city = other_host.cityKey/value variables
Return two columns named __text and __value to create a variable where the display name differs from the stored value. The __text column values must be unique:
SELECT hostname AS __text, id AS __value
FROM hostTime-dependent variables
To use time range macros like $__timeFilter(column) in your variable query, set the variable refresh to On Time Range Change:
SELECT event_name
FROM event_log
WHERE $__timeFilter(time_column)Chained variables
Create nested variables by referencing one variable inside another. For example, create a region variable, then use it to filter a hosts variable:
SELECT hostname
FROM host
WHERE region = '$region'Use variables in queries
Reference variables in your Oracle queries using the $variable or ${variable} syntax.
Multi-value variables
If a variable allows multiple selections, use the IN operator instead of =:
SELECT *
FROM host
WHERE hostname IN ($hostname)Grafana interpolates multi-value variables as single-quoted, comma-separated values (for example, 'host1','host2','host3').
Variable syntax reference
For the full variable syntax including advanced formatting options, refer to Variable syntax.


