• No results found

Data Tool Platform SQL Development Tools

N/A
N/A
Protected

Academic year: 2022

Share "Data Tool Platform SQL Development Tools"

Copied!
33
0
0

Loading.... (view fulltext now)

Full text

(1)

Data Tool Platform SQL Development Tools

ekapner

(2)
(3)

Contents

Setting SQL Development Preferences...5

Execution Plan View Options Preferences...5

General Preferences...5

Label Decorations Preferences...6

SQL Editor Preferences...6

Code Assist Preferences...7

SQL Files/Scrapbooks Preferences...7

Syntax Coloring Preferences...7

Templates Preferences...8

SQL Query Builder Preferences...8

SQL Results View Options Preferences...9

Export Format Options Preferences...9

History Options Preferences...10

Result Set Viewer Preferences...10

SQL Query Builder...12

Creating a SELECT Statement...12

Creating a FULLSELECT (UNION) Statement...13

Creating a WITH Statement...14

Creating Joins...15

Creating an INSERT Statement From a Values Set...16

Creating an INSERT Statement From a Subquery...16

Creating an UPDATE Statement...17

Creating a DELETE Statement...18

Building Expressions...19

Expression Types...19

Editing a SQL Statement...20

Running the SQL Statement Code...21

Creating a SQL File...22

SQL File Editor...22

SQL Scrapbook...22

Editing a SQL File...23

Opening a SQL File...23

Saving a SQL File...23

Executing a SQL Statement...24

Running an Ad Hoc SQL Statement...25

Executing a SQL File...26

Running a Routine Object...27

Creating a Launch Configuration for Routine Objects...27

Routine Objects...28

Viewing SQL Results...30

(4)

SQL Results View...30

Terminating Execution in SQL Results View ...31

Exporting SQL Execution Results...32

Saving Execution Results to a Project...32

Removing Results from SQL Results View...33

Saving SQL Results History...33

Filtering SQL Results History...33 Contents

(5)

Setting SQL Development Preferences

Set SQL Development preferences for label decorations, execution plans, SQL Editor, SQL Query Builder, and SQL Results view.

1. Select Window > Preferences from the main menu bar.

2. In the left pane, under Data Management, expand SQL Development.

Execution Plan View Options Preferences

Set execution plan view options to specify defaults for viewing query plans.

Table 1. Execution plan view options Description

Property

Select Vertical Orientation to display the plan from top to bottom.

Select Horizontal Orientation (default) to display the plan from left to right.

SQL Execution Plan View Orientation

Specify the output encoding. The default is Cp1252.

Cp1252

ISO-8859-1

US-ASCII

UTF-16

UTF-16BE

UTF-16LE

UTF-8 Export Encoding

General Preferences

The general user preferences concern executing and debugging procedural objects.

Table 2. General preferences Description

Property

Displays the Press F2 for focus message in hover help (ToolTips). If you make a hover message sticky, the message text opens in a scrollable window from which you can select and copy content.

Show Affordance in Hover on How to Make it Sticky

Select the action to be taken on an error during SQL execution.

Always — always continues execution when an error occurs.

Never — always stops execution when an error occurs.

Prompt — interrupts execution on each error, displaying a dialog to resume execution (default).

SQL Error Execution Action

Setting SQL Development Preferences

(6)

Label Decorations Preferences

Set label decorations preferences to set the display format of objects appearing in the Database Development perspective.

Table 3. Label decorations: Text tab Description

Property

Specify the display format for table columns. Select Add Variables to add a variable to the format.

Column format

Displays an example of the selected format.

Example

SQL Editor Preferences

SQL Editor preferences define the behavior of the SQL File Editor.

Table 4. SQL Editor preferences: General Description

Field

Automatically update SQL statement structure in outline view and perform syntax validation while editing (default).

Disabling validation also disables portability checking and the Outline view.

Enable Syntax Validation

Database type used as the standard target for portability checks. You must enable syntax validation to select a portability target.

Each line that is not portable to the target is annotated with a check . You can display additional information for the target (including error messages) by moving your cursor over the marker, if you enable show detailed annotation information.

Portability Check Target

Disable syntax validation when content exceeds this number of lines. Use this option to adjust editor performance. The default is 1000.

Maximum Number of Lines

Select to prompt before disabling validation (default).

Prompt to Disable Syntax Validation When Content Exceeds Maximum Number of Lines

Display additional annotation information, including lists of expected commands for the encountered syntax, if you enabled syntax validation.

Show Detailed Annotation Information

Table 5. SQL Editor preferences: Typing Description and default values Field

