Toad for Oracle
Overview
Each data grid includes context menu items and a print dialog. The data grid is used in the SQL Editor, Schema Browser (Tables | Data and Views | Data),
SQL Modeler, and Master/Detail Browser.
Right-click menu
The right-click menu for the Data Grid provides numerous display, printing, and exporting options.
Popup Editor
The Popup Editor is for nested tables, objects, reference columns, bfiles, cursors,
LONG, CLOB, CHAR, or VARCHAR data type columns. Blob Edit is for LONG
RAW/BLOB data type columns. For example, for columns that are long (200 characters or more), when you double-click, a text editor displays. For date columns, a date picker is displayed where you can select a date from a calendar presentation.
To view and/or edit the contents of a large column Memo Edit
If the View | Options | Data Grids | Popup Memo Editor on
Double-Click setting is checked,
1.
Double-click a column to edit its value in the Memo Edit popup window.
– OR –
Right-click to display the right-click menu.
2.
Click the Popup Editor menu item.
3.
If you want to make changes to the data in the Memo Edit popup window, the resultset must be editable. Otherwise, the Memo Edit popup window is read-only.
Print Grid
This invokes the Print window.
108
Data Grids
Save Grid Contents
The Save As right-click menu item displays the Save Grid Contents window which contains format and file options.
Delimiters
Some programs require commas, which is a popular standard, to distinguish the data from one column to another column. The ASCII standard for dividing data is the <TAB> character.
Format radio buttons
Default - Tab Delimited
• ASCII, Comma Delimited - Divides data between columns with commas
• Tab Delimited - Divides data between columns with tabs
• Other Delim Char - You type the character you want to use as a delimiter
• HTML Table - Generates <TR></TR> and <TD></TD> HTML tags
(tags for table rows and columns) and puts the values between the tags
• Insert Statements - Saves the file with Insert statement. When exporting a data grid, it lets you supply the schema and table name.
If multiple tables were right-clicked from the Schema Browser, the schema and table names are filled in automatically.
• SQL Loader - Saves the file in SQL Loader format. The Output file contains both header and data information and is ready to be used by
SQL Loader.
• XLS File - Saves the file as an Excel file, supports "Include Nulls" option
• XLS Instance - Causes Toad to start up Excel if it is not running or connects to an instance of Excel if it is already running and copies the data to Excel. If Excel is already running when this feature is activated the data is created in a new sheet.
• XML Plain - Saves the file as an XML data file with no XSL style sheet
• XML (with XSL) - Saves the file in the old XML format
The options panel includes radio buttons for Insert, Truncate, Append, Replace, and text boxes for entering the Field Separator and the String Fields Enclosed by character.
109
Toad for Oracle
Other options include:
Double Quote Char (text) Columns
Default - Unchecked
If this option is checked, text will be enclosed in double quotes.
7369 "SMITH" "CLERK"7902
Include Column Headers
Default - Unchecked
If this option is checked, the column headers will be included in the text output.
Include NULL Text
Default - Unchecked
If this option is checked, the word NULL will be included for empty cells (cells that contain no information).
Zip resulting file(s)
Automatically zips the file.
You can save to File or Clipboard. If you save to file you can select to launch the file after it is created.
After you click OK, Toad will display a confirmation message that states the number of rows that were exported.
110
Data Grids
Select Columns - Row Numbers
Check or uncheck the columns you want to see. The Select Columns window includes a check box for Row Numbers. This lets you display or hide row numbers in the data grids.
To rearrange the order of the columns
1.
Select the column you want to move by clicking on its header in the grid.
2.
Drag the column(s) left or right as desired.
If after rearranging your columns, you copy the data to the clipboard, or save the data to a file, the data will be in the new column order.
To temporarily hide selected columns
1.
Select the Select Columns item from the right-click menu.
2.
Uncheck the columns you want to hide. They will NOT be included when you copy to clipboard or save to file.
This does NOT requery the data from the database. It just temporarily hides the columns.
111
Toad for Oracle
To set the column widths to a custom width setting
If you want to see more or less of a column,
• Move the mouse pointer to the grid headings, over the border between two columns, and drag it left or right.
If the columns of a query are the same from query to query, then Toad retains these custom column widths. You could add a WHERE clause, or an ORDER BY, etc., re-execute the query, and the column widths would remain the same.
If the columns of a query are different, then the grid columns will be sized according to the View | Options | Data Grids - Visual | Size columns to
the width of the headers, Size columns to the width of the data and Allow
columns to be less than the header width options.
Export to Flat File
When you Export to Flat File, you export data to an ASCII file without column delimiters. The spec file indicates start and end points for columns which you can edit.
On the Options tab select the table to export. You must set up the Specifications
File which will define the table name, table owner, how many lines in the output file will be covered by a single record of data, the columns of data, what line they will appear on, the starting column, and the length of each column of data.
Spec File tab
This is where you set up where your columns will begin and end.
Spec Filename
You can type in your filename or use the drill down to choose a target path.
Execute
This button exports the data to the file.
112
Data Grids
Save Spec File
This saves your specifications file and all your edits.
Generate Columns
This creates columns for your specifications file based on the DDL for the table, not the width of the actual table data.
Example of a specification file:
TABLENAME=EMPLOYEE
TABLEOWNER=DEMO
LINESPERRECORD=1
COL1=EMPLOYEE_ID,1,1,5
COL2=LAST_NAME,1,6,15
COL3=FIRST_NAME,1,21,15
COL4=MIDDLE_INITIAL,1,36,1
COL5=JOB_ID,1,37,4
COL6=MANAGER_ID,1,41,5
COL7=HIRE_DATE,1,46,22
COL8=SALARY,1,68,10
COL9=COMMISSION,1,78,10
COL10=DEPARTMENT_ID,1,88,3
The basic format for the column definition lines is:
COLx=COL_NAME,Output_row_num,Start Col,Num Columns
Flat File Export from Table window
You can also create a flat file from a table using the Database | Export |
Table as Flat File menu item. On the Options tab, you would select the schema and the table to export.
SQL Loader tab
This tab lets you set up the import parameters for the file that you are exporting so that you can later import it through Oracle SQL Loader.
113
Toad for Oracle
Find Data
The Grid Data Find window lets you search through selected columns for selected values or characters. You can specify whether you want the search case sensitive, and whether or not you want to have partial matches.
To find data
1.
From the right-click menu or from the main Grid menu select Find
Data. The Grid Data Find window displays.
2.
Select the Column you want to search.
3.
Enter the keyword or Value to find.
4.
Click the ADD button.
5.
Select the desired case sensitive and partial match options.
6.
Click OK.
Toad will search all records for the value and position the recordset to the first matching value. If the records are cached, the search is fast. If Toad needs to query ahead in the recordset, you'll have to wait for additional rows to be fetched from the database.
This dialog lets you enter a multiple column search criteria.
Example: ENAME = 'SMITH' AND JOB = 'CLERK'
You can press <F3> to find the next row with the specified value.
Duplicate Row
This item lets you copy an entire row.
114
Data Grids
To copy one row to create a new one
1.
Edit the recordset.
2.
Click in a cell of the row you want to copy.
3.
Select the Grid | Copy Row menu item (also accessible from the right-click menu).
4.
This copies the entire row to the bottom of the SQL Results grid ready for you to edit. NOTE: the recordset MUST be editable before
the Copy Row function will work.
5.
After you edit the cell contents, move to the row above in order for the row to be sent to Oracle. If you want to cancel from adding this row, press the <ESC> key.
Record Count
This displays a message window that shows the count of the number of records in the recordset. Record count is cancelable in the SQL Editor, the Schema
Browser, the Master/Detail Browser, and the SQL Modeler.
Set Sequence Field
This invokes the Set Sequence Column window which lets you apply a previously created sequence to the selected column on the data grid. After the sequence is applied, if you add a new record in the table and leave the sequenced column blank, Toad will auto-generate the next number in the sequence applied to the column. Columns with assigned sequences are displayed in aqua.
The following example uses Set Sequence Field.
Run the following scripts in the SQL Editor. They will create a table called
SEQ_TABLE with columns titled FIRST_NME, LAST_NME, and ID_NMR. It creates a Sequence called SEQA that starts with 1, increments by 1, and has a maximum value of 4.
DROP TABLE SEQ_TABLE CASCADE CONSTRAINTS ;
CREATE TABLE SEQ_TABLE (
FIRST_NME CHAR (20),
LAST_NME CHAR (20),
ID_NMR NUMBER (4) NOT NULL,
CONSTRAINT UNIQUEID
UNIQUE (ID_NMR))
CREATE SEQUENCE SEQA START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE
4 NOCACHE NOCYCLE NOORDER
115
Toad for Oracle
Next, you need to display the data grid for SEQ_TABLE. You can do this through the SQL Editor or the Schema Browser. For this example, use the Schema
Browser.
1.
From the Schema Browser | Tables list select the SEQ_TABLE. In the details panel click the Data tab. The cells are currently empty of data.
2.
Right-click in the data grid and select Set Sequence Field.
3.
The Set Sequence Column window displays.
4.
From the Sequence dropdown select SEQA. From the Column dropdown select ID_NMR.
5.
Click OK.
6.
Insert data in the record for FIRST_NME and LAST_NME.
7.
When you click the Insert Record button 1 is automatically entered
8.
Insert 3 more records of names.
The ID_NMR column populates with 2, 3, and 4.
9.
Try to Insert data for a 5th record. An error message displays.
"ORA-8004: sequence SEQA.NEXTVAL exceeds MAXVALUE and cannot be instantiated." This is because you set the maximum records of the sequence to 4.
You can then delete the extra record.
116
Data Grids
Fix Current Column
You can select and fix columns. Click in a column, right-click, and select Fix
Column to fix the selected column. The column(s) you select will be anchored to the left. The fixed columns remain locked to the left in view during horizontal scrolling. Once a column is fixed, other columns can be dragged into the fixed area. To move a column out of the fixed area click and drag it to the right of the bold horizontal fixed column divider bar. When you display Row Numbers they automatically display as fixed columns.
Preview Current Column
This displays a full row below each data row to show the value of the selected column. This is useful for viewing long varchar columns.
Remove Preview Column
This removes the Preview Column.
Allow Multi-Select
When this is checked, you can select more than one row by pressing <CTRL> and the rows you want to select. If you accidentally select a row you want to deselect, press <CTRL> and click the row and it will be deselected.
When Multi-Select is not checked, you can only select one row at a time.
Grid Options
This invokes the Data Grids - Visual page which contains numerous display options including fonts and column sizing. This is discussed in detail later in this chapter. The Font option is on the Data Grids - Visual page.
Size Columns
You have a choice of
• Size Columns to Data
• Size Columns to Headers
About Row Height
You can easily adjust the height of your rows by moving your mouse to the gutter (the left of the first column) and over a row divider line until you get the double arrow, then click-and-drag the row up or down to increase or decrease its height. The new height adjustment automatically applies to all rows in the table. Row height adjustment is useful for viewing varchar columns.
117