Oracle7 Server SQL Reference

Contents Index Home Previous Next

ALTER SESSION

Purpose

To alter your current session in one of the following:

Prerequisites

To enable and disable the SQL trace facility or to change the default label format, you must have ALTER SESSION system privilege.

To raise your session label, you must have WRITEUP and READUP system privileges. To lower your session label, you must have WRITEDOWN system privilege. To change your session label laterally, you must have READUP, WRITEUP, and WRITEDOWN system privileges.

To perform the other operations of this command, you do not need any privileges.

Syntax

Keywords and Parameters

SQL_TRACE controls the SQL trace facility for your session:

TRUE enables the SQL trace facility.

FALSE disables the SQL trace facility.

GLOBAL_NAMES

controls the enforcement of global name resolution for your session:

TRUE enables the enforcement of global name resolution.

FALSE disables the enforcement of global name resolution.

For information on enabling and disabling global name resolution with this parameter, see the ALTER SYSTEM command [*].

NLS_LANGUAGE

changes the language in which Oracle7 returns errors and other messages. This parameter also implicitly specifies new values for these items:

NLS_TERRITORY

implicitly specifies new values for these items:

NLS_DATE_FORMAT

explicitly specifies a new default date format. The 'fmt' value must be a date format model as specified in the section "Date Format" [*].

NLS_DATE_LANGUAGE

explicitly changes the language for day and month names and abbreviations and spelled values of other date format elements.

NLS_NUMERIC_CHARACTERS

explicitly specifies a new decimal character and group separator. The 'text' value must have this form:

'dg'

where:

d is the new decimal character.

g is the new group separator.

The decimal character and the group separator must be two different single-byte characters, and cannot be a numeric value or any of the following characters:

"+" plus "-" minus (or hyphen) "<" less-than ">" greater-than

NLS_ISO_CURRENCY

explicitly specifies the territory whose ISO currency symbol should be used.

NLS_CURRENCY

explicitly specifies a new local currency symbol. The symbol cannot exceed 10 characters.

NLS_SORT

changes the sequence into which Oracle7 sorts character values.

sort specifies the name of a linguistic sort sequence.

BINARY specifies a binary sort.

The default sort for all character sets is binary.

NLS_CALENDAR

explicitly specifies a new calendar type.

LABEL

changes your DBMS session label to either:

MLS_LABEL_FORMAT

changes the default label format for your session. For more information on this parameter, see the Trusted Oracle7 Server Administrator's Guide.

OPTIMIZER_GOAL

specifies the approach and goal of the optimizer for your session:

RULE specifies the rule-based approach.

ALL_ROWS specifies the cost-based approach and optimizes for best throughput.

FIRST_ROWS specifies the cost-based approach and optimizes for best response time.

CHOOSE causes the optimizer to choose an optimization approach based on the presence of statistics in the data dictionary.

FLAGGER

specifies FIPS flagging.

ENTRY flags for SQL92 Entry level

INTERMEDIATE

flags for SQL92 Intermediate level

FULL flags for SQL92 Full level

OFF turns off flagging

SESSION_CACHED_CURSORS

specify the size of the session cache for holding frequently used cursors.

integer specifies how many cursors can be retained in the cache.

CLOSE_OPEN_CACHED_CURSORS

controls whether cursors opened and cached in memory by PL/SQL are automatically closed at each COMMIT. A value of FALSE signifies that cursors opened by PL/SQL are held open so that subsequent executions need not open a new cursor. A value of TRUE causes open cursors to be closed at each COMMIT or ROLLBACK.

INSTANCE

in a parallel server, accesses database files as if the session were connected to the instance specified by integer.

HASH_JOIN_ENABLED

enables or disables the use of the hash join operation in queries. The default is TRUE, which allows hash joins.

HASH_AREA_SIZE

specifies in bytes the amount of memory to use for hash join operations. The default is twice the value of the SORT_AREA_SIZE initialization parameter.

HASH_MULTIBLOCK_IO_COUNT

specifies the number of data blocks to read and write during a hash join operation. The value multiplied by the DB_BLOCK_SIZE initialization parameter should not exceed 64 kilobytes. The default value for this parameter is 1. If the multi-threaded server is used, the value is always 1, and any value given here is ignored.

REMOTE_DEPENDENCIES_MODE

specifies how dependencies of remote stored procedures are handled by the session. For more information, refer to "Remote Dependencies" in the Oracle7 Server Application Developer's Guide.

ISOLATION_LEVEL

specifies how transactions containing database modifications are handled.

SERIALIZABLE

