Overview
On the Database Management page of OceanBase Developer Center (ODC), click Workspace in the top navigation bar and click SQL Window in the drop-down list that appears.
The SQL window provides an SQL editing area for editing scripts, an execution record tab, and a result tab for displaying the execution results. The SQL window also supports executing PL statements.
SQL editing area
The SQL editing area provides many features for you.
Feature | Description |
Auto-complete | The SQL editing area provides the auto-complete feature to improve your SQL statement editing efficiency. For example, when you edit SQL statements, the table name is auto-completed for cross-database queries. |
Intelligent identification of keywords and code | Database keywords are highlighted in different colors, and PL/SQL statements are identified. |
Right-click of object names in the | When you right-click the name of a table, view, or function in a |
Object drag-and-drop | You can directly drag an object from the object list and drop it into an SQL statement in the SQL editing area to fill in the object name in the statement.
|
Independent sessions | You can click + to add multiple SQL windows in one connection. |
Identification of abnormal special symbols | Abnormal special symbols can be identified and marked with yellow wavy underlines in the editing area of the SQL window. |
Viewing the execution status | When you hover the pointer over an SQL window tab, the window name and execution status are displayed. |
In Oracle mode, the autocommit feature of ODC is set to OFF by default. You can change the transaction commit mode by modifying the value of the
autocommit
variable in the following two ways: click the Settings icon in the upper-right corner of the SQL window and modify the variable in the Session Variables dialog box, or click Session in the top navigation bar and modify the variable on the Session Properties page. Note that the settings in the Set session variable dialog box are valid only for the current SQL window. For more information, see Session management.In manual-commit mode, make sure to set
ob_trx_idle_timeout
to a value greater than the timeout value of SQL queries. Otherwise, if two SQL statements in one transaction are executed at an interval longer than the value ofob_trx_idle_timeout
, the connection will be terminated. However, if theob_trx_idle_timeout
parameter is set to an excessively large value, the session cannot be released in time, resulting in unnecessary memory consumption. Therefore, you must set this parameter to a proper value.
In addition to the preceding features, the toolbar of the editing area provides buttons that implement the following features.
Feature | Description |
Run | Click this button to execute all the SQL statements in the current window. This button is disabled if an SQL statement is being executed in another window of the same session. |
Run the current statement | Click this button to execute all the selected SQL statements or the SQL statement in the line where the pointer is located. This button is disabled if an SQL statement is being executed in another window of the same session. |
Abort | Click this button to abort the statement that is being executed. |
SQL Check | Click this icon to check SQL syntax. |
Execution plan | Click this button to view the execution plan for the SQL statement that you select or on which the pointer is located. This execution plan is estimated by the system before execution and is the result of the Click Execution Plan. On the Plan Details tab, click View Formatting Info to go to the format page. |
Find and Replace | Click this icon and enter text in the search field to find the specific content and enter text in the replacement field to replace the content found. |
Undo | Click this button to undo the last operation. |
Redo | Click this button to reverse an Undo operation. |
Format | Click this button to apply formatting, such as indentation, line break, and keyword highlighting, to the selected SQL statements or all the SQL statements in the current SQL window. |
IN value conversion | Click this button to convert the copied rows or columns into the specified format during queries. After you paste the copied data to the SQL editing area, select the copied data and click IN Value Conversion to convert it into the in('A','B') format.
|
Case Sensitivity | The system supports three configurations: All Caps, All Lowercase, and Capitalize First Letter. Click this icon to convert the selected statements in the script to the corresponding capitalization format. |
Indent | You can add indents to or delete indents from the selected statements in the script. |
Comment | You can click Add Comments to convert the statements that you select into comments or click Delete Comment to convert comments to SQL statements. |
Save script | Click this button/use the shortcut key Ctrl+S to save the script in the current window. Click this icon to save the script in the current window. You can open a saved script when you enter the workspace again. You can view only the SQL scripts saved by yourself. The script names must be unique. After you open a stored script, you can continue to edit it. |
Settings |
|
Snippets | Click this button to view and reference built-in and custom code snippets. For more information, see Snippets. |
Commit |
|
Rollback |
|
Execute a PL statement
You can edit a PL statement in the SQL window. Note that you must end the PL statement with the specified delimiter.
At present, you can use the following methods to specify a delimiter in ODC:
Click Settings in the toolbar of the SQL editing area. In the window that appears, select the required delimiter in the Delimiter field.
On the Personal Settings page, select a required delimiter in Delimiter Settings.
Right-click the PL object in the left navigation bar and select Run, which supports setting the parameter value as DEFAULT, NULL or empty string.
ImportantIn ODC V2.4.1 and later versions, you can use the
DELIMITER
statement in the editing area to define a delimiter. In Settings, the Delimiter field displays the delimiter that you specified.You can directly use forward slashes (/) to separate PL statements. However, if a PL statement contains any forward slashes, you still need to set a custom delimiter.
After you execute the PL statement in the SQL window, the result tab displays the database management system (DBMS) output.
Record tab
On the Record tab, you can view the history of SQL statements executed in the current connection. It includes Status, Time, SQL Statement, Results, TRACE ID, Time Spent, and Execution Details. Execution Details is the execution plan.
Column | Description |
Check box | You can select the check box in front of the record list and click Delete in the upper-right corner of the list to delete multiple execution records at a time. |
TRACE ID | The ID of the execution record. Important If TRACE ID is empty, make sure that the system parameter enable_sql_audit and the variable ob_enable_trace_log are both set to ON when the statement is executed. You can take the following steps to turn on the variables:
|
Time Spent | Time Spent of an SQL statement in ODC is divided into the following three parts:
You can move the pointer over the icon next to Time Spent. The time spent on executing an SQL statement is displayed in three sections in the tooltip. |
Execution Details | By default, the execution plan is displayed in text. In the Execution Details column, click View. The Execution Details page displays the basic information, time spent, I/O statistics, and executed SQL statements. |
Logs tab
You can view the execution records of the current SQL window on the Logs tab.
Results tab
You can view the execution result of the current SQL statement on the Results tab. The result set on the Results tab can be used in the following interactive operations to facilitate daily development work.
Operation | Description |
Select required data | You can select the required data of a result set and copy the data to an external file by using hotkeys. You can also click a field name or row number to select an entire row or column. You can also click Export in the toolbar to export data of a result set to a local file. |
Select rows and columns |
|
Right-click a cell | You can right-click a cell and choose Copy Row, Copy, or Export to Clipboard to directly export the data into an external file. |
Right-click a row ID | You can right-click a row ID and choose Copy Row, Freeze this row, Unlock all frozen rows, or Export to Clipboard.
|
Zoom in | If the data in a cell is too long to be displayed in full, you can perform the following operations to view the data in full:
|
View BLOBs |
|
Right-click the tab name of a result tab | For example, you can right-click the tab name of the Results 1 tab and click Pin in the context menu to pin the tab, so that it remains displayed. In this way, when you execute a new query, a new result tab appears but does not overwrite the pinned result tab. This allows you to compare the query results. Click Unpin to unpin a result tab. |
Filter, sort, and search for data | Each field name in the result set is provided with a filter icon, a sort icon, and a search icon. You can use them to filter, sort, and search for data in a single column. |
Drag the column name | You can adjust the order of fields by dragging column names in a result set. |
Adjust the column width | You can adjust the column width by dragging the column edge. |
The field type and remarks information displayed in the status bar | Click a field in the result set, and the status bar at the bottom supports displaying specific information such as the type and remarks of the field. |
The navigation bar of the Result tab also provides the following tools.
Feature | Description |
Column mode | Click this button to display the selected data row in the form of a table. On the Column Mode page, you can switch to the previous or next row. Column mode makes it easier to view data in a row that has many columns. To view data in column mode, perform the following steps:
|
Columns | Click this button to select the columns to be displayed on the page. |
Back to start | Click this button to go to the first page. |
Previous | Click this button to go to the previous page. |
Next | Click this button to go to the next page. |
Jump to bottom | Click this button to go to the last page. |
Search | Enter a keyword in the search box to search for the desired results. |
Edit | Click Edit to enable editing mode for the current result set. The editing mode supports the following operations: Add, Copy Current Row, Delete, Cancel, Confirm Modification, which commits a transaction when auto-commit is enabled, and Modify and Submit, which is displayed when auto-commit is disabled. In the editing mode, you can either double-click target data to directly modify it or click the preceding buttons for convenient operations. When you edit a cell, you can right-click the cell and choose Copy or Set to Null from the context menu to operate on the cell. Note The ResultMetaData is obtained during the execution of an SQL statement to indicate whether the result set can be edited.
|
Download Data | You can export the query results to a CSV, SQL, or Excel file.
Note
|
Plan | Click this button to view the actual resource consumption and execution plan of an executed SQL statement. This allows you to evaluate the performance of the statement. |