Overview
Bind variables (also called parameters) allow you to create dynamic, reusable queries with values that can be supplied at runtime. This feature improves query performance, security, and maintainability.Benefits of Bind Variables
Performance
- Query plans are cached and reused
- Reduces parsing overhead
- Improves database performance
Security
- Prevents SQL injection attacks
- Safely handles user input
- Automatic escaping of special characters
Reusability
- Same query with different values
- Create query templates
- Share parameterized queries
Basic Syntax
Colon Notation
Standard Oracle bind variable syntax:Named Parameters
Use descriptive parameter names:Using Bind Variables
Interactive Input
When you execute a query with bind variables:- Koala detects all parameters
- Opens input dialog
- Enter values for each parameter
- Query executes with supplied values
Input Dialog Features
The parameter input dialog provides:- Parameter Name: Clear identification
- Data Type: Automatic type detection
- Default Values: Previously used values
- Validation: Type and format checking
- Help Text: Optional descriptions
Parameter Types
String Parameters
:last_name
→ ‘Smith’:email_pattern
→ ’%@oracle.com’
Numeric Parameters
:min_amount
→ 1000.00:max_quantity
→ 50
Date Parameters
- ‘YYYY-MM-DD’
- ‘DD-MON-YYYY’
- ‘MM/DD/YYYY’
Boolean Parameters
- ‘TRUE’ or ‘FALSE’
- ‘1’ or ‘0’
- ‘Y’ or ‘N’
Advanced Features
Default Values
When you execute a query with bind variables, Koala will prompt you to enter values for each parameter. Previously used values are remembered and suggested as defaults.Common Usage Patterns
IN Clause with Multiple Values
For queries that need multiple values, you can use bind variables with IN clauses:Query Templates
You can create reusable query patterns with bind variables:Performance Considerations
Query Plan Caching
Bind variables improve performance:- Query plan generated once
- Reused for different values
- Reduces database load
- Faster execution
Best Practices
- Use bind variables for frequently changing values
- Don’t use for static values
- Name parameters clearly
- Group related parameters
Security Benefits
SQL Injection Prevention
Bind variables prevent injection:Data Sanitization
Automatic handling of:- Special characters
- Quotes and escapes
- Null values
- Data type conversion
Troubleshooting
Common Issues
”Invalid parameter value”
- Check data type matches column
- Verify format (especially dates)
- Ensure value within valid range
”Parameter not found”
- Check parameter name spelling
- Ensure colon prefix (
:param
) - Verify parameter is used in query
”Too many bind variables”
- Oracle limit: 65,535 per query
- Simplify complex queries
- Use temporary tables for large datasets
Integration with Query History
When you use bind variables:- Parameters are saved with query history
- Previous parameter values are remembered
- You can recall and reuse parameterized queries