transactions in the session use the serializable transaction isolation mode as specified in SQL92. That is, if a serializable transaction attempts to execute a DML statement that updates rows that are updated by another uncommitted transaction at the start of the serializable transaction, then the DML statement fails. A serializable transaction can see its own updates. The COMPATIBLE initialization parameter must be set to 7.3.0 or higher for SERIALIZABLE mode to work.

READ COMMITTED

transactions in the session will use the default Oracle transaction behavior. Thus, if the transaction contains DML that require row locks held by another transaction, then the DML statement will wait until the row locks are released.

CLOSE DATABASE LINK

closes the database link dblink, eliminating your session's connection to the remote database. The database link cannot be currently in use by an active transaction or an open cursor.

ADVISE

sends advice for forcing a distributed transaction to a remote database. This advice appears on the remote database in the ADVICE column of the DBA_2PC_PENDING data dictionary view in the event the distributed transaction becomes in-doubt. The following are advice options:

COMMIT places the value 'C' in DBA_2PC_PENDING.ADVICE.

ROLLBACK places the value 'R' in DBA_2PC_PENDING.ADVICE.

NOTHING places the value ' ' in DBA_2PC_PENDING.ADVICE.

COMMIT IN PROCEDURE

specifies whether procedures and stored functions can issue COMMIT and ROLLBACK statements:

ENABLE permits procedures and stored functions to issue these statements.

DISABLE prohibits procedures and stored functions from issuing these statements.

Enabling and Disabling the SQL Trace Facility

The SQL trace facility generates performance statistics for the processing of SQL statements. You can enable and disable the SQL trace facility for all sessions on an Oracle7 instance with the initialization parameter SQL_TRACE. When you begin a session, Oracle7 enables or disables the SQL trace facility based on the value of this parameter. You can subsequently enable or disable the SQL trace facility for your session with the SQL_TRACE option of the ALTER SESSION command.

For more information on the SQL trace facility, including how to format and interpret its output, see Appendix A "Performance Diagnostic Tools" of the Oracle7 Server Tuning.

Example I

To enable the SQL trace facility for your session, issue the following statement:

ALTER SESSION 
	SET SQL_TRACE = TRUE 

Using NLS Parameters

Oracle7 contains support for use in different nations and with different languages. When you start an instance, Oracle7 establishes support based on the values of initialization parameters that begin with "NLS". For information on these parameters, see Oracle7 Server Reference. You use the NLS clauses of the ALTER SESSION command to change NLS characteristics dynamically for your session. You can query the dynamic performance table V$NLS_PARAMETERS to see the current NLS attributes for your session.

Language for Error Messages

You can specify a new language for error messages with the NLS_LANGUAGE parameter. Note that this parameter also implicitly changes other language-related items. Oracle7 provides error messages in a wide range of languages on many platforms.

Example II

The following statement changes the language for error messages to the French:

ALTER SESSION 
	SET NLS_LANGUAGE = French 

Oracle7 returns error messages in French:

SELECT * FROM emp
ORA-00942: Table ou vue n'existe pas 

Default Date Format

You can specify a new default date format either explicitly with the NLS_DATE_FORMAT parameter or implicitly with the NLS_TERRITORY parameter. For information on the default date format models, see the section "Date Format Models" [*].

Example III

The following statement dynamically changes the default date format for your session to 'YYYY MM DD-HH24:MI:SS':

ALTER SESSION 
	SET NLS_DATE_FORMAT = 'YYYY MM DD HH24:MI:SS' 

Oracle7 uses the new default date format:

SELECT TO_CHAR(SYSDATE) Today
 	FROM DUAL 
TODAY 
------------------- 
1993 08 12 14:25:56 

Language for Months and Days

You can specify a new language for names and abbreviations of months and days either explicitly with the NLS_DATE_LANGUAGE parameter or implicitly with the NLS_LANGUAGE parameter.

Example IV

The following statement changes the language for date format elements to the French:

ALTER SESSION 
	SET NLS_DATE_LANGUAGE = French 

SELECT TO_CHAR(SYSDATE, 'Day DD Month YYYY') Today
 	FROM DUAL 

TODAY 
--------------------------- 
Mardi    28 Février   1992 

Decimal Character and Group Separator

You can specify new values for these number format elements either explicitly with the NLS_NUMERIC_CHARACTERS parameter or implicitly with the NLS_TERRITORY parameter:

D (decimal character)

is the character that separates the integer and decimal portions of a number.

G (group separator)

is the character that separates groups of digits in the integer portion of a number.

For information on how to use number format models, see the section "Number Format Models" [*].

