advertisement
PL/SQL Developer 7.1 User’s Guide 189
20. The Query Builder
The Query Builder allows you to create and modify select statements in your PL/SQL and SQL source files. It provides a simple point and click interface to build the field list, the table list, where clause and order by clause of the select statement.
20.1 Creating a new select statement
For this example we will assume that we want to create a join statement between the dept and emp table, and show some columns from both tables: select e.empno, e.ename, d.deptno, d.dname from emp e, dept d order by e.empno
To create a new select statement, place the editor cursor at the text position where you want it to be inserted, and press the Query Builder button on the toolbar (or select the Query Builder item from the
Tools menu). This will bring up an empty Query Builder Form:
On the left side you see an Object Browser with just the tables and views. On the right you see the work area, which is empty right now. At the bottom you see 3 panels with the field list (and optionally the into item list), the where clause and the order by clause. The bottom section contains a tab page that allows you to switch to the actual SQL text that would be created from the current query definition.
At the top of the window you see a toolbar with a New button to create a new query, an Open button to open a previously saved query definition from a file, a Save button to save the current query definition to a file, a Parse button to parse the current query definition, and a Preferences button. The OK button returns you to the PL/SQL or SQL Editor and inserts the SQL text you have built.
190 PL/SQL Developer 7.1 User’s Guide
To include tables or views in the select statement, drag them from the Object Browser into the work area. Each time you add a new table, the Table Properties dialog appears:
Here you can enter an alias for the table. For our example we wanted to use ‘e’ for the emp table:
After adding the Dept table in the same way, you are asked if you want to join the 2 tables using the columns of the foreign key named EMP_FOREIGN_KEY:
After checking this option, you will see the new join condition in the bottom half of the form.
PL/SQL Developer 7.1 User’s Guide
Now the Dept table is added, and the join condition is visualized in the work area:
191
What we need to do now is include the columns in the field list of the select statement. Just click on the checkbox next to the column names. The columns will be displayed in the Fields panel:
If you want to create a PL/SQL select .. into statement, you would also need to specify the items for the
Into list next to the fields. The selection list will display the PL/SQL variables that are defined in the
PL/SQL code where you insert the statement. In this case we do not want to create an Into list, so we can leave these items empty.
192 PL/SQL Developer 7.1 User’s Guide
To create the order by clause, drag the empno column to the Order By panel:
Now you can press the OK button to insert the SQL statement into the editor.
20.2 Modifying an existing select statement
To modify an existing select statement in your PL/SQL or SQL source code, simply right-click on the select statement and select the Query Builder item from the popup menu. The complete select statement will be marked in the editor, and the Query Builder will be displayed. Now you can change the query definition as described in the previous chapter.
20.3 Manipulating the query definition
The following paragraphs describe how you can manipulate the query definition.
Changing the field list
To add a field from a table in the work area to the query, you can click on the checkbox next to the column, or you can drag the column to the field list. You can alternatively double-click on the column if the field list has the focus.
You can also drag a column or column folder directly from the Object Browser to the field list. Column folders are located under the table, its constraints and its indexes.
You can type column names and other expressions directly in the field list.
To delete a field from the field list, right click on it and select Delete selected items from the popup menu. If you select multiple fields, you can remove them all at once.
You can move fields to a different position by selecting them, and dragging them to their new position.
If you want a distinct result set, check the corresponding option above the field list.
Using field aliases
To use an alias for a field, simply type the alias after the expression, just like you would do if you were typing the select statement by hand.
PL/SQL Developer 7.1 User’s Guide 193
Changing the where clause
The where clause is a normal text editor, where you can enter the conditions. To include a column, you can drag it from the table in the work area, or you can double-click on the column if the where clause has the focus.
To add a join condition based on a foreign key constraint definition, right-click on the table in the work area and select the Foreign keys item from the popup menu. You cannot use this function to remove an existing join condition, but need to remove the text in the editor instead.
Changing the order by clause
The order by clause can be manipulated in the same way as the field list, except that you cannot use the checkboxes next to the column names. To change an item between ascending and descending order, you can click on the button next to the item, which will display a corresponding arrow.
Using a synonym for a table or view
To use a table or view through a synonym, right-click on the work area and select the Add Table item from the popup menu. Type the synonym name in the Name property, provide an alias if necessary, and press the OK button.
20.4 Query Builder Preferences
By pressing the Preferences button on the toolbar, you can change the behavior of the Query Builder.
The following form will appear:
Most of these preferences affect the layout of the generated select statement:
Keyword case
Determines how the SQL keywords (select, from, into, where, order by) are inserted into the generated SQL statement.
Item case
Determines how the items (table names, column names) are inserted into the generated SQL statement.
Keyword alignment
Determines whether the SQL keywords are right or left aligned.
194 PL/SQL Developer 7.1 User’s Guide
Comma separator
Determines whether commas are placed before the next item, or after the current item. This is primarily of interest if the Single item per line option is enabled.
‘AND’ separator
Determines whether the ‘AND’ operator is placed before the next condition, or after the current condition in the where clause.
Always prefix table with owner
When enabled, table names are prefixed with the owner (e.g. scott.emp instead of emp). When disabled, tables are only prefixed with the owner if they are not owned by the current user.
Keywords on separate line
When enabled, a SQL keyword is placed on a separate line and all items are placed on subsequent lines with a 2 character indent. If this option is disabled, the items will immediately follow the keyword on the same line.
Single item per line
When enabled, each item will be placed on a new line. When disabled, items will be placed on a single line, until the Right margin is reached.
Right margin
Determines the maximum length of each line when the Single item per line preference is disabled.
Always show table property editor
When this option is enabled, the table property editor will always be displayed after adding a new table to the query definition. When this option is disabled, the property will only be displayed if the newly added table is already used in the query, and therefore needs to have an alias.
Display SQL parts on a single page
Determines if the 3 SQL parts (Field list, Where clause, Order By clause) are displayed on a single page. If this option is disabled, each part is displayed on a separate tab page, next to the tab page of the SQL text.
20.5 Query Builder Plug-Ins
If a Query Builder Plug-In is installed, then the standard Query Builder function will invoke the Plug-
In. Right-clicking on the Query Builder button allows you to select a query builder from a list of all installed query builders. The most recently used query builder will be invoked by default when you subsequently use the Query Builder function again.
advertisement
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Related manuals
advertisement
Table of contents
- 3 Contents
- 9 Introduction
- 13 Installation
- 13 System requirements
- 13 Workstation installation
- 13 Server based installation
- 14 Scripted installation
- 14 Uninstalling PL/SQL Developer
- 15 Writing programs
- 15 Creating a program
- 16 Saving a program
- 17 Modifying a program
- 17 Compiling a program
- 18 Substitution variables
- 19 Testing programs
- 19 Creating a Test Script
- 20 Executing a Test Script
- 21 Variable types
- 22 Saving Test Scripts
- 23 Tracking run-time errors
- 23 Package states & Java session states
- 23 Viewing result sets
- 23 Viewing dbms_output
- 24 Viewing HTP output
- 24 Debugging
- 27 Tracing execution
- 28 Regression testing
- 29 Optimizing
- 29 Using the Explain Plan Window
- 30 Automatic statistics
- 31 The PL/SQL Profiler
- 32 SQL Trace
- 34 Ad hoc SQL
- 34 Using the SQL Window
- 35 Result grid manipulation
- 39 Query By Example mode
- 40 Linked Queries
- 40 Substitution variables
- 41 Updating the database
- 42 Viewing and editing XMLTYPE columns
- 42 Direct Query Export
- 42 Saving SQL Scripts
- 43 Creating Standard Queries
- 44 The Command Window
- 44 Entering SQL statements and commands
- 45 Developing command files
- 46 Supported commands
- 49 Creating and modifying non-PL/SQL objects
- 49 The table definition editor
- 60 The sequence definition editor
- 60 The synonym definition editor
- 61 The library definition editor
- 61 The directory definition editor
- 62 The job definition editor
- 62 The queue definition editor
- 63 The queue table definition editor
- 64 The user definition editor
- 67 The role definition editor
- 68 The profile definition editor
- 68 The database link definition editor
- 69 Diagrams
- 69 Creating a diagram
- 71 Saving and opening a diagram file
- 71 Updating a diagram
- 72 Reports
- 72 Standard reports
- 73 Custom reports
- 74 Variables
- 77 Refining the layout
- 84 The Style Library
- 84 Options
- 86 The Reports menu
- 87 Graphics
- 89 Projects
- 89 Creating a new project
- 89 Saving a project
- 90 Adding files to a project
- 90 Adding database objects to a project
- 90 Working with project items
- 91 Compiling a project
- 92 To-Do Items
- 93 Creating a To-Do Item
- 93 Editing a To-Do Item
- 94 Closing a To-Do Item
- 94 Deleting a To-Do Item
- 95 Windows, database sessions and transactions
- 95 Session mode
- 95 Execution in Multi session or Dual session mode
- 96 Browsing objects
- 96 Using the Browser
- 101 Browser Filters
- 102 Browser Folders
- 104 Preferences
- 105 Oracle – Connection
- 106 Oracle – Options
- 107 Oracle – Debugger
- 108 Oracle – Output
- 109 Oracle – Trace
- 109 Oracle – Profiler
- 110 Oracle – Logon History
- 111 Oracle – Hints
- 113 User Interface – Options
- 115 User Interface – Toolbar
- 115 User Interface – Browser
- 117 User Interface – Editor
- 120 User Interface – Fonts
- 121 User Interface – Code Assistant
- 122 User Interface – Key Configuration
- 123 User Interface – Appearance
- 124 User Interface – Date/Time
- 125 Window Types – Program Window
- 127 Window Types – SQL Window
- 129 Window Types – Test Window
- 129 Window Types – Plan Window
- 129 Tools – Differences
- 130 Tools – Data Generator
- 131 Tools – To-Do List
- 131 Tools – Recall Statement
- 132 Files – Directories
- 133 Files – Extensions
- 134 Files – Format
- 134 Files – Backup
- 135 Files – HTML/XML
- 136 Other – Printing
- 137 Other – Updates & News
- 138 Preference sets
- 140 Tools
- 140 Browser
- 140 Find Database Objects
- 141 Compile Invalid Objects
- 142 Export Tables
- 145 Import Tables
- 147 Export User Objects
- 148 Text Importer
- 151 ODBC Importer
- 153 Data Generator
- 156 Compare User Objects
- 158 Compare Table Data
- 160 Event Monitor
- 161 Sessions
- 163 User Defined Tools
- 167 Test Manager
- 170 The Editor
- 170 Selection functions
- 170 Column selection
- 171 Code Assistant
- 172 Recalling statements
- 172 Special Copy
- 173 Context sensitive help
- 174 Database object popup menu
- 174 Explain Plan
- 174 Macros
- 175 Bookmarks
- 176 Color marks
- 177 Code Contents
- 178 Code Hierarchy
- 179 Code Folding
- 179 Split Editing
- 180 Hyperlink navigation
- 180 Navigation buttons
- 181 Refactoring
- 181 Search Bar
- 183 The Large Data Editor
- 184 Editing plain text
- 184 Editing RTF
- 185 Editing XML
- 186 Editing images
- 186 Editing Hex data
- 187 Invoking an external viewer or editor
- 189 The Query Builder
- 189 Creating a new select statement
- 192 Modifying an existing select statement
- 192 Manipulating the query definition
- 193 Query Builder Preferences
- 194 Query Builder Plug-Ins
- 195 The PL/SQL Beautifier
- 195 Defining the options
- 196 Defining the rules
- 197 Using the beautifier
- 198 Templates
- 198 The Template Window
- 199 Using a template
- 200 Creating and modifying templates
- 205 Window List
- 206 Dockable and Floating Tools
- 207 Authorization
- 207 Enabling authorization
- 208 Defining authorization
- 209 Disabling authorization
- 210 Oracle File System (OFS)
- 210 OFS Manager
- 212 OFS Usage
- 214 Help systems
- 214 MS Help files
- 214 HTML Manuals
- 218 Customization
- 218 Preferences
- 218 Window layout
- 218 On-line documentation
- 220 Command-line parameters
- 222 SQL, PL/SQL, Command, Java and XML keywords
- 222 Plug-Ins