Automatically close single quotes ( ').

Close Single Quotes

Automatically close double quotes ( ").

Close Double Quotes

Automatically close curly braces { }.

Close Parentheses

Automatically close comments ( /* */).

Close Comments

Setting SQL Development Preferences

(7)

Description and default values Field

Automatically add the END statement (for Transact-SQL).

Begin-End

Code Assist Preferences

SQL Editor Code Assist preferences define the behavior of the Code Assist feature in SQL File Editor.

Table 6. Code Assist preferences Explanation Field

Insert single proposals (default).

Insert Single Proposals Automatically

Display system tables when applicable.

Show System Tables

Display system views when applicable.

Show System Views

Display system procedures and functions when applicable.

Show System Procedures and Functions

Display the owner.

Show Owner of Table or View

Invoke Code Assist automatically (default).

Enable Auto Activation

Specify the time in milliseconds that must elapse after you type a character before Code Assist is automatically invoked. Default is 500.

When you enter a character and pause before entering another character, Code Assist automatically displays a menu of keywords you can select to complete the SQL statement.

Auto Activation Delay

Enter characters that automatically activate Code Assist.

Enter characters in any order with no separator character.

When you type these characters, the Code Assist menu displays after the auto activation delay unless you enter another character.

Auto Activation Triggers for SQL

SQL Files/Scrapbooks Preferences

SQL files and scrapbooks preferences define the behavior of SQL files in SQL File Editor and SQL Scrapbook.

Table 7. SQL Files/Scrapbooks preferences Description

Field

Select a connection type, connection profile name, and database to use by default in new SQL File Editor or SQL Scrapbook sessions.

Default Connection Information for New SQL Files/Scrapbooks

Use the same target connection information for multiple files.

Persist the Target Connection Information When Executing Multiple SQL Files

Syntax Coloring Preferences

Indicate your preferences for syntax coloring for SQL source code in SQL File Editor or SQL Scrapbook.

Setting SQL Development Preferences

(8)

Table 8. Syntax Coloring preferences Description Field

Select a syntax item and then click the color box and/or select a style check box to determine how that item type is rendered in the editor.

Syntax Items

Displays an example of the syntax coloring choices.

Preview

Templates Preferences

You can create new SQL templates and edit existing ones.

Templates make code generation more convenient by allowing you to insert frequently recurring source code patterns into your projects in SQL Editor.

Table 9. SQL Editor template preferences Description

Field

Displays the existing templates in your workspace. Displayed information includes the name, context, description, and status of the auto-insert attribute.

Create, Edit, or Remove Templates

Displays the first few lines of the SQL template.

Preview

Create a new template. New templates are added to the list.

New

Edit the selected template.

Edit

Deletes all selected templates.

Remove

Restores removed default templates.

Restore Removed

Reverts the selected template to its default state.

Revert to Default

Imports templates into your workspace from the file system.

Import

Exports all selected templates to a specified location in the file system.

Export

SQL Query Builder Preferences

Indicate the SQL Query Builder preferences.

Table 10. SQL Query Builder preferences Description

Field

Select to indicate that the table references qualified by the current schema become unqualified in the SQL code.

Omit Current Schema in Generated SQL Statement

If you omit the current schema, select its replacement:

Authorization ID — uses the user name from the connection profile. The table references are qualified using the current schema name.

Schema Name — enter the schema to use as the current schema.

Current Schema

Setting SQL Development Preferences

(9)

SQL Results View Options Preferences

The SQL Results view preferences determine the behavior of the SQL Results view.

Table 11. SQL Results view options Explanation

Field

Select a window display style:

Single Window — display execution results in a single window, with status details at the end. For a single statement with multiple results, display result sets one after another in the same window.

Multiple Windows — display execution status and each result for the current statement in a separate window.

Display Window

Select a results display mode:

Text Mode — similar to iSQL output when in single-tab mode.

Grid Mode — similar to the Interactive SQL window.

Display Mode

Show column headings in the results view.

Show Column Headings

Show row numbers in results view.

In text mode, this property is always enabled.

In grid mode, this property is selected by default.

Show Row Number

Show number of rows affected.

In text mode, this property is always enabled. Row count appears at the end of the results.

In grid mode, this property is selected by default. Row count appears in the Status window.

Show Row Count Message

Enter the number of rows to retrieve from the result set. The default is 0 (retrieve all rows).

Set a maximum to improve performance when testing queries and to avoid running out of memory when retrieving data from very large tables, for example, tables with a hundred million rows.

Max Row Count

Enter number of rows to display in the results view.

To see all results, set Maximum Rows to Retrieve to 0, and then save to a file.

Max Display Row Count

Enter characters to display when the value is NULL. Default is NULL.

Display Null Value As

Split messages among more than one tab.

Split All Messages Into Multiple Message Tabs

If you selected Multiple windows for the Display Window preference, enter a maximum number of tabs.

Limit Tabs Number to

If you selected Single window for the Display Window preference, enter a maximum number of visible tables.

Limit Visible Tables Number to

Export Format Options Preferences

Set export format options for the XML format, column delimiters, and encoding.

Setting SQL Development Preferences

(10)

Table 12. Export Format Options preferences: General Description

Field

Insert the XML header string automatically at the beginning of each XML file.

Add XML Header Automatically

Enter the header string to be inserted at the beginning of the XML file, for example, <?xml version="1.0" encoding="UTF-8"?>.

XML Header

Include the contents of the SQL result enclosed in a root tag you specify in the Root Tag field.

Add XML Root Tag Automatically

Enter the XML root tag to wrap the SQL results with, for example, resultsets. Do not include angle brackets.

Root Tag

Table 13. Export Format Options preferences: Default column delimiter Description

Field

Column Aligned — use the same-width font to display the result, and align each column, fill spaces between columns (default)

Comma Separated — use comma to separate columns

Tab Delimited — use tab to separate columns

User-defined — use user-defined string to separate columns Output Format

Displays the delimiter for the output format.

Delimeter

Table 14. Export Format Options preferences: Default output encoding Description

Property

ISO-8859-1 — ISO 8859-1 Latin 1.

US-ASCII — US ASCII, with 8-bit data, ISO 646.

UTF-16 — Unicode UTF-16.

UTF-16BE — Unicode UTF-16, big endian.

UTF-16LE — Unicode UTF-16, little endian.

UTF-8 (default) — Unicode UTF-8.

Default Output Encoding

History Options Preferences

Set history option preferences for the display of history in the SQL Results view.

Table 15. History options preferences Description

Property

Select the columns that comprise the history displayed in the SQL Results view: Status, Operation, Frequency, Date, Action Type, Consumer Name, and Connection Profile.

Columns to Display

Save the results history during shutdown; load the results history in the SQL Results view during startup.

Automatically Persist Result History

Result Set Viewer Preferences

Select the viewer to display SQL results.

Setting SQL Development Preferences

(11)

Table 16. Result Set Viewer preferences Description

Field

Select viewer from dropdown list.

Select Viewer

Setting SQL Development Preferences

(12)

SQL Query Builder

Create, edit, or run SQL statements using the SQL Query Builder graphical interface, which provides access to your database schema and objects so that you can quickly create or edit SQL statements without actually typing any SQL code. However, you also have the flexibility to add or modify the SQL code in the editor window.

The options in the SQL Query Builder change depending on the statement type you are building. By default, the statement type is SELECT.

Note: Some syntactic variations might exist between your database and the SQL syntax that SQL Query Builder supports; consequently, some SQL Query Builder features might not work with your database.

Creating a SELECT Statement

Use SQL Query Builder to create a SELECT statement to retrieve data from a database and display the results set in table format.

Prerequisites

Connect to the data source through a connection profile.

Note: Some syntactic variations might exist between your database and the SQL syntax that SQL Query Builder supports; consequently, some SQL Query Builder features might not work with your database.

1. Open a new or an existing SQL file, and be sure to select the connection profile Type, Name, and Database.

2. In an appropriate place in the editor window, right-click and select Edit in SQL Query Builder.

3. Add one or more tables to the statement.

a) Right-click in the Tables pane and select Add Table.

b) (Optional) Indicate a Table alias.