The decimal character and the group separator can only be single-byte characters and cannot be the same character. If the decimal character is not a period (.), you must use single quotation marks to enclose all number values that appear in expressions in your SQL statements. When not using a period for the decimal point, you should always use the TO_NUMBER function to ensure that a valid number is retrieved.

Example V

The following statement dynamically changes the decimal character to ',' and the group separator to '.':

ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ',.' 

Oracle7 returns these new characters when you use their number format elements:

SELECT TO_CHAR( SUM(sal), 'L999G999D99') Total FROM emp 

TOTAL 
-------------
  FF29.025,00 

ISO Currency Symbol

You can specify a new value for the C number format element, the ISO currency symbol, either explicitly with the NLS_ISO_CURRENCY parameter or implicitly with the NLS_TERRITORY parameter. The value that you specify for these parameters is a territory whose ISO currency symbol becomes the value of the C number format element.

Example VI

The following statement dynamically changes the ISO currency symbol to the ISO currency symbol for the territory America:

ALTER SESSION
 	SET NLS_ISO_CURRENCY = America 
SELECT TO_CHAR( SUM(sal), 'L999G999D99') Total
 	FROM emp 

TOTAL 
-------------
 USD29,025.00 

Local Currency Symbol

You can specify a new value for the L number format element, called the local currency symbol, either explicitly with the NLS_CURRENCY parameter or implicitly with the NLS_TERRITORY parameter.

Example VII

The following statement dynamically changes the local currency symbol to 'DM':

ALTER SESSION
 	SET NLS_CURRENCY = 'DM' 

SELECT TO_CHAR( SUM(sal), 'L999G999D99') Total
 	FROM emp 

TOTAL 
-------------
   DM29.025,00 

Linguistic Sort Sequence

You can specify a new linguistic sort sequence or a binary sort either explicitly with the NLS_SORT parameter or implicitly with the NLS_LANGUAGE parameter.

Example VIII

The following statement dynamically changes the linguistic sort sequence to Spanish:

ALTER SESSION
 	SET NLS_SORT = XSpanish 

Oracle7 sorts character values based on their position in the Spanish linguistic sort sequence.

Changing the Optimization Approach and Goal

The Oracle7 optimizer can use either of these approaches to optimize a SQL statement:

rule-based

The optimizer optimizes a SQL statement based on the indexes and clusters associated with the accessed tables, the syntactic constructs of the statement, and a heuristically ranked list of these constructs.

cost-based

The optimizer optimizes a SQL statement by considering statistics describing the tables, indexes, and clusters accessed by the statement as well as the information considered with the rule-based approach.

With the cost-based approach, the optimizer can optimize a SQL statement with one of these goals:

best throughput

or the minimal time necessary to return all rows accessed by the statement

best response time

or the minimal time necessary to return the first row accessed by the statement

When you start your instance, the optimization approach is established by the initialization parameter OPTIMIZER_MODE. If this parameter establishes the cost-based approach, the default goal is best throughput. You can subsequently change the optimization approach or the goal of the cost-based optimization approach for your session with the OPTIMIZER_GOAL parameter.

Example IX

The following statement changes the goal of the cost-based approach to best response time:

ALTER SESSION
 	SET OPTIMIZER_GOAL = FIRST_ROWS 

For information on how to choose a goal for the cost-based approach based on the characteristics of your application, see the Oracle7 Server Tuning.

FIPS Flagging

FIPS flagging causes an error message to be generated when a SQL statement is issued that is an extension of ANSI SQL92. In Oracle7, Release 7.3, there is currently no difference between Entry, Intermediate, or Full level flagging. Once flagging is set in a session, a subsequent ALTER SESSION SET FLAGGER commands will work, but generates the message, ORA-00097. This allows FIPS flagging to be altered without disconnecting the session.

Caching Session Cursors

If an application repeatedly issues parse calls on the same set of SQL statements, the reopening of the session cursors can affect performance. The ALTER SESSION SET SESSION_CACHED_CURSORS command allows frequently used session cursors to be stored in a session cache even if they are closed. This is particularly useful for some Oracle7 tools. For example, Oracle Forms applications close all session cursors associated with a form when switching to another form; in this case, frequently used cursors would not have to be reparsed.

Oracle7 uses the shared SQL area to determine if more than three parse requests were issued on a given statement. If so, Oracle7 moves the cursor into the session cursor cache. Subsequent requests to parse that SQL statement by the same session will find the cursor in the session cursor cache.

Session cursors are automatically cached if the initialization parameter, SESSION_CACHED_CURSORS is set to a positive value. This parameter specifies the maximum number of session cursors to be kept in the cache. A least recently used algorithm ages out entries in the cache to make room for new entries when needed. You use the ALTER SESSION SET SESSION_CACHED_CURSORS command to dynamically enable session cursor caching.

