Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / SQL reference.pdf
Скачиваний:
24
Добавлен:
12.05.2015
Размер:
11.92 Mб
Скачать

SYS_CONNECT_BY_PATH

manager that are equal to or less than the current salary. You can see that Raphaely and Cambrault have the same cumulative total. This is because Raphaely and Cambrault have the identical salaries, so Oracle adds together their salary values and applies the same cumulative total to both rows.

SELECT manager_id, last_name, salary,

SUM(salary) OVER (PARTITION BY manager_id ORDER BY salary

RANGE UNBOUNDED PRECEDING) l_csum

FROM employees;

MANAGER_ID

LAST_NAME

SALARY

L_CSUM

----------

--------------- ---------- ----------

 

100

Mourgos

5800

5800

 

100

Vollman

6500

12300

 

100

Kaufling

7900

20200

 

100

Weiss

8000

28200

 

100

Fripp

8200

36400

 

100

Zlotkey

10500

46900

 

100

Raphaely

11000

68900

 

100

Cambrault

11000

68900

 

100

Errazuriz

12000

80900

.

 

 

 

 

.

 

 

 

 

.

149

Taylor

8600

30200

 

 

149

Hutton

8800

39000

 

149

Abel

11000

50000

 

201

Fay

6000

6000

 

205

Gietz

8300

8300

 

 

King

24000

24000

SYS_CONNECT_BY_PATH

Syntax sys_connect_by_path::=

SYS_CONNECT_BY_PATH ( column , char )

Purpose

SYS_CONNECT_BY_PATH is valid only in hierarchical queries. It returns the path of a column value from root to node, with column values separated by char for each row returned by CONNECT BY condition.

Functions 6-155

SYS_CONTEXT

Both column and char can be any of the datatypes CHAR, VARCHAR2, NCHAR, or NVARCHAR2. The string returned is of VARCHAR2 datatype and is in the same character set as column.

See Also: "Hierarchical Queries" on page 8-3 for more information about hierarchical queries and CONNECT BY conditions

Examples

The following example returns the path of employee names from employee Kochhar to all employees of Kochhar (and their employees):

SELECT LPAD(’ ’, 2*level-1)||SYS_CONNECT_BY_PATH(last_name, ’/’) "Path" FROM employees

START WITH last_name = ’Kochhar’

CONNECT BY PRIOR employee_id = manager_id;

Path

---------------------------------------------------------------

/Kochhar

/Kochhar/Greenberg

/Kochhar/Greenberg/Faviet

/Kochhar/Greenberg/Chen

/Kochhar/Greenberg/Sciarra

/Kochhar/Greenberg/Urman

/Kochhar/Greenberg/Popp

/Kochhar/Whalen

/Kochhar/Mavris

/Kochhar/Baer

/Kochhar/Higgins

/Kochhar/Higgins/Gietz

SYS_CONTEXT

Syntax sys_context::=

 

 

 

 

 

 

 

 

,

length

SYS_CONTEXT

(

namespace

,

parameter

)

6-156 Oracle9i SQL Reference

SYS_CONTEXT

Purpose

SYS_CONTEXT returns the value of parameter associated with the context namespace. You can use this function in both SQL and PL/SQL statements.

For namespace and parameter, you can specify either a string (constant) or an expression that resolves to a string designating a namespace or an attribute. The context namespace must already have been created, and the associated parameter and its value must also have been set using the DBMS_SESSION.set_ context procedure. The namespace must be a valid SQL identifier. The parameter name can be any string. It is not case sensitive, but it cannot exceed 30 bytes in length.

The datatype of the return value is VARCHAR2. The default maximum size of the return value is 256 bytes. You can override this default by specifying the optional length parameter. The valid range of values is 1 to 4000 bytes. (If you specify an invalid value, then Oracle ignores it and uses the default.)

Oracle9i provides a built-in namespace called USERENV, which describes the current session. The predefined parameters of namespace USERENV are listed Table 6–2 on page 6-158, along with the lengths of their return strings.

Restriction on SYS_CONTEXT You cannot specify this function in a parallel query.

See Also:

Oracle9i Application Developer’s Guide - Fundamentals for information on using the application context feature in your application development

CREATE CONTEXT on page 13-12 for information on creating user-defined context namespaces

Oracle9i Supplied PL/SQL Packages and Types Reference for information on the DBMS_SESSION.set_context procedure

Examples

The following statement returns the name of the user who logged onto the database:

CONNECT OE/OE

SELECT SYS_CONTEXT (’USERENV’, ’SESSION_USER’)

FROM DUAL;

SYS_CONTEXT (’USERENV’, ’SESSION_USER’)

------------------------------------------------------

Functions 6-157

SYS_CONTEXT

OE

The following hypothetical example returns the group number that was set as the value for the attribute group_no in the PL/SQL package that was associated with the context hr_apps when hr_apps was created:

SELECT SYS_CONTEXT (’hr_apps’, ’group_no’) "User Group"

FROM DUAL;

Table 6–2 Predefined Parameters of Namespace USERENV

 

 

Return

 

 

Length

Parameter

Return Value

(bytes)

 

 

 

AUDITED_CURSORID

Returns the cursor ID of the SQL that triggered the

NA

 

audit.

 

 

 

 

AUTHENTICATION_DATA

Data being used to authenticate the login user. For

256

 

X.503 certificate authenticated sessions, this field

 

 

returns the context of the certificate in HEX2 format.

 

 

Note: You can change the return value of the

 

 

