Run SQL Statements (RUNSQLSTM)
Where allowed to run: All environments (*ALL) Threadsafe: No |
Parameters Examples Error messages |
The Run SQL Statements (RUNSQLSTM) command processes a source file of Structure Query Language (SQL) statements.
RUNSQLSTM will run SQL statements in the default activation group. If RUNSQLSTM is included in a compiled CL program or ILE CL procedure, the activation group of the CL program or procedure is ignored.
Top |
Parameters
Keyword | Description | Choices | Notes |
---|---|---|---|
SRCFILE | Source file | Qualified object name | Optional, Positional 1 |
Qualifier 1: Source file | Name | ||
Qualifier 2: Library | Name, *LIBL, *CURLIB | ||
SRCMBR | Source member | Name | Optional, Positional 2 |
SRCSTMF | Source stream file | Path name | Optional |
COMMIT | Commitment control | *CHG, *UR, *CS, *ALL, *RS, *NONE, *NC, *RR | Optional, Positional 3 |
NAMING | Naming | *SYS, *SQL | Optional, Positional 4 |
ERRLVL | Severity level | 0-40, 10 | Optional |
DATFMT | Date format | *JOB, *USA, *ISO, *EUR, *JIS, *MDY, *DMY, *YMD, *JUL | Optional |
DATSEP | Date separator character | *JOB, '/', '.', ',', '-', ' ', *BLANK | Optional |
TIMFMT | Time format | *HMS, *USA, *ISO, *EUR, *JIS | Optional |
TIMSEP | Time separator character | *JOB, ':', '.', ',', ' ', *BLANK | Optional |
MARGINS | Source margins | Element list | Optional |
Element 1: Right margin | 1-32754, 80 | ||
DFTRDBCOL | Default collection | Name, *NONE | Optional |
SAAFLAG | IBM SQL flagging | *NOFLAG, *FLAG | Optional |
FLAGSTD | ANS flagging | *NONE, *ANS | Optional |
DECMPT | Decimal point | *JOB, *SYSVAL, *PERIOD, *COMMA | Optional |
SRTSEQ | Sort sequence | Single values: *JOB, *LANGIDUNQ, *LANGIDSHR, *HEX Other values: Qualified object name |
Optional |
Qualifier 1: Sort sequence | Name | ||
Qualifier 2: Library | Name, *LIBL, *CURLIB | ||
LANGID | Language id | Character value, *JOB | Optional |
OPTION | Source listing options | *LIST, *NOSRC, *ERRLIST, *NOLIST | Optional |
PRTFILE | Print file | Qualified object name | Optional |
Qualifier 1: Print file | Name, QSYSPRT | ||
Qualifier 2: Library | Name, *LIBL, *CURLIB | ||
PROCESS | Statement processing | *RUN, *SYN | Optional |
SECLVLTXT | Second level text | *NO, *YES | Optional |
ALWCPYDTA | Allow copy of data | *OPTIMIZE, *YES, *NO | Optional |
ALWBLK | Allow blocking | *ALLREAD, *NONE, *READ | Optional |
SQLCURRULE | SQL rules | *DB2, *STD | Optional |
DECRESULT | Decimal result options | Element list | Optional |
Element 1: Maximum precision | 31, 63 | ||
Element 2: Maximum scale | 0-63, 31 | ||
Element 3: Minimum divide scale | 0-9, 0 | ||
CONACC | Concurrent access resolution | *DFT, *CURCMT, *WAIT | Optional |
SYSTIME | System time sensitive | *YES, *NO | Optional |
OUTPUT | Listing output | *NONE, *ERROR, *NOLIST, *MSG, *PRINT | Optional |
TGTRLS | Target release | Simple name, *CURRENT | Optional |
DBGVIEW | Debugging view | *NONE, *SOURCE, *STMT, *LIST | Optional |
CLOSQLCSR | Close SQL cursor | *ENDMOD, *ENDACTGRP | Optional |
DLYPRP | Delay PREPARE | *NO, *YES | Optional |
USRPRF | User profile | *NAMING, *USER, *OWNER | Optional |
DYNUSRPRF | Dynamic user profile | *USER, *OWNER | Optional |
Top |
Source file (SRCFILE)
Specifies the source file that contains the Structured Query Language (SQL) statements to be run.
Qualifier 1: Run SQL Statements
- name
- Specify the name of the source file that contains the SQL statements to be run. The source file can be a database file or an inline data file.
Qualifier 2: Library
- *LIBL
- All libraries in the library list for the current thread are searched until the first match is found.
- *CURLIB
- The current library for the job is searched. If no library is specified as the current library for the job, the QGPL library is used.
- name
- Specify the name of the library to be searched.
Top |
Source member (SRCMBR)
Specifies the source file member that contains the Structured Query Language (SQL) statements to be run.
- name
- Specify the name of the source file member that contains the SQL statements to be run.
Top |
Source stream file (SRCSTMF)
Specifies the path name to the file that contains the SQL statements. The path name can be either absolute or relative.
Top |
Commitment control (COMMIT)
Specifies whether SQL statements are run under commitment control.
- *CHG or *UR
- Specifies the objects referred to in SQL ALTER, CALL, COMMENT ON, CREATE, DROP, GRANT, LABEL ON, RENAME, and REVOKE statements and the rows updated, deleted, and inserted are locked until the end of the unit of work (transaction). Uncommitted changes in other jobs can be seen.
- *CS
- Specifies the objects referred to in SQL ALTER, CALL, COMMENT ON, CREATE, DROP, GRANT, LABEL ON, RENAME, and REVOKE statements and the rows updated, deleted, and inserted are locked until the end of the unit of work (transaction). A row that is selected, but not updated, is locked until the next row is selected. Uncommitted changes in other jobs cannot be seen.
- *ALL or *RS
- Specifies the objects referred to in SQL ALTER, CALL, COMMENT ON, CREATE, DROP, GRANT, LABEL ON, RENAME, and REVOKE statements and the rows selected, updated, deleted, and inserted are locked until the end of the unit of work (transaction). Uncommitted changes in other jobs cannot be seen.
- *NONE or *NC
- Specifies that commitment control is not used. Uncommitted changes in other jobs can be seen. If the SQL DROP SCHEMA statement is included in the program, *NONE or *NC must be used.
- *RR
- Specifies the objects referred to in SQL ALTER, CALL, COMMENT ON, CREATE, DROP, GRANT, LABEL ON, RENAME, and REVOKE statements and the rows selected, updated, deleted, and inserted are locked until the end of the unit of work (transaction). Uncommitted changes in other jobs cannot be seen. All tables referred to in SELECT, UPDATE, DELETE, and INSERT statements are locked exclusively until the end of the unit of work (transaction).
Top |
Naming convention (NAMING)
Specifies the naming convention used for objects in SQL statements.
- *SYS
- The system naming convention (library-name/file-name) is used.
- *SQL
- The SQL naming convention (schema-name.table-name) is used.
Top |
Severity level (ERRLVL)
Specifies whether the processing is successful, based on the severity of the messages generated by the processing of the SQL statements. If errors that are greater than the value specified for this parameter occur during processing, no more statements are run and the statements are rolled back if they are running under commitment control. Syntax checking will be attempted for the remaining statements in the source.
- 10
- Statement processing is stopped when error messages with a severity level greater than 10 are received.
- 0-40
- Specify the severity level to be used.
Top |
Date format (DATFMT)
Specifies the format used when accessing date result columns. For input date strings, the specified value is used to determine whether the date is specified in a valid format.
Note: An input date string that uses the format *USA, *ISO, *EUR, or *JIS is always valid.
- *JOB
- The format specified for the job is used. Use the Display Job (DSPJOB) command to determine the current date format for the job.
- *USA
- The United States date format mm/dd/yyyy is used.
- *ISO
- The International Organization for Standardization (ISO) date format yyyy-mm-dd is used.
- *EUR
- The European date format dd.mm.yyyy is used.
- *JIS
- The Japanese Industrial Standard date format yyyy-mm-dd is used.
- *MDY
- The date format mm/dd/yy is used.
- *DMY
- The date format dd/mm/yy is used.
- *YMD
- The date format yy/mm/dd is used.
- *JUL
- The Julian date format yy/ddd is used.
Top |
Date separator character (DATSEP)
Specifies the separator used when accessing date result columns.
Note: This parameter applies only when *JOB, *MDY, *DMY, *YMD, or *JUL is specified for the Date format (DATFMT) parameter.
- *JOB
- The date separator specified for the job at precompile time, when a new interactive SQL session is created, or when RUNSQLSTM is run is used.
Use the Display Job (DSPJOB) command to determine the current date separator value for the job.
- '/'
- A slash is used as the date separator.
- '.'
- A period is used as the date separator.
- '-'
- A dash is used as the date separator.
- ','
- A comma is used as the date separator.
- ' ' or *BLANK
- A blank is used as the date separator.
Top |
Time format (TIMFMT)
Specifies the format used when accessing time result columns. For input time strings, the specified value is used to determine whether the time is specified in a valid format.
Note: An input time string that uses the format *USA, *ISO, *EUR, or *JIS is always valid.
- *HMS
- The hh:mm:ss format is used.
- *USA
- The United States time format hh:mmxx is used, where xx is AM or PM.
- *ISO
- The International Organization for Standardization (ISO) time format hh.mm.ss is used.
- *EUR
- The European time format hh.mm.ss is used.
- *JIS
- The Japanese Industrial Standard time format hh:mm:ss is used.
Top |
Time separator character (TIMSEP)
Specifies the separator used when accessing time result columns.
Note: This parameter applies only when *HMS is specified for the Time format (TIMFMT) parameter.
- *JOB
- The time separator specified for the job at precompile time, when a new interactive SQL session is created, or when RUNSQLSTM is run is used.
Use the Display Job (DSPJOB) command to determine the current time separator value for the job.
- ':'
- A colon is used as the time separator.
- '.'
- A period is used as the time separator.
- ','
- A comma is used as the time separator.
- ' ' or *BLANK
- A blank is used as the time separator.
Top |
Source margins (MARGINS)
Specifies the part of the source input record that contains source text. The left margin is always position 1 of the input record. The right margin defaults to 80.
If the Source stream file (SRCSTMF) parameter is specified, margins are ignored.
- 1-32754
- Specify the ending position to be used for each input record.
Top |
Default collection (DFTRDBCOL)
Specifies the name of the schema identifier used for the unqualified names of the tables, views, indexes, SQL packages, aliases, constraints, external programs, node groups, and triggers. This parameter applies only to static SQL statements.
- *NONE
- The naming convention specified for the Naming convention (NAMING) parameter is used.
- name
- Specify the name of the schema identifier to be used instead of the naming convention specified for the NAMING parameter.
Top |
IBM SQL flagging (SAAFLAG)
Specifies the IBM SQL flagging function. This parameter allows you to flag SQL statements to verify whether they conform to IBM SQL syntax.
- *NOFLAG
- No checks are made to see whether SQL statements conform to IBM SQL syntax.
- *FLAG
- Checks are made to see whether SQL statements conform to IBM SQL syntax.
Top |
ANS flagging (FLAGSTD)
Specifies whether non-standard statements are flagged. This parameter allows you to flag SQL statements to verify whether they conform to the Core level of the ISO/IEC 9075-2003 standards.
- *NONE
- No checks are made to see whether SQL statements conform to ANSI standards.
- *ANS
- Checks are made to see whether SQL statements conform to standards.
Top |
Decimal point (DECMPT)
Specifies the decimal point value used for numeric constants in SQL statements. This value is also used as the decimal point character when casting between character and numeric values.
- *JOB
- The representation for the decimal point is the value used by the job running the statement.
- *SYSVAL
- The QDECFMT system value is used as the decimal point.
- *PERIOD
- A period represents the decimal point.
- *COMMA
- A comma represents the decimal point.
Top |
Sort sequence (SRTSEQ)
Specifies the sort sequence table to be used for string comparisons in SQL statements.
Single values
- *JOB
- The SRTSEQ value for the job is used.
- *LANGIDUNQ
- The unique-weight sort table for the language specified for the Language id (LANGID) parameter is used.
- *LANGIDSHR
- The shared-weight sort table for the language specified for the LANGID parameter is used.
- *HEX
- A sort sequence table is not used. The hexadecimal values of the characters are used to determine the sort sequence.
Qualifier 1: Sort sequence
- name
- Specify the name of the sort sequence table to be used with this program.
Qualifier 2: Library
- *LIBL
- All libraries in the library list for the current thread are searched until the first match is found.
- *CURLIB
- The current library for the job is searched. If no library is specified as the current library for the job, the QGPL library is used.
- name
- Specify the name of the library to be searched.
Top |
Language id (LANGID)
Specifies the language identifier to be used when SRTSEQ(*LANGIDUNQ) or SRTSEQ(*LANGIDSHR) is specified.
- *JOB
- The LANGID value for the job is retrieved.
- language-identifier
- Specify a language identifier.
Top |
Source listing options (OPTION)
Specifies the option for the listing generated by the command.
- *LIST
- A complete listing with the contents of the source and all errors is generated.
- *NOSRC
- A listing with only the messages is generated.
- *ERRLIST
- A complete listing is generated only if errors greater than the ERRLVL parameter are encountered during processing.
- *NOLIST
- No listing is generated. If errors greater than the ERRLVL parameter are encountered during processing, the messages will be sent to the joblog.
Top |
Print file (PRTFILE)
Specifies the printer device file to which the printout from the command is directed. The file must have a minimum length of 132 bytes. If a file with a record length of less than 132 bytes is specified, information is lost.
Qualifier 1: Print file
- QSYSPRT
- The output file is directed to the IBM-supplied printer file, QSYSPRT.
- name
- Specify the name of the printer device file to which the output is directed.
Qualifier 2: Library
- *LIBL
- All libraries in the library list for the current thread are searched until the first match is found.
- *CURLIB
- The current library for the job is searched. If no library is specified as the current library for the job, the QGPL library is used.
- name
- Specify the name of the library where the printer file is located.
Top |
Statement processing (PROCESS)
Specifies whether SQL statements in the source file member are executed or syntax-checked only.
- *RUN
- Statements are syntax-checked and run.
- *SYN
- Statements are syntax-checked only.
Top |
Second level text (SECLVLTXT)
Specifies whether the second-level message text descriptions should be written to the output listing.
- *NO
- Second-level text is not included in the listing.
- *YES
- Second-level text with replacement data is added to the listing for all messages.
Top |
Allow copy of data (ALWCPYDTA)
Specifies whether a copy of the data can be used in a SELECT statement.
- *OPTIMIZE
- The system determines whether to use the data retrieved directly from the database or to use a copy of the data. The decision is based on which method provides the best performance. If the Commitment control (COMMIT) parameter is not *NONE, the Allow blocking (ALWBLK) parameter should be set to *ALLREAD, when possible, for best performance.
- *YES
- A copy of the data is used only when necessary.
- *NO
- A copy of the data is not used. If a temporary copy of the data is required to perform the query, an error message is returned.
Top |
Allow blocking (ALWBLK)
Specifies whether the database manager can use record blocking and the extent to which blocking can be used for read-only cursors.
- *ALLREAD
- Rows are blocked for read-only cursors. All cursors in a program that are not explicitly able to be changed are opened for read-only processing even though there may be EXECUTE or EXECUTE IMMEDIATE statements in the program.
Specifying *ALLREAD:
- Allows record blocking for all read-only cursors.
- Can improve the performance of almost all read-only cursors in programs, but limits queries in the following ways:
- The Rollback (ROLLBACK) command, a ROLLBACK statement in host languages, or the ROLLBACK HOLD SQL statement does not reposition a read-only cursor when *ALLREAD is specified.
- Dynamic running of a positioned UPDATE or DELETE statement (for example, using EXECUTE IMMEDIATE), can not be used to update a row in a cursor unless the DECLARE statement for the cursor includes the FOR UPDATE clause.
- *NONE
- Rows are not blocked for retrieval of data for cursors.
Specifying *NONE:
- Guarantees that the data retrieved is current.
- May reduce the amount of time required to retrieve the first row of data for a query.
- Stops the database manager from retrieving a block of data rows that is not used by the program when only the first few rows of a query are retrieved before the query is closed.
- Can degrade the overall performance of a query that retrieves a large number of rows.
- *READ
- Records are blocked for read-only retrieval of data for cursors when:
- *NONE is specified for the Commitment control (COMMIT) parameter, which indicates that commitment control is not used.
- The cursor is declared with a FOR READ ONLY clause or there are no dynamic statements that could run a positioned UPDATE or DELETE statement for the cursor.
Top |
SQL rules (SQLCURRULE)
Specifies the semantics used for SQL statements.
- *DB2
- The semantics of all SQL statements will default to the rules established for DB2. The following semantics are controlled by this option:
Hexadecimal constants are treated as character data.
- *STD
- The semantics of all SQL statements will default to the rules established by the ISO and ANSI SQL standards. The following semantics are controlled by this option:
Hexadecimal constants are treated as binary data.
Top |
Decimal result options (DECRESULT)
Specifies the maximum precision, maximum scale, and minimum divide scale that should be used during decimal operations, such as decimal arithmetic. The specified limits only apply to NUMERIC and DECIMAL data types.
Element 1: Maximum precision
- 31
- The maximum precision (length) that should be returned from decimal operations is 31 digits.
- 63
- The maximum precision (length) that should be returned from decimal operations is 63 digits.
Element 2: Maximum scale
- 31
- The maximum scale (number of decimal positions to the right of the decimal point) that should be returned from decimal operations is 31 digits.
- 0-63
- Specify the maximum scale (number of decimal positions to the right of the decimal point) that should be returned from decimal operations. The value can range from 0 to the maximum precision.
Element 3: Minimum divide scale
- 0
- The minimum divide scale is not used.
- 0-9
- Specify the minimum divide scale (number of decimal positions to the right of the decimal point) that should be returned from decimal operations. The value cannot exceed the maximum scale. If 0 is specified for the maximum scale, minimum divide scale is not used.
Top |
Concurrent access resolution (CONACC)
Specifies how the database manager should handle record lock conflicts for data in the process of being updated.
- *DFT
- Specifies that the concurrent access option will not be explicitly set for this program. The value that is in effect when the program is invoked will be used. The value can be set using the SQL_CONCURRENT_ACCESS_RESOLUTION option in the query options file QAQQINI.
- *CURCMT
- Directs the database manager to use the currently committed data when possible in the case of record lock conflicts for read-only queries. This only applies when the commit level is *CS.
- *WAIT
- Directs the database manager to wait for the outcome in the case of record lock conflicts.
Top |
System time sensitive (SYSTIME)
Specifies whether references to system-period temporal tables in both static and dynamic SQL statements are affected by the value of the CURRENT TEMPORAL SYSTEM_TIME special register.
- *YES
- References to system-period temporal tables are affected by the value of the CURRENT TEMPORAL SYSTEM_TIME special register.
- *NO
- References to system-period temporal tables are not affected by the value of the CURRENT TEMPORAL SYSTEM_TIME special register.
Top |
Listing output (OUTPUT)
Specifies whether the precompiler listing is generated.
Note: This parameter applies only to CREATE and ALTER statements for SQL procedures, functions, or triggers in the source file. This value will be used when creating the program for the SQL routine.
- *NONE
- The precompiler listing is not generated.
- *ERROR
- The precompiler listing
- *NOLIST
- The precompiler listing
- *MSG
- The precompiler listing
- The precompiler listing is generated.
Top |
Target release (TGTRLS)
Specifies the release of the operating system on which you intend to use the object being created.
Note: This parameter applies only to CREATE and ALTER statements for SQL procedures, functions, or triggers in the source file. This value will be used when creating the program for the SQL routine.
When specifying the target-release value, the format VxRxMx is used to specify the release, where Vx is the version, Rx is the release, and Mx is the modification level. For example, V5R3M0 is version 5, release 3, modification 0.
Valid values depend on the current version, release, and modification level of the operating system, and they change with each new release.
- *CURRENT
- The object is to be used on the release of the operating system currently running on your system. The object can also be used on a system with any subsequent release of the operating system installed.
- target-release
- Specify the release in the format VxRxMx. The object can be used on a system with the specified release or with any subsequent release of the operating system installed.
Top |
Debugging view (DBGVIEW)
Specifies the type of source debug information to be provided by SQL.
Note: This parameter applies only to CREATE and ALTER statements for SQL procedures, functions, or triggers in the source file. This value will be used when creating the program for the SQL routine.
- *NONE
- No debug view information is generated.
- *SOURCE
- Generates a source view of the C source generated by RUNSQLSTM for the SQL procedures, functions, or triggers in the input SQL source member. The C source member is passed to the SQL precompiler by invoking the CRTSQLCI (Create SQL ILE C object) command. A source view is also generated by the SQL precompiler for the C source member which is produced by the precompiler.
- *STMT
- Allows the compiled object to be debugged using program statement numbers and symbolic identifiers.
- *LIST
- Generates the listing view for debugging the compiled object.
Top |
Close SQL cursor (CLOSQLCSR)
Specifies when SQL cursors are implicitly closed, SQL prepared statements are implicitly discarded, and LOCK TABLE locks are released. SQL cursors are explicitly closed when the user issues the CLOSE, COMMIT, or ROLLBACK (without HOLD) SQL statements. This option is ignored for SQL table functions and triggers.
Note: This parameter applies only to CREATE and ALTER statements for SQL procedures and functions in the source file. This value will be used when creating the program for the SQL routine.
- *ENDMOD
- SQL cursors are closed and SQL prepared statements are implicitly discarded when the module is exited. LOCK TABLE locks are released when the first SQL program on the call stack ends. Note that a cursor may only be logically closed and will only be physically closed when the first program with SQL leaves the stack and only if that program was not compiled with *ENDACTGRP.
- *ENDACTGRP
- SQL cursors are closed and SQL prepared statements are implicitly discarded, and LOCK TABLE locks are released when the activation group ends.
Top |
Delay PREPARE (DLYPRP)
Specifies whether the dynamic statement validation for a PREPARE statement is delayed until an OPEN, EXECUTE, or DESCRIBE statement is run. Delaying validation improves performance by eliminating redundant validation.
Note: This parameter applies only to CREATE and ALTER statements for SQL procedures, functions, or triggers in the source file. This value will be used when creating the program for the SQL routine.
- *NO
- Dynamic statement validation is not delayed. When the dynamic statement is prepared, the access plan is validated. When the dynamic statement is used in an OPEN or EXECUTE statement, the access plan is revalidated. Because the authority or the existence of objects referred to by the dynamic statement may change, you must still check the SQLCODE or SQLSTATE after issuing the OPEN or EXECUTE statement to ensure that the dynamic statement is still valid.
- *YES
- Dynamic statement validation is delayed until the dynamic statement is used in an OPEN, EXECUTE, or DESCRIBE SQL statement. When the dynamic statement is used, the validation is completed and an access plan is built. If you specify *YES on this parameter for precompiled programs, you should check the SQLCODE and SQLSTATE after running an OPEN, EXECUTE, or DESCRIBE statement to ensure that the dynamic statement is valid.
Note: If you specify *YES, performance is not improved if the INTO clause is used on the PREPARE statement or if a DESCRIBE statement uses the dynamic statement before an OPEN is issued for the statement.
Top |
User profile (USRPRF)
Specifies the user profile that is used when the compiled program object and SQL package object is run, including the authority that the program object or SQL package has for each object in static SQL statements. The profile of either the owner or the user is used to control access to objects.
Note: This parameter applies only to CREATE and ALTER statements for SQL procedures, functions, or triggers in the source file. This value will be used when creating the program for the SQL routine.
- *NAMING
- The user profile is determined by the naming convention. If the naming convention is *SQL, USRPRF(*OWNER) is used. If the naming convention is *SYS, USRPRF(*USER) is used.
- *USER
- The profile of the user running the program or SQL package is used.
- *OWNER
- The user profiles of both the owner and the user are used when the program or SQL package is run.
Top |
Dynamic user profile (DYNUSRPRF)
Specifies the user profile used for dynamic SQL statements.
Note: This parameter applies only to CREATE and ALTER statements for SQL procedures, functions, or triggers in the source file. This value will be used when creating the program for the SQL routine.
- *USER
- Local dynamic SQL statements are run under the profile of the program's user. Distributed dynamic SQL statements are run under the profile of the application server job.
- *OWNER
- Local dynamic SQL statements are run under the profile of the program's owner. Distributed dynamic SQL statements are run under the profile of the SQL package's owner.
Top |
Examples
RUNSQLSTM SRCFILE(MYLIB/MYFILE) SRCMBR(MYMBR)
This command processes the SQL statements in member MYMBR found in file MYFILE in library MYLIB.
Top |
Error messages
*ESCAPE Messages
- SQL9006
- DB2 Query Mgr and SQL DevKit not at same install level as the operating system.
- SQL9010
- RUNSQLSTM or RUNSQL command failed.
- SQL9014
- Remote Connection Active
Top |