You might want to use a table alias to make the table name more readable or shorten it for display/output.

4. (Optional) If you added two or more tables, you can create a join.

5. (Optional) Select DISTINCT if you want only one instance each of duplicated rows returned in the final result set.

6. Specify the columns to use in the statement.

Description Option

Right-click the table in the Tables pane, and select Select All Columns.

Specify all columns

Use either method:

Specify specific columns

In the Tables pane, select the check box next to the column name.

In the Columns tab, select the specific column from the drop-down menu.

7. (Optional) Define other column attributes.

a) Specify a column alias.

You might want to use a column alias to make the column name more readable or shorten it for display/output.

b) Deselect Output if you do not want the column values to display in the results set but want to use it for some other purpose.

SQL Query Builder

(13)

For example, you might want to order the output by customer number but you do not want the customer number to display.

c) Change the Sort Type for each column.

By default, columns are sorted in ascending order.

d) Change the Sort Order.

By default, columns are sorted in the order they appear in the Columns table.

8. (Optional) In the Conditions tab, indicate the conditions for the statement.

The conditions enable you to better define which columns appear in the results set. For example, you might only want to list store locations with sales greater than $10,000.

a) Select a Column.

Alternately, select define a condition using the Expression Builder wizard.

b) Select an Operator.

c) Enter a specific Value, select a column from the drop-down list, or build an expression.

d) (Optional) Select AND or OR to specify another condition.

9. (Optional) In the Group tab, indicate on which column you want to group results.

For example, you might want to group the sum of all sales from each store.

10. (Optional) To limit the output based on the specified GROUP clause, add a Group Condition.

a) Select a Column.

Alternately, select define a condition using the Expression Builder wizard.

b) Select an Operator.

c) Enter a specific Value, select a column from the drop-down list, or build an expression.

d) (Optional) Select AND or OR to specify another condition.

11. (Optional) To run the SQL code, in the SQL Source pane, right-click and select Run SQL.

View the results in the SQL Results tab.

12. Click OK to exit SQL Query Builder and to return to the SQL File Editor, where the SQL code displays in the editor window.

Clicking Cancel results in no changes to the SQL code in the SQL File Editor. You lose any changes you made in SQL Query Builder.

Creating a FULLSELECT (UNION) Statement

Use SQL Query Builder to create a FULLSELECT UNION statement, which combines the results set for two tables.

Prerequisites

Connect to the data source through a connection profile.

Note: Some syntactic variations might exist between your database and the SQL syntax that SQL Query Builder supports; consequently, some SQL Query Builder features might not work with your database.

1. Open a new or an existing SQL file, and be sure to select the connection profile Type, Name, and Database.

2. In an appropriate place in the editor window, right-click and select Edit in SQL Query Builder.

3. Righ-click SELECT Statement, and select Convert to FULLSELECT (UNION).

4. Add one or more tables to the statement.

a) Right-click in the Tables pane and select Add Table.

SQL Query Builder

(14)

b) (Optional) Indicate a Table alias.

You might want to use a table alias to make the table name more readable or shorten it for display/output.

5. Define the SELECT statements.

a) In Outline view, expand the SELECT Statement and Union trees.

b) Click the first SELECT, and then create the SELECT statement.

c) Click the second SELECT, and then create the SELECT statement.

All selected columns need to be of the same data type.

You can nest a FULLSELECT UNION statement under a SELECT statement.

6. (Optional) Click SELECT Statement to define any other SELECT Statement options, such as operator or sort type.

UNION only selects distinct values while UNION ALL selects all values.

a) Next to the statement type, select UNION ALL to change the Operator from the default UNION.

b) Change the sort type or sort order.

7. (Optional) To run the SQL code, in the SQL Source pane, right-click and select Run SQL.

View the results in the SQL Results tab.

8. Click OK to exit SQL Query Builder and to return to the SQL File Editor, where the SQL code displays in the editor window.

Clicking Cancel results in no changes to the SQL code in the SQL File Editor. You lose any changes you made in SQL Query Builder.

Creating a WITH Statement

Use SQL Query Builder to create a WITH statement that you can reference from a SELECT statement. A WITH statement comprises one or more common table expressions and a SELECT statement. A common table expression defines a named result table that you can specify as a table in the FROM clause of a subsequent SELECT statement.

Prerequisites

1. Connect to the data source through a connection profile.

2. Open a new or existing SQL file, and be sure to select the connection profile Type, Name, and Database.

3. In SQL Query Builder, create a SELECT statement.

Note: Some syntactic variations might exist between your database and the SQL syntax that SQL Query Builder supports; consequently, some SQL Query Builder features might not work with your database.

1. In the Outline pane, right-click SELECT Statement and select Add Common Table Expression (WITH).

SQL Query Builder adds the WITH statement code in the SQL Source pane and to the tree in the Outline pane.

2. In the Outline view, expand the WITH statement tree, click SELECT node contained inside the WITH node, and define its SELECT statement.

SQL Query Builder creates a temporary table on which the main SELECT statement is based.

3. Add a table.

a) (Optional) Select the WITH node and enter a name for the temporary Table.