AUTHENTICATION_DATA attribute using the length

 

 

parameter of the syntax. Values of up to 4000 are

 

 

accepted. This is the only attribute of USERENV for

 

 

which Oracle implements such a change.

 

 

 

 

AUTHENTICATION_TYPE

How the user was authenticated:

30

 

DATABASE: user name/password authentication

 

 

OS: operating system external user

 

 

authentication

 

 

NETWORK: network protocol or ANO

 

 

authentication

 

 

PROXY: OCI proxy connection authentication

 

 

 

 

BG_JOB_ID

Job ID of the current session if it was established by

64

 

an Oracle background process. Null if the session

 

 

was not established by a background process.

 

 

 

 

CLIENT_IDENTIFIER

Returns the client session identifier in the global

NA

 

context—that is, the globally accessed application

 

 

context or (in the OCI context) the OCI_ATTR_

 

 

CLIENT_IDENTIFIER attribute. If no globally

 

 

relevant identifier has been set, returns null.

 

 

 

 

CLIENT_INFO

Returns up to 64 bytes of user session information

64

 

that can be stored by an application using the DBMS_

 

 

APPLICATION_INFO package.

 

 

 

 

6-158 Oracle9i SQL Reference

SYS_CONTEXT

Table 6–2 (Cont.) Predefined Parameters of Namespace USERENV

 

 

Return

 

 

Length

Parameter

Return Value

(bytes)

 

 

 

CURRENT_SCHEMA

Name of the default schema being used in the

30

 

current schema. This value can be changed during

 

 

the session with an ALTER SESSION SET CURRENT_

 

 

SCHEMA statement.

 

 

 

 

CURRENT_SCHEMAID

Identifier of the default schema being used in the

30

 

current session.

 

 

 

 

CURRENT_SQL

Returns the current SQL that triggered the

64

 

fine-grained auditing event. You can specify this

 

 

attribute only inside the event handler for the

 

 

Fine-Grained Auditing feature.

 

 

 

 

CURRENT_USER

The name of the user whose privilege the current

30

 

session is under.

 

 

 

 

CURRENT_USERID

User ID of the user whose privilege the current

30

 

session is under.

 

 

 

 

DB_DOMAIN

Domain of the database as specified in the DB_

256

 

DOMAIN initialization parameter.

 

 

 

 

DB_NAME

Name of the database as specified in the DB_NAME

30

 

initialization parameter.

 

 

 

 

ENTRY_ID

The available auditing entry identifier. You cannot

30

 

use this attribute in distributed SQL statements. To

 

 

use this keyword in USERENV, the initialization

 

 

parameter AUDIT_TRAIL must be set to TRUE.

 

 

 

 

EXTERNAL_NAME

External name of the database user. For SSL

256

 

authenticated sessions using v.503 certificates, this

 

 

field returns the distinguished name (DN) stored in

 

 

the user certificate.

 

 

 

 

FG_JOB_ID

Job ID of the current session if it was established by a

30

 

client foreground process. Null if the session was not

 

 

established by a foreground process.

 

 

 

 

GLOBAL_CONTEXT_

Returns the number being used in the System Global

NA

MEMORY

Area by the globally accessed context.

 

 

 

 

HOST

Name of the host machine from which the client has

54

 

connected.

 

 

 

 

INSTANCE

The instance identification number of the current

30

 

instance.

 

 

 

 

Functions 6-159

SYS_CONTEXT

Table 6–2 (Cont.) Predefined Parameters of Namespace USERENV

 

 

Return

 

 

Length

Parameter

Return Value

(bytes)

 

 

 

IP_ADDRESS

IP address of the machine from which the client is

30

 

connected.

 

 

 

 

ISDBA

Returns TRUE if the user has been authenticated as

30

 

having DBA privileges either through the operating

 

 

system or through a password file.

 

 

 

 

LANG

The ISO abbreviation for the language name, a

62

 

shorter form than the existing ’LANGUAGE

 

 

parameter.

 

 

 

 

LANGUAGE

The language and territory currently used by your

52

 

session, along with the database character set, in this

 

 

form:

 

 

language_territory.characterset

 

 

 

 

NETWORK_PROTOCOL

Network protocol being used for communication, as

256

 

specified in the ’PROTOCOL=protocol’ portion of

 

 

the connect string.

 

 

 

 

NLS_CALENDAR

The current calendar of the current session.

62

 

 

 

NLS_CURRENCY

The currency of the current session.

62

 

 

 

NLS_DATE_FORMAT

The date format for the session.

62

 

 

 

NLS_DATE_LANGUAGE

The language used for expressing dates.

62

 

 

 

NLS_SORT

BINARY or the linguistic sort basis.

62

 

 

 

NLS_TERRITORY

The territory of the current session.

62

 

 

 

OS_USER

Operating system user name of the client process that

30

 

initiated the database session.

 

 

 

 

PROXY_USER

Name of the database user who opened the current

30

 

session on behalf of SESSION_USER.

 

 

 

 

PROXY_USERID

Identifier of the database user who opened the

30

 

current session on behalf of SESSION_USER.

 

 

 

 

SESSION_USER

Database user name by which the current user is

30

 

authenticated. This value remains the same

 

 

throughout the duration of the session.

 

 

 

 

SESSION_USERID

Identifier of the database user name by which the

30

 

current user is authenticated.

 

 

 

 

6-160 Oracle9i SQL Reference

Соседние файлы в папке Oracle selected docs