dbcall
Calls a stored procedure in an external database via JDBC. You can define input and output parameters in the SQL statement using names that start with a colon (:).
Command properties
| Item | Description |
|---|---|
| Command type | Driver query |
| Required permission | None |
| License usage | Counted |
| Parallel execution | Not supported |
| Distributed execution | Not supported |
Syntax
Target
PROFILE- JDBC profile name. Can be specified as a query parameter. The JDBC profile must be registered in advance.
SQL- SQL statement for calling the stored procedure. Can include input and output parameters.
- Input parameters: Specify in the format
:name. The query parameter value set by thesetcommand is substituted. - Output parameters: Specify in the format
:name(type). Thetypemust be one ofvarchar,int, ordatetime.
Error codes
Parse errors
| Error code | Message | Description |
|---|---|---|
| 12000 | invalid-jdbc-profile | The specified JDBC profile does not exist. |
| 12001 | no-jdbc-permission | The current user does not have permission to use the JDBC profile. |
| 12002 | - | No query parameter is defined for an input parameter. This code is not registered in the global error message list, so the code string itself is shown as the message. |
Runtime errors
N/A
Description
The dbcall command connects to an external database registered as a JDBC profile and calls a stored procedure. You can define input and output parameters in the SQL statement using names that start with a colon (:).
Input parameters are specified in the format :name. The query parameter value set by the set command is substituted. String values are automatically enclosed in quotes, and numeric values are inserted as-is.
Output parameters are specified in the format :name(type). Supported types are:
varchar: Stringint: Integerdatetime: Date/time
The output varies depending on how the stored procedure returns results:
- When only output parameters are returned without a result set, one record composed of the output parameters is output.
- When both a result set and output parameters are returned, the output parameter fields are added to all records in the result set.
- When multiple result sets are returned, all result sets are output sequentially.
If the JDBC profile name is exactly sonar, it is a profile reserved for internal system use, so it is always blocked regardless of the execution path. If you need to temporarily allow it for maintenance, incident response, or another operational purpose, set the boot switch logpresso.sonar.allow_system_profile to true (default: not set, blocked).
Examples
-
Calling a stored procedure
dbcall mydb {call sp_get_users()}Calls the
sp_get_usersstored procedure using themydbJDBC profile and outputs the result set. -
Calling a stored procedure with input parameters
set dept="sales" | dbcall mydb {call sp_get_employees(:dept)}Sets the
deptquery parameter tosalesand calls thesp_get_employeesstored procedure with the parameter. -
Calling a stored procedure with output parameters
dbcall mydb {call sp_count_orders(:total_count(int))}Calls the
sp_count_ordersstored procedure and outputs a record containing the integer-type output parametertotal_count. -
Using both input and output parameters
set category="electronics" | dbcall mydb {call sp_category_summary(:category, :item_count(int), :total_amount(varchar))}Passes the
categoryinput parameter and outputs a record containing theitem_countandtotal_amountoutput parameters.
Change history
The dbcall command has been available since before Sonar 4.0.