For more information on session cursor caching, see the Oracle7 Server Tuning.

Accessing the Database as if Connected to Another Instance in a Parallel Server

For optimum performance, each instance of a parallel server uses its own private rollback segments, freelist groups, and so on. A database is usually designed for a parallel server such that users connect to a particular instance and access data that is partitioned primarily for their use. If the users for that instance must connect to another instance, the data partitioning can be lost. The ALTER SESSION SET INSTANCE command allows users to access an instance as if they were connected to their usual instance.

Closing Database Links

A database link allows you to access a remote database in DELETE, INSERT, LOCK TABLE, SELECT, and UPDATE statements. When you issue a statement that uses a database link, Oracle7 creates a session for you on the remote database using the database link. The connection remains open until you end your local session or until the number of database links for your session exceeds the value of the initialization parameter OPEN_LINKS.

You can use the CLOSE DATABASE LINK clause of the ALTER SESSION command to explicitly close a database link if you do not plan to use it again in your session. You may want to explicitly close a database link if the network overhead associated with leaving it open is costly. Before closing a database link, you must first close all cursors that use the link and then end your current transaction if it uses the link.

Example X

This example updates the employee table on the SALES database using a database link, commits the transaction, and explicitly closes the database link:

UPDATE emp@sales 
	SET sal = sal + 200
 	WHERE empno = 9001 
COMMIT 
ALTER SESSION
 	CLOSE DATABASE LINK sales 

Offering Advice for Forcing In-doubt Distributed Transactions

If a network or machine failure occurs during the commit process for a distributed transaction, the state of the transaction may be unknown, or in-doubt. The transaction can be manually committed or rolled back on each database involved in the transaction with the FORCE clause of the COMMIT or ROLLBACK commands.

Before committing a distributed transaction, you can use the ADVISE clause of the ALTER SESSION command to send advice to a remote database in the event a distributed transaction becomes in-doubt. If the transaction becomes in-doubt, the advice appears in the ADVICE column of the DBA_2PC_PENDING view on the remote database. The administrator of that database can then use this advice to decide whether to commit or roll back the transaction on the remote database. For more information on distributed transactions and how to decide whether to commit or roll back in-doubt distributed transactions, see the "Database Administration" chapter of Oracle7 Server Distributed Systems, Volume I.

You issue multiple ALTER SESSION statements with the ADVISE clause in a single transaction. Each such statement sends advice to the databases referenced in the following statements in the transaction until another such statement is issued. This allows you to send different advice to different databases.

Example XI

This transaction inserts an employee record into the EMP table on the database identified by the database link SITE1 and deletes an employee record from the EMP table on the database identified by SITE2:

ALTER SESSION
 	ADVISE COMMIT 
INSERT INTO emp@site1 
	VALUES (8002, 'FERNANDEZ', 'ANALYST', 7566,
            TO_DATE('04-OCT-1992', 'DD-MON-YYYY'), 3000, NULL, 20) 
ALTER SESSION
 	ADVISE ROLLBACK 
DELETE FROM emp@site2
 	WHERE empno = 8002 
COMMIT 

This transaction has two ALTER SESSION statements with the ADVISE clause. If the transaction becomes in-doubt, SITE1 is sent the advice 'COMMIT' by virtue of the first ALTER SESSION statement and SITE2 is sent the advice 'ROLLBACK' by virtue of the second.

Enabling and Disabling Transaction Control in Procedures and Stored Functions

Since procedures and stored functions are written in PL/SQL, they can issue COMMIT and ROLLBACK statements. If your application performs record management that would be disrupted by a COMMIT or ROLLBACK statement not issued directly by the application itself, you may want to prevent procedures and stored functions called during your session from issuing these statements. You can do this with the following statement:

ALTER SESSION DISABLE COMMIT IN PROCEDURE 

If you subsequently call a procedure or a stored function that issues a COMMIT or ROLLBACK statement, Oracle7 returns an error and does not commit or roll back the transaction. SQL*Forms automatically prohibits COMMIT and ROLLBACK statements in procedures and stored functions.

You can subsequently allow procedures and stored functions to issue COMMIT and ROLLBACK statements in your session by issuing the following statement:

ALTER SESSION ENABLE COMMIT IN PROCEDURE 

This command does not apply to database triggers. Triggers can never issue COMMIT or ROLLBACK statements.

Related Topics

"Tuning SQL Statements" and "Performance Diagnostic Tools" of the Oracle7 Server Tuning Guide.


Contents Index Home Previous Next