PL/SQL Developer 7.1 User`s Guide


Add to my manuals
222 Pages

advertisement

PL/SQL Developer 7.1 User`s Guide | Manualzz

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

Was this manual useful for you? Yes No
Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Related manuals

advertisement

Table of contents