b) Select columns from the table.

c) (Optional) Select the WITH node and enter names for each Column in the temporary table.

4. In the Outline view, click the SELECT statement at the bottom of the outline tree.

SQL Query Builder

(15)

The SELECT statement is based on the temporary table just defined.

5. Add the temporary WITH table and/or any other tables and select columns from the tables.

The WITH table is now listed as a choice in the Add Table dialog.

6. (Optional) To run the SQL code, in the SQL Source pane, right-click and select Run SQL.

View the results in the SQL Results tab.

7. Click OK to exit SQL Query Builder and to return to the SQL File Editor, where the SQL code displays in the editor window.

Clicking Cancel results in no changes to the SQL code in the SQL File Editor. You lose any changes you made in SQL Query Builder.

Creating Joins

Create a join in a SELECT statement to retrieve data from two or more tables based on matching column values.

Prerequisites

1. Connect to the data source through a connection profile.

2. Open a new or existing SQL file, and be sure to select the connection profile Type, Name, and Database.

3. In SQL Query Builder, create a SELECT statement.

A join enables you to select data from two or more tables into a single results set without repeating unnecessary data. You can create different kinds of joins depending on what data from each table you want in the results set.

Table 17. Join operators Description Join operator

Returns data from all tables based on a common condition.

Inner join

Returns all the values from the left table plus matched values from the right table, and fills in NULLs for any missing values from the right table.

Left outer join

Returns all the values from the right table and matched values from the left table, and fills in NULLs for any missing values from the left table.

Right outer join

Combines the results of both left and right outer joins. The joined table contains all records from both tables, and fills in NULLs for missing matches on either side.

Full outer join

Note: Some syntactic variations might exist between your database and the SQL syntax that SQL Query Builder supports; consequently, some SQL Query Builder features might not work with your database.

1. In the Tables pane, add two or more tables

2. Drag the pointer from a column in one table to a column in another table.

By default, SQL Query Builder creates an inner join. You can also create a join by right-clicking anywhere in the Tables pane and selecting Create Join.

3. (Optional) To change the join type from the default inner join, right-click on the connector line and select Specify Join Type.

All joins defined between the two tables change to the selected join type.

SQL Query Builder

(16)

4. (Optional) To run the SQL code, in the SQL Source pane, right-click and select Run SQL.

View the results in the SQL Results tab.

5. Click OK to exit SQL Query Builder and to return to the SQL File Editor, where the SQL code displays in the editor window.

Clicking Cancel results in no changes to the SQL code in the SQL File Editor. You lose any changes you made in SQL Query Builder.

Creating an INSERT Statement From a Values Set

Use SQL Query Builder to create an INSERT statement to insert new rows at the end of a table with the values you indicate for the specified columns.

Prerequisites

Connect to the data source through a connection profile.

Note: Some syntactic variations might exist between your database and the SQL syntax that SQL Query Builder supports; consequently, some SQL Query Builder features might not work with your database.

1. Open a new or an existing SQL file, and be sure to select the connection profile Type, Name, and Database.

2. In an appropriate place in the editor window, right-click and select Edit in SQL Query Builder.

3. In the Outline pane, right-click SELECT Statement and select Change Statement Type.

4. Select INSERT and click OK.

5. Select the table by right-clicking in the Tables pane and selecting Add Table.

6. Specify the columns to use in the statement.

Description Option

Right-click the table in the Tables pane, and select Select All Columns.

Specify all columns

Use either method:

Specify specific columns

In the Tables pane, select the check box next to the column name.

In the Columns tab, select the specific column from the drop-down menu.

7. Enter the values for the selected columns.

a) In the Values pane, click the Values box next to the column name.

b) Enter a value, select NULL, or build an expression.

8. (Optional) To run the SQL code, in the SQL Source pane, right-click and select Run SQL.

View the results in the SQL Results tab.

9. Click OK to exit SQL Query Builder and to return to the SQL File Editor, where the SQL code displays in the editor window.

Clicking Cancel results in no changes to the SQL code in the SQL File Editor. You lose any changes you made in SQL Query Builder.

Creating an INSERT Statement From a Subquery

Use SQL Query Builder to create an INSERT statement from a subquery.

SQL Query Builder

(17)

Prerequisites

Connect to the data source through a connection profile.

Note: Some syntactic variations might exist between your database and the SQL syntax that SQL Query Builder supports; consequently, some SQL Query Builder features might not work with your database.

1. Open a new or an existing SQL file, and be sure to select the connection profile Type, Name, and Database.

2. In an appropriate place in the editor window, right-click and select Edit in SQL Query Builder.

3. In the Outline pane, right-click SELECT Statement and select Change Statement Type.

4. Select INSERT and click OK.

5. Select the table by right-clicking in the Tables pane and selecting Add Table.

6. Specify the columns to use in the statement.

Description Option

Right-click the table in the Tables pane, and select Select All Columns.

Specify all columns

Use either method:

Specify specific columns

In the Tables pane, select the check box next to the column name.

In the Columns tab, select the specific column from the drop-down menu.

7. Select Subquery.

8. From the Query name list, select Add SELECT Statement or Add FULLSELECT Statement.

9. Complete the SELECT or FULLSELECT statement.

You can nest a FULLSELECT statement under a SELECT statement.

10. (Optional) To run the SQL code, in the SQL Source pane, right-click and select Run SQL.

View the results in the SQL Results tab.

11. Click OK to exit SQL Query Builder and to return to the SQL File Editor, where the SQL code displays in the editor window.

Clicking Cancel results in no changes to the SQL code in the SQL File Editor. You lose any changes you made in SQL Query Builder.

Creating an UPDATE Statement

Use SQL Query Builder to create an UPDATE statement to update data in a table. You can explicitly set the values or derive them from the results of a build expression.

Prerequisites

Connect to the data source through a connection profile.

By specifying one or more conditions, you can indicate which rows in the database table to update. If you do not specify any conditions, all rows of the target table are updated.

1. Open a new or an existing SQL file, and be sure to select the connection profile Type, Name, and Database.

2. In an appropriate place in the editor window, right-click and select Edit in SQL Query Builder.

3. In the Outline pane, right-click SELECT Statement and select Change Statement Type.

4. Select UPDATE and click OK.

5. Select the table by right-clicking in the Tables pane and selecting Add Table.

SQL Query Builder

(18)

6. Specify the columns to use in the statement.

Description Option

Right-click the table in the Tables pane, and select Select All Columns.

Specify all columns

Use either method:

Specify specific columns

In the Tables pane, select the check box next to the column name.

In the Columns tab, select the specific column from the drop-down menu.

7. In the Set tab, indicate the columns to update and the update value.

a)

Select an individual column by clicking a column and then Add individual column to statement to select it for update, or select multiple columns by highlighting two or more columns and clicking

Add columns to statement as a group.

b) In the Expression box, enter an expression or value.

Enter a value directly in the box or select Specify Value to enter one. Select Edit Expression or Replace Expression to build an expression using Expression Builder. Leave as DEFAULT if you do not wish to change the value during update.

8. (Optional) In the Where tab, indicate a condition that targets specific rows for update.

a) Select a Column.

Alternately, select define a condition using the Expression Builder wizard.

b) Select an Operator.

c) Enter a specific Value, select a column from the drop-down list, or build an expression.

d) (Optional) Select AND or OR to specify another condition.

9. (Optional) To run the SQL code, in the SQL Source pane, right-click and select Run SQL.

View the results in the SQL Results tab.

10. Click OK to exit SQL Query Builder and to return to the SQL File Editor, where the SQL code displays in the editor window.

Clicking Cancel results in no changes to the SQL code in the SQL File Editor. You lose any changes you made in SQL Query Builder.

Creating a DELETE Statement

Use SQL Query Builder to create a DELETE statement to remove data from a specified table. By specifying one or more conditions, you can indicate which rows in the database table to delete. If you do not specify any conditions, all rows in the target table are deleted.

Prerequisites

Connect to the data source through a connection profile.

Note: Some syntactic variations might exist between your database and the SQL syntax that SQL Query Builder supports; consequently, some SQL Query Builder features might not work with your database.

1. Open a new or an existing SQL file, and be sure to select the connection profile Type, Name, and Database.

2. In an appropriate place in the editor window, right-click and select Edit in SQL Query Builder.

3. In the Outline pane, right-click SELECT Statement and select Change Statement Type.

SQL Query Builder

(19)

4. Select DELETE and click OK.

5. Select the table by right-clicking in the Tables pane and selecting Add Table.

6. (Optional) Indicate one or more conditions that target specific rows for deletion.

a) Select a Column.

Alternately, select define a condition using the Expression Builder wizard.

b) Select an Operator.

c) Enter a specific Value, select a column from the drop-down list, or build an expression.

d) (Optional) Select AND or OR to specify another condition.

7. (Optional) To run the SQL code, in the SQL Source pane, right-click and select Run SQL.

View the results in the SQL Results tab.

8. Click OK to exit SQL Query Builder and to return to the SQL File Editor, where the SQL code displays in the editor window.

Clicking Cancel results in no changes to the SQL code in the SQL File Editor. You lose any changes you made in SQL Query Builder.

Building Expressions

Use the Expression Builder in SQL Query Builder to build simple or complex expressions, or subqueries when creating SELECT, UPDATE, INSERT, and DELETE statements.

Prerequisites

1. Connect to the data source through a connection profile.

2. Open a new or existing SQL file, and be sure to select the connection profile Type, Name, and Database.

3. Edit an existing SQL statement or create a new one in SQL Query Builder.

Note: Some syntactic variations might exist between your database and the SQL syntax that SQL Query Builder supports; consequently, some SQL Query Builder features might not work with your database.

1. In the Column cell in which you want to create the expression, select Build Expression, and then click outside the cell to launch the Expression Builder wizard.

2. Select the expression type and click Next.

3. Enter appropriate information in the wizard pages.

4. Once you enter all applicable information, click Finish.

Expression Types

In SQL Query Builder, you can use build expressions of these types when creating SQL statements.

SQL Query Builder

(20)

Table 18. Expression types Description Type

A function returns a value. Functions types include column functions, scalar functions, row functions, or table functions.

The argument of a column function is a collection of like values (a column). This function can return a NULL value.

The argument(s) of a scalar function are individual scalar values, which can be of different types. This function can return a NULL value.

The argument of a row function is a structured type.

The function returns a row of built-in data types and can only be specified as a transform function for a structured type.

The argument(s) of a table function are individual scalar values, which can be of different types. The function returns a table, and can be specified only within the FROM clause of a SELECT statement.

Function

CASE expressions allow an expression to be selected based on the evaluation of one or more conditions. A CASE expression contains one or more when clauses of either Search or Simple type.

A Search CASE expression contains a condition that is evaluated, such as i<8.

A Simple CASE expression determines if the when clause evaluates to true; otherwise, the else clause determines the value of the case-expression.

CASE

A CAST function converts instances of a datatype to instances of a different datatype.

CAST

A constant specifies a value: a string or a number.

Numeric constants can be an integer, floating-point, or decimal.

A string constant can be a character string,

hexadecimal, or a host variable name. A colon precedes the host variable name, for example, :var. The host variable becomes a value when the statement is executed.

Constant

A subquery is a SELECT, WITH, or FULLSELECT statement nested within another SQL statement. The expression value is the result of the subquery.

Subquery

You can build an expression by applying operators to columns or expressions such as x+y where x is a column and y is an expression.

Build up expressions by operators

Editing a SQL Statement

Use SQL Query Builder to edit an individual SQL statement. You can only edit one SQL statement at a time.

SQL Query Builder

(21)

Prerequisites

Connect to the data source through a connection profile.

1. Open an existing SQL file, and be sure to select the connection profile Type, Name, and Database.

2. Highlight the entire single SQL statement, right-click and select Edit in SQL Query Builder.

3. Edit the SQL statement as required.

4. (Optional) To run the SQL code, in the SQL Source pane, right-click and select Run SQL.

View the results in the SQL Results tab.

5. Click OK to exit SQL Query Builder and to return to the SQL File Editor, where the SQL code displays in the editor window.

Clicking Cancel results in no changes to the SQL code in the SQL File Editor. You lose any changes you made in SQL Query Builder.

Running the SQL Statement Code

Use SQL Query Builder to run an individual SQL statement and view its execution results.

Prerequisites

Connect to the data source through a connection profile.

1. Open an existing SQL file, and be sure to select the connection profile Type, Name, and Database.

2. Highlight the entire single SQL statement, right-click and select Edit in SQL Query Builder.

3. In the SQL Source pane, right-click and select Run SQL.

4. (Optional) View the results in the SQL Results tab.

5. Click OK to exit SQL Query Builder and to return to the SQL File Editor, where the SQL code displays in the editor window.

Clicking Cancel results in no changes to the SQL code in the SQL File Editor. You lose any changes you made in SQL Query Builder.

SQL Query Builder

(22)

Creating a SQL File

Use Database Development tools to create SQL files.

You can use an existing project to store the SQL file or create a project when you create the SQL file.

1. In the Database Development perspective, select File > New > SQL File.

You can also click Open Scrapbook to Edit SQL Statements to quickly create SQL statements in SQL Scrapbook.

2. Associate the SQL file with a project.

Do this To

Enter or select the project in the Enter or Select the Parent Folder.

Use an existing project

Click Create Project, and follow the wizard instructions.

Create a new project

3. Enter the File Name.

4. (Optional) Click Advanced to link to a file in the file system and to create, edit, or remove defined path variables.

5. (Optional) Associate the SQL file with a connection profile.

a) Select a Connection Profile Type.

b) Select a Connection Profile Name, or click Create to create one.

c) Select the Database Name.

6. (Optional) Select Do Not Connect Now to remain disconnected from the server.

You cannot use the complete Content Assist feature if you select this option.

7. Click Finish.

A SQL file is created under the project in Navigator and opens in the SQL File Editor.

8. Right-click in the SQL File Editor and select Edit in SQL Query Builder to graphically build SQL statements, or type your SQL directly in the editor window.

9. (Optional) To add or remove comment delimiters for a line of code, right-click one or more lines of code, and select Toggle Comment.

10. When finished, save the SQL file.

SQL File Editor

Use the SQL File Editor to create and edit SQL statements.

The SQL File Editor enables standard text-based editing of SQL statements with the added functionality of Content Assist, syntax color, and multiple statement support. You can associate the SQL file with a specific connection profile, and use the SQL File Editor to graphically build SQL statements using SQL Query Builder.

SQL Scrapbook

SQL Scrapbook enables you to quickly create and execute SQL commands and queries without creating a SQL file.

Creating a SQL File

(23)

You can associate SQL Scrapbook with a specific connection profile and database, and you can execute a highlighted SQL statement or all SQL statements directly from the editor window. You can also create procedural objects and use SQL Query Builder to create select, insert, update, and delete statements.

You access SQL Scrapbook by clicking the Open Scrapbook to Edit SQL Statements button.

Editing a SQL File

Edit the SQL statements in a SQL file.

1. In Navigator, double-click the SQL file to open it in SQL File Editor.

2. (Optional) Change the connection profile Type, Name, and/or Database.

Associating a SQL file with the connection profile of a connected data server enables you to use the full capabilities of Content Assist and to execute the SQL file or selected statements.

3. (Optional) Right-click in the left margin and select Show Line Numbers.

4. Edit the SQL file by manually editing the SQL code or by launching SQL Query Builder.

5. (Optional) Remove edits since your last save by right-clicking and selecting Revert File.

6. Save the file to the project or to a new project.

Opening a SQL File

Open a SQL file for viewing or editing in the SQL File Editor.

1. In Navigator, expand the project folder in which the SQL file resides.

2. Double-click the SQL file to open it.

Saving a SQL File

Save one or more SQL files to the current project, or save a SQL file to a different project or to a different file name.

• Save one or more SQL files simultaneously.

Description Option

Select File > Save from the main menu bar.

Save to current project

Select File > Save As from the main menu bar, and specify project information in the Save As dialog.

Save to different project

Select File > Save As from the main menu bar, and specify a file name in the Save As dialog.

Save to different file name

Select File > Save All from the main menu bar.

Save all SQL files to the current project

Creating a SQL File

(24)

Executing a SQL Statement

Execute a SQL statement from an editor.

Prerequisites

Be sure the data server for which you are executing a SQL statement is running, and you created and established a connection to the data server. Open the SQL file.

1. Highlight the SQL statements you want to execute.

2. Execute one, multiple, or all SQL statements.

Do this To

HIghtlight the statements and select Execute Selected Text.

Execute one or more SQL statements

Select Execute All.

Execute all statements

Execution status and and results appear in the SQL Results view.

Executing a SQL Statement

(25)

Running an Ad Hoc SQL Statement

Use the Eclipse launch configuration mechanism to run an ad hoc SQL query.

Prerequisites

Make sure that the database server is running. Establish a connection to the database through a connection profile.

1. Select Run > Run Configurations.

2. In the Main tab, click Adhoc SQL.

3. Select the connection Profile and Database.

4. In the Run box, enter the SQL query, or click SQL to graphically build the SQL statements in SQL Query Builder.

5. Click Run to execute the query.

You can view the results of the ad hoc query in the SQL Results view.

Running an Ad Hoc SQL Statement

(26)

Executing a SQL File

You can execute a SQL file from the SQL File Editor or from Navigator.

Prerequisites

Make sure the database server is running and you are connected to it through a connection profile.

Execute the SQL file using one of the following methods.

Description Option

From SQL File Editor

1. In the Navigator project folder, double-click to open the SQL file in SQL File Editor.

2. Right-click in the editor, and select Execute All.

From Navigator

1. Select one or more SQL files.

2. Right-click the files and choose Execute SQL File.

3. If you selected multiple SQL files, click OK in the Select Profiles for the File dialog.

The SQL file executes, and results appear in the SQL Results view. SQL Results view displays the result sets, database server messages, execution status (success or failure) and operation details.

Executing a SQL File

(27)

Running a Routine Object

Run a routine object to obtain SQL results from the database.

Prerequisites

Connect to your database server through a connection profile. Save or deploy the routine object to a database.

1. In Data Source Explorer, find the routine object in the navigation tree.

2. Right-click the object and select Run.

Note: If the object includes parameters, the Configure Parameters dialog appears. Edit parameter values as necessary.

3. Click OK to run the object.

The SQL Results view displays the status of the run instance and execution details, and returns result sets and server messages, if any.

Creating a Launch Configuration for Routine Objects

Use the launch configuration feature to run stored procedures, triggers, and ad hoc queries. Creating your own launch configurations is optional, but it can help you perform more consistent, robust, and efficient iterative testing of routine objects.

DTP creates a launch configuration automatically using the name, connection profile name and type, and object type. You can create additional launch configurations with different launch properties. For example, you can specify different parameters or ad hoc SQL statements.

1. Select Run > Run Configurations from the main menu.

2.

Click New Launch Configuration.

You can also choose an existing launch configuration by selecting it in the left pane. You can edit it, or duplicate it and use it as a basis for a new configuration.

3. Enter a unique Name for the launch configuration.

4. On the Main tab, select a connection Profile and a Database.

5. Select the object Type.

6. If basing the launch configuration on an existing object, click Browse to select the object.

7. In the Run box, complete the execution information.

Description Object

Click Configure Parameter, and assign values to any parameters.

Stored procedures

Enter an INSERT, UPDATE, or DELETE statement, or click SQL to visually build the statement using SQL Query Builder.

Triggers

Enter the SQL statement, or click SQL to visually build the statement using SQL Query Builder.

Ad hoc SQL

8. (Optional) Click the Options tab to set additional preferences, if the database server support this feature.

9. (Optional) Click the Common tab to set other attributes for this object.

Running a Routine Object

(28)

Table 19. Common launch configuration attributes Explanation

Field

Specify where to save the launch configuration:

Select Local File to make it available to this project only.

Select Shared File to make it available to other projects.

Save As

Click Debug or Run to display the configuration in a Favorites menu.

Display in Favorites Menu

(Optional) Click Other, and select an encoding to override Export Format preferences.

Console Encoding

Select Allocate Console if the object requires input (default).

Standard Input and Output: Allocate Console

(Optional) Click File to choose a location for file output:

Click Workspace to select a project resource to which to redirect output.

Click File System to save the output as a file.

Click Variables to select and configure a variable for output.

Standard Input and Output: File

(Optional) Click Append to append output from each launch to the existing file. Otherwise, each launch overwrites previous output.

Standard Input and Output: Append

Indicates that the object runs in the background.

Launch in Background

10. Click Apply to accept launch configuration changes.

11. Click Run to execute the object.

Results appear in SQL Results view.

Routine Objects

Routine objects are the building blocks of a database application. Database Development builds the skeleton for routine objects and provides tools to populate the body of the object with the appropriate SQL.

Routine objects standardize actions performed by more than one application program. By coding an action once and storing it in the database for future use, applications need only execute the routine or fire the trigger to achieve the desired result repeatedly. Because changes occur in only one place, all applications using the action automatically acquire the new functionality if the implementation of the action changes. When you create an object, it is automatically checked for correct syntax and stored in the system tables. The first time any application calls or fires the object, it is compiled from the system tables into the server's virtual memory and executed from there.

Running a Routine Object

(29)

Table 20. Object types Description

Object type

A stored procedure is a collection of SQL statements and optional control-of-flow statements. A stored procedure can use parameters to accept values and return values to the calling environment. A stored procedure can also return result sets or invoke other procedures.

Stored procedures

A trigger is a special form of stored procedure that executes when a user attempts to change table or column data using a command such as insert, delete, or update. Triggers can call stored procedures and functions and can fire other triggers. Triggers are often used to enforce referential integrity and can cascade changes through related tables, roll back transactions, enforce complex restrictions, and perform simple analyses.

Triggers

You can develop the object types that your database and server support.

Running a Routine Object

(30)

Viewing SQL Results

Use the SQL Results view to see the results of an executed SQL query or routine object.

1. Execute your SQL query, code to create a database object, or a routine object.

2. Examine the execution results in SQL Results view.

Results include the status of the query or object, the text of the query, the date and time, and error or informational messages.

Note: The maximum number of result tabs that display is determined via the SQL Results view preference page. Any result sets that exceed the maximum number do not display. To view more result tabs, increase the limit. To view all results, export all results to a file and view the results in an external editor.

SQL Results View

SQL Results view displays the results of executing SQL statements, running routine objects, and creating database objects.

SQL Results view appears in the Database Development perspective and consists of a history frame and a details frame. The history frame displays the execution history for past queries. The details frame displays the status and results of the last execution. Use the view pull-down menu to filter history results and set preferences.

Table 21. SQL Results history Description

Field

Enter a query expression in the text field at the top the SQL Results history pane to filter the results that match the expression.

History Filter

Displays whether the operation failed, succeeded, terminated, or is still running.

Status

Displays the SQL statement that was executed.

Operation

Displays the current date and time when the operation failed, successfully executed, terminated, or reached a breakpoint.

Date

Displays the connection profile on which the corresponding operation was run.

Connection Profile

To save SQL results, right-click in the history pane, and select Save History.

When you execute multiple queries in a SQL file containing a delimiter (such as go) using the Execute All or Execute Selected Text options, the results are grouped in a tree structure in the SQL Results view. The root node is a top-level result history. Expand this node in the SQL Results view to see the results for each individual SQL statement.

Right-click the root node of the group SQL statement and select Save History to save all the resultsets from one group execution of a set of SQL queries.

There are two modes for the details frame, single-tab and multitab:

• In single-tab mode, all results and messages appear in the same column, with messages and status at the end.

• In multitab mode, each result and message is in a separate tab.

Viewing SQL Results

(31)

Table 22. Text View context menu options Description

Option

Launches the Find/Replace dialog, which allows you to search for and replace specific text in the resultset. This replaces the data of the displayed resultset only. It does not replace the data on the server.

Note: Find/Replace is enabled only when results are displayed in text mode.

Find/Replace

Launches the Save dialog, which allows you to save the SQL results to a project. You can choose to Save All Results or Save Current Results.

Save Results

Launches the Export All Results dialog, which allows you to save the result set to a file outside of any project for use with other applications. You can choose to Export All Results or Export Current Results.

Export Results

Allows you to print the SQL results. You can choose to Print All Results or Print Current Results.

Print Results

Table 23. SQL Results tabs for multi-tab mode Description

Tab

Shows the interim status of running the routine object or selected text.

Status

For a routine object, displays the input and output parameter names, datatypes, values, and parameter types (IN, OUT, or IN/OUT).

Parameters

Displays results for a SQL query in the routine object, SQL file, or selected statement.

Result n

Table 24. SQL Results buttons Action

Name Icon

Terminate a long-running instance.

Terminate Result

Remove the status, result sets, and messages of a selected SQL result instance.

Remove Result

Remove all results for completed statements from the SQL Results view.

Remove All Visible Results

Toggle between text mode and grid mode.

Display the Result in Text Mode

Toggle between single-tab and multitab display.

Display the Result in Single Tab

Filter the SQL results.

Filter Results

Terminating Execution in SQL Results View

You can terminate the execution of a routine object or SQL statement from the SQL Results view. Terminating the execution of an object or SQL statement stops further results from being displayed for the corresponding query.

Viewing SQL Results

(32)

You can terminate a running result from SQL Results view. Terminating a result stops it from running and makes it possible to remove it from the history, but does not remove it automatically.

Right-click a running result in the History frame of the SQL Results view and select Terminate.

Exporting SQL Execution Results

In SQL Results view, you can export a single result set or all execution results.

Prerequisites

Open SQL Results view.

Exporting saves the result set to a file outside of the workspace project for use with other applications.

1. If in Single Tab mode, switch to Text (multitab) mode.

2. Export a single result or all results.

Do this To export

In the Result tab, , right-click and select Export > Current Result.

A single result

In the Result tab, right-click and select Export > All Results.

All results

3. Enter a File Name, or click Browse to find an existing file or save the results to a specific location and file name.

If you do not specify a file location, the file is saved to the <installation>\eclipse directory.

4. Select a file Format.

5. Select the Export Options.

6. Click Finish.

Saving Execution Results to a Project

After you execute SQL queries or run objects, you can save the results to a project from SQL Results view.

Prerequisites

Open SQL Results view.

1. If in Single Tab mode, switch to Text (multitab) mode.

2. Save a single result or all results.

Do this To save

In the Result tab, , right-click and select Save > Current Result.

A single result

In the Result tab, right-click and select Save > All Results.

All results

3. Select the project folder in which to save the result set.

4. Enter the File Name.

5. Select the File Type.

6. Specify the Export Options.

Viewing SQL Results

(33)

7. Click OK.

The result set opens in the editor or external tool for the format you chose.

Removing Results from SQL Results View

Remove query results from the History frame of the SQL Results view.

All execution results remain in SQL Results view. You can remove one or all finished results. Removing a result deletes all result sets for that result instance from the display and from the history.

In the SQL Results view History pane, right-click a finished result and select one:

Description Option

Remove only the selected result Remove

Remove all results Remove All

Saving SQL Results History

Save the SQL Results view history to a log file that includes the history summary and the result sets.

1. In SQL Results view, right-click any result in the History frame, and select Save History.

2. Choose a location for the history log file, and enter a File Name.

3. Click Save.

Filtering SQL Results History

Set filtering options for the SQL Results history to limit the visible results sets.

1. In SQL Results view, select Filters from the view pull-down menu.

2. Specify which options to view in the SQL results history.

Action Filtering option

Deselect one or more connection profiles to remove the result sets from view.

Connection Profiles

Indicate the maximum number of entries to display in the History pane. The default is 50.

Limit Visible History To

View results for deleted profiles or profiles with changed names.

Display Results of Unresolvable Connection Profiles

Select which statuses to view.

Result Status

3. Click OK.

Viewing SQL Results

References

Related documents

SELECT Statements in PL/SQL to Retrieve data Data Manipulation in the Server Using PL/SQL The SQL Cursor concept. Learn to use SQL Cursor Attributes to Obtain Feedback on DML How

Just as business query and reporting tools allow users to retrieve data from relational databases without knowing SQL, OLAP viewers allow users to access data in an OLAP

CASE statement evaluates a explain of Boolean expressions and, scramble it finds an advance that evaluates to TRUE, executes a clap of statements associated with certain

• Creating tables from query results (SQL create table statement with select clause). • Creating

SELECT Statements in PL/SQL to Retrieve data Data Manipulation in the Server Using PL/SQL The SQL Cursor concept. Learn to use SQL Cursor Attributes to Obtain Feedback on DML How

• With the CASCADE option, all such constraints and views that reference the table are dropped automatically from the schema.

SQL Update Statement, Update Query in SQL, SQL Update Select, SQL Update Join, SQL update table from another table, sql update multiple rows, update command in sql, sql update

SELECT Statements in PL/SQL to Retrieve data Data Manipulation in the Server Using PL/SQL The SQL Cursor concept. Learn to use SQL Cursor Attributes to Obtain Feedback on DML How