Basic SQL statements and functions used in QMF queries

You can issue SQL statements directly to the database from the QMF SQL Query panel. The SQL Query panel supports all SQL statements that can be run dynamically.

Selected SQL statements and keywords that are used in QMF SQL queries are described in this topic.

When you type a query on the SQL Query panel, remember to:
  • Enclose reserved words in double quotation marks.

    In many cases, words that are keywords in database management systems cannot be used as the name of a table, view, column, or index in a QMF SQL query unless they are enclosed in double quotation marks.

  • Enclose in double quotation marks any part of an object name that spans two or more lines.
    When any part of an object name (the location, authorization ID, or the object name itself) is continued on a new line, that part of the name must be delimited by double quotation marks. The following figure shows an example of a long object name that spans two lines. The name is qualified with an authorization ID that also spans two lines.
    Figure 1. Delimiting qualified object names that span multiple lines.
    SQL QUERY                                            MODIFIED  LINE    1       
    SELECT * FROM "VERY_LONG_AUTHID_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXX"."VERY_LONG_TABLE_NAME_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXX"                                                                               
    
    
    
    
    
                                                                            
  • Activate support for multiple statements and use proper syntax if the query contains more than one SQL statement.

    To include multiple SQL statements in a QMF SQL query, set the DSQEC_RUN_MQ global variable to 1 and place a semicolon at the end of every statement except the last.

    CREATE PROCEDURE and CALL statements must be used alone in a query.

    No more than one SELECT statement can be used in a query that includes other SQL statements.

  • Both simple and bracketed comments can be used in an SQL query. Simple comments are introduced with two consecutive hyphens (--) and end with the end of a line. Simple comments cannot be continued to the next line. Bracketed comments are introduced with /* and end with */. Bracketed comments can be continued to the next line.

When your SQL query references an unqualified table or view name, QMF sends the unqualified name to Db2® for resolution. Db2 uses the value in the CURRENT SCHEMA register to qualify the table or view name. QMF allows you to issue SET CURRENT SCHEMA statements to change the